OPALX (Object Oriented Parallel Accelerator Library for Exascal) master (dc2a29eed580)
OPALX
Loading...
Searching...
No Matches
Fieldmap.hpp
Go to the documentation of this file.
1#ifndef OPALX_FIELDMAP_ICC
2#define OPALX_FIELDMAP_ICC
3
4#include <fstream>
5#include <iostream>
6#include <string>
7#include <typeindex>
8#include "Fields/Fieldmap.h"
9
22template <class T>
23bool Fieldmap::interpretLine(std::ifstream& in, T& value, const bool& file_length_known) {
24 bool read_all = true;
25 std::string buffer;
26 std::streampos start = in.tellg();
27
28 getLine(in, buffer);
29 if (in.eof() && !file_length_known) {
30 return false;
31 }
32 std::istringstream interpreter(buffer, std::istringstream::in);
33
34 interpreter >> value;
35
36 if (interpreter.rdstate() ^ std::ios_base::eofbit) {
37 in.seekg(start);
38 if (in.eof()) {
40 return false;
41 }
42 std::string expecting(std::string(typeid(T).name()));
44 (interpreter.rdstate() ^ std::ios_base::eofbit), read_all, expecting, buffer);
45 }
46 return (!(interpreter.rdstate() ^ std::ios_base::eofbit)
47 && read_all); // eof should not be an error but if not eof
48}
49
54template <class S, class T>
56 std::ifstream& in, S& value1, T& value2, const bool& file_length_known) {
57 bool read_all = true;
58 std::string buffer;
59 std::streampos start = in.tellg();
60
61 getLine(in, buffer);
62 if (in.eof() && !file_length_known) {
63 return false;
64 }
65 std::istringstream interpreter(buffer, std::istringstream::in);
66
67 interpreter >> value1;
68 if (interpreter.rdstate()) read_all = false;
69
70 interpreter >> value2;
71
72 if (interpreter.rdstate() ^ std::ios_base::eofbit) {
73 in.seekg(start);
74 if (in.eof()) {
76 return false;
77 }
78 std::string expecting(std::string(typeid(S).name()));
79 expecting += std::string(" ") + std::string(typeid(T).name());
81 (interpreter.rdstate() ^ std::ios_base::eofbit), read_all, expecting, buffer);
82 }
83 return (!(interpreter.rdstate() ^ std::ios_base::eofbit)
84 && read_all); // eof should not be an error but if not eof
85}
86
91template <class S, class T, class U>
93 std::ifstream& in, S& value1, T& value2, U& value3, const bool& file_length_known) {
94 bool read_all = true;
95 std::string buffer;
96 std::streampos start = in.tellg();
97
98 getLine(in, buffer);
99 if (in.eof() && !file_length_known) {
100 return false;
101 }
102 std::istringstream interpreter(buffer, std::istringstream::in);
103
104 interpreter >> value1;
105
106 interpreter >> value2;
107 if (interpreter.rdstate()) read_all = false;
108
109 interpreter >> value3;
110
111 if (interpreter.rdstate() ^ std::ios_base::eofbit) {
112 in.seekg(start);
113 if (in.eof()) {
115 return false;
116 }
117 std::string expecting(
118 std::string(typeid(S).name()) + std::string(" ") + std::string(typeid(T).name())
119 + std::string(" ") + std::string(typeid(U).name()));
121 (interpreter.rdstate() ^ std::ios_base::eofbit), read_all, expecting, buffer);
122 }
123 return (!(interpreter.rdstate() ^ std::ios_base::eofbit)
124 && read_all); // eof should not be an error but if not eof
125}
126
131template <class S, class T, class U, class V>
133 std::ifstream& in, S& value1, T& value2, U& value3, V& value4,
134 const bool& file_length_known) {
135 bool read_all = true;
136 std::string buffer;
137 std::streampos start = in.tellg();
138
139 getLine(in, buffer);
140 if (in.eof() && !file_length_known) {
141 return false;
142 }
143 std::istringstream interpreter(buffer, std::istringstream::in);
144
145 interpreter >> value1;
146
147 interpreter >> value2;
148
149 interpreter >> value3;
150 if (interpreter.rdstate()) read_all = false;
151
152 interpreter >> value4;
153
154 if (interpreter.rdstate() ^ std::ios_base::eofbit) {
155 in.seekg(start);
156 if (in.eof()) {
158 return false;
159 }
160 std::string expecting(
161 std::string(typeid(S).name()) + std::string(" ") + std::string(typeid(T).name())
162 + std::string(" ") + std::string(typeid(U).name()) + std::string(" ")
163 + std::string(typeid(V).name()));
165 (interpreter.rdstate() ^ std::ios_base::eofbit), read_all, expecting, buffer);
166 }
167 return (!(interpreter.rdstate() ^ std::ios_base::eofbit)
168 && read_all); // eof should not be an error but if not eof
169}
170
175template <class S>
177 std::ifstream& in, S& value1, S& value2, S& value3, S& value4, S& value5, S& value6,
178 const bool& file_length_known) {
179 bool read_all = true;
180 std::string buffer;
181 std::streampos start = in.tellg();
182
183 getLine(in, buffer);
184 if (in.eof() && !file_length_known) {
185 return false;
186 }
187 std::istringstream interpreter(buffer, std::istringstream::in);
188
189 interpreter >> value1;
190
191 interpreter >> value2;
192
193 interpreter >> value3;
194
195 interpreter >> value4;
196
197 interpreter >> value5;
198 if (interpreter.rdstate()) read_all = false;
199
200 interpreter >> value6;
201
202 if (interpreter.rdstate() ^ std::ios_base::eofbit) {
203 in.seekg(start);
204 if (in.eof()) {
206 return false;
207 }
208 std::string expecting(
209 std::string(typeid(S).name()) + std::string(" ") + std::string(typeid(S).name())
210 + std::string(" ") + std::string(typeid(S).name()) + std::string(" ")
211 + std::string(typeid(S).name()) + std::string(" ") + std::string(typeid(S).name())
212 + std::string(" ") + std::string(typeid(S).name()));
214 (interpreter.rdstate() ^ std::ios_base::eofbit), read_all, expecting, buffer);
215 }
216 return (!(interpreter.rdstate() ^ std::ios_base::eofbit)
217 && read_all); // eof should not be an error but if not eof
218}
219
220#endif
double T
Definition OPALTypes.h:8
void missingValuesWarning()
Definition Fieldmap.cpp:470
void interpretWarning(const std::ios_base::iostate &state, const bool &read_all, const std::string &error_msg, const std::string &found)
Definition Fieldmap.cpp:452
bool interpretLine(std::ifstream &in, S &value, const bool &file_length_known=true)
void getLine(std::ifstream &in, std::string &buffer)
Definition Fieldmap.h:237