OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
Fieldmap.hpp
Go to the documentation of this file.
1 #ifndef CLASSIC_FIELDMAP_ICC
2 #define CLASSIC_FIELDMAP_ICC
3 
4 
5 #include <string>
6 #include <iostream>
7 #include <fstream>
8 #include <boost/type_index.hpp>
9 #include "Fields/Fieldmap.h"
10 
11 template<class T>
12 bool Fieldmap::interpreteLine(std::ifstream & in, T & value, const bool & file_length_known)
13 {
14  bool read_all = true;
15  std::string buffer;
16  std::streampos start = in.tellg();
17 
18  getLine(in, buffer);
19  if (in.eof() && !file_length_known) {
20  return false;
21  }
22  std::istringstream interpreter(buffer, std::istringstream::in);
23 
24  interpreter >> value;
25 
26  if (interpreter.rdstate() ^ std::ios_base::eofbit) {
27  in.seekg(start);
28  if (in.eof()) {
30  return false;
31  }
32  std::string expecting(boost::typeindex::type_id<T>().pretty_name());
33  interpreteWarning((interpreter.rdstate() ^ std::ios_base::eofbit), read_all, expecting, buffer);
34  }
35  return (!(interpreter.rdstate() ^ std::ios_base::eofbit) && read_all); // eof should not be an error but if not eof
36 }
37 
38 template<class S, class T>
39 bool Fieldmap::interpreteLine(std::ifstream & in, S & value1, T & value2, const bool & file_length_known)
40 {
41  bool read_all = true;
42  std::string buffer;
43  std::streampos start = in.tellg();
44 
45  getLine(in, buffer);
46  if (in.eof() && !file_length_known) {
47  return false;
48  }
49  std::istringstream interpreter(buffer, std::istringstream::in);
50 
51  interpreter >> value1;
52  if (interpreter.rdstate()) read_all = false;
53 
54  interpreter >> value2;
55 
56  if (interpreter.rdstate() ^ std::ios_base::eofbit) {
57  in.seekg(start);
58  if (in.eof()) {
60  return false;
61  }
62  std::string expecting(boost::typeindex::type_id<S>().pretty_name());
63  expecting += std::string(" ") + boost::typeindex::type_id<T>().pretty_name();
64  interpreteWarning((interpreter.rdstate() ^ std::ios_base::eofbit), read_all, expecting, buffer);
65  }
66  return (!(interpreter.rdstate() ^ std::ios_base::eofbit) && read_all); // eof should not be an error but if not eof
67 }
68 
69 template<class S, class T, class U>
70 bool Fieldmap::interpreteLine(std::ifstream & in, S & value1, T & value2, U & value3, const bool & file_length_known)
71 {
72  bool read_all = true;
73  std::string buffer;
74  std::streampos start = in.tellg();
75 
76  getLine(in, buffer);
77  if (in.eof() && !file_length_known) {
78  return false;
79  }
80  std::istringstream interpreter(buffer, std::istringstream::in);
81 
82  interpreter >> value1;
83 
84  interpreter >> value2;
85  if (interpreter.rdstate()) read_all = false;
86 
87  interpreter >> value3;
88 
89  if (interpreter.rdstate() ^ std::ios_base::eofbit) {
90  in.seekg(start);
91  if (in.eof()) {
93  return false;
94  }
95  std::string expecting(boost::typeindex::type_id<S>().pretty_name() + std::string(" ") +
96  boost::typeindex::type_id<T>().pretty_name() + std::string(" ") +
97  boost::typeindex::type_id<U>().pretty_name());
98  interpreteWarning((interpreter.rdstate() ^ std::ios_base::eofbit), read_all, expecting, buffer);
99  }
100  return (!(interpreter.rdstate() ^ std::ios_base::eofbit) && read_all); // eof should not be an error but if not eof
101 }
102 
103 template<class S, class T, class U, class V>
104 bool Fieldmap::interpreteLine(std::ifstream & in, S & value1, T & value2, U & value3, V & value4, const bool & file_length_known)
105 {
106  bool read_all = true;
107  std::string buffer;
108  std::streampos start = in.tellg();
109 
110  getLine(in, buffer);
111  if (in.eof() && !file_length_known) {
112  return false;
113  }
114  std::istringstream interpreter(buffer, std::istringstream::in);
115 
116  interpreter >> value1;
117 
118  interpreter >> value2;
119 
120  interpreter >> value3;
121  if (interpreter.rdstate()) read_all = false;
122 
123  interpreter >> value4;
124 
125  if (interpreter.rdstate() ^ std::ios_base::eofbit) {
126  in.seekg(start);
127  if (in.eof()) {
129  return false;
130  }
131  std::string expecting(boost::typeindex::type_id<S>().pretty_name() + std::string(" ") +
132  boost::typeindex::type_id<T>().pretty_name() + std::string(" ") +
133  boost::typeindex::type_id<U>().pretty_name() + std::string(" ") +
134  boost::typeindex::type_id<V>().pretty_name());
135  interpreteWarning((interpreter.rdstate() ^ std::ios_base::eofbit), read_all, expecting, buffer);
136  }
137  return (!(interpreter.rdstate() ^ std::ios_base::eofbit) && read_all); // eof should not be an error but if not eof
138 }
139 
140 template<class S>
141 bool Fieldmap::interpreteLine(std::ifstream & in, S & value1, S & value2, S & value3, S & value4, S & value5, S & value6, const bool & file_length_known)
142 {
143  bool read_all = true;
144  std::string buffer;
145  std::streampos start = in.tellg();
146 
147  getLine(in, buffer);
148  if (in.eof() && !file_length_known) {
149  return false;
150  }
151  std::istringstream interpreter(buffer, std::istringstream::in);
152 
153  interpreter >> value1;
154 
155  interpreter >> value2;
156 
157  interpreter >> value3;
158 
159  interpreter >> value4;
160 
161  interpreter >> value5;
162  if (interpreter.rdstate()) read_all = false;
163 
164  interpreter >> value6;
165 
166  if (interpreter.rdstate() ^ std::ios_base::eofbit) {
167  in.seekg(start);
168  if (in.eof()) {
170  return false;
171  }
172  std::string expecting(boost::typeindex::type_id<S>().pretty_name() + std::string(" ") +
173  boost::typeindex::type_id<S>().pretty_name() + std::string(" ") +
174  boost::typeindex::type_id<S>().pretty_name() + std::string(" ") +
175  boost::typeindex::type_id<S>().pretty_name() + std::string(" ") +
176  boost::typeindex::type_id<S>().pretty_name() + std::string(" ") +
177  boost::typeindex::type_id<S>().pretty_name());
178  interpreteWarning((interpreter.rdstate() ^ std::ios_base::eofbit), read_all, expecting, buffer);
179  }
180  return (!(interpreter.rdstate() ^ std::ios_base::eofbit) && read_all); // eof should not be an error but if not eof
181 }
182 
183 
184 #endif
Definition: rbendmap.h:8
void missingValuesWarning()
Definition: Fieldmap.cpp:590
void interpreteWarning(const std::string &error_msg, const std::string &expecting, const std::string &found)
Definition: Fieldmap.cpp:563
bool interpreteLine(std::ifstream &in, S &value, const bool &file_length_known=true)
void getLine(std::ifstream &in, std::string &buffer)
Definition: Fieldmap.h:198