/usr/include/openmeeg/IOUtils.H is in libopenmeeg-dev 2.0.0.dfsg-5.1ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 | /*
Project Name : OpenMEEG
© INRIA and ENPC (contributors: Geoffray ADDE, Maureen CLERC, Alexandre
GRAMFORT, Renaud KERIVEN, Jan KYBIC, Perrine LANDREAU, Théodore PAPADOPOULO,
Emmanuel OLIVI
Maureen.Clerc.AT.sophia.inria.fr, keriven.AT.certis.enpc.fr,
kybic.AT.fel.cvut.cz, papadop.AT.sophia.inria.fr)
The OpenMEEG software is a C++ package for solving the forward/inverse
problems of electroencephalography and magnetoencephalography.
This software is governed by the CeCILL-B license under French law and
abiding by the rules of distribution of free software. You can use,
modify and/ or redistribute the software under the terms of the CeCILL-B
license as circulated by CEA, CNRS and INRIA at the following URL
"http://www.cecill.info".
As a counterpart to the access to the source code and rights to copy,
modify and redistribute granted by the license, users are provided only
with a limited warranty and the software's authors, the holders of the
economic rights, and the successive licensors have only limited
liability.
In this respect, the user's attention is drawn to the risks associated
with loading, using, modifying and/or developing or reproducing the
software by the user in light of its specific status of free software,
that may mean that it is complicated to manipulate, and that also
therefore means that it is reserved for developers and experienced
professionals having in-depth computer knowledge. Users are therefore
encouraged to load and test the software's suitability as regards their
requirements in conditions enabling the security of their systems and/or
data to be ensured and, more generally, to use and operate it in the
same conditions as regards security.
The fact that you are presently reading this means that you have had
knowledge of the CeCILL-B license and that you accept its terms.
*/
#ifndef IOUTILS_H
#define IOUTILS_H
#include <iostream>
#include <string>
#include <limits>
// Various stream manipulators to handle various kinds of token
// in the input stream (comments, strings, white spaces,
// optional elements...).
namespace io_utils {
// Copy the imanip object from the old C++ library since it is apparently
// not in the standard. Remove it for a more standard solution ? (TODO).
template <typename> class imanip;
template <typename TP>
inline std::istream& operator>>(std::istream& i,const imanip<TP>& m) { return (*m.func)(i,m.obj); }
template <typename TP>
class imanip {
std::istream& (*func)(std::istream&, TP);
TP obj;
public:
imanip(std::istream& (*f)(std::istream&, TP), TP a): func(f), obj(a) {}
friend std::istream& operator>> <>(std::istream&,const imanip<TP>&);
};
template <typename,typename> class imanip2;
template <typename T1,typename T2>
inline std::istream& operator>>(std::istream& i,const imanip2<T1,T2>& m) { return (*m.func)(i,m.obj1,m.obj2); }
template <typename T1,typename T2>
class imanip2 {
std::istream& (*func)(std::istream&,T1,T2);
T1 obj1;
T2 obj2;
public:
imanip2(std::istream& (*f)(std::istream&,T1,T2),T1 a,T2 b): func(f), obj1(a),obj2(b) {}
friend std::istream& operator>> <>(std::istream&,const imanip2<T1,T2>&);
};
template <typename> class omanip;
template <typename TP>
inline std::ostream& operator<<(std::ostream& i,const omanip<TP>& m) { return (*m.func)(i,m.obj); }
template <typename TP>
class omanip {
std::ostream& (*func)(std::ostream&,TP);
TP obj;
public:
omanip(std::ostream& (*f)(std::ostream&,TP),TP a): func(f), obj(a) {}
friend std::ostream& operator<< <>(std::ostream&,const omanip<TP>&);
};
template <typename,typename> class omanip2;
template <typename T1,typename T2>
inline std::ostream& operator<<(std::ostream& i,const omanip2<T1,T2>& m) { return (*m.func)(i,m.obj1,m.obj2); }
template <typename T1,typename T2>
class omanip2 {
std::ostream& (*func)(std::ostream&,T1,T2);
T1 obj1;
T2 obj2;
public:
omanip2(std::ostream& (*f)(std::ostream&,T1,T2),T1 a,T2 b): func(f), obj1(a),obj2(b) {}
friend std::ostream& operator<< <>(std::ostream& i,const omanip2<T1,T2>& m);
};
// Ignoring the istream till the end of the line.
inline std::istream&
skip_line(std::istream& is) {
return is.ignore(std::numeric_limits<int>::max(),'\n');
}
// Eat pure white spaces (' ' and '\t')
inline std::istream&
skip_spaces(std::istream& is) {
char separator;
while (is.get(separator) && ((separator==' ') || (separator=='\t')));
return is.putback(separator);
}
// Eat up comments starting with the given character.
// Example: To remove the lines begining with a '#' then read data.
// cin >> skip_comments('#') >> data;
inline std::istream&
skip_lines_internal(std::istream& is,const unsigned char c) {
is >> std::ws;
while (is.peek()==c) {
skip_line(is);
is >> std::ws;
}
return is;
}
inline imanip<const unsigned char>
skip_comments(const unsigned char c) {
return imanip<const unsigned char>(skip_lines_internal,c);
}
// Test if the input character stream is equal to s.
inline bool
match_string(std::istream& is,const char*& s)
{
is >> std::ws;
while (*s && is.peek()==static_cast<unsigned char>(*s)) {
is.get();
s++;
}
return *s=='\0';
}
// Eat up comments beginning with the given string.
// Example: To remove the lines begining with a "//" then read data.
// cin >> skip_comments("//") >> data;
inline std::istream&
skip_lines_internal(std::istream& is,const char* s)
{
const char* s1 = s;
while (match_string(is,s1)) {
skip_line(is);
s1 = s;
}
return is;
}
inline imanip<const char*>
skip_comments(const char* s) {
return imanip<const char*>(skip_lines_internal,s);
}
// Match the given string with an input stream.
// Example: To parse lines such as "x=156 y=34".
// cin >> match("x=") >> x >> match("y=") >> y;
inline std::istream&
match_internal(std::istream& is,const char* s) {
is >> std::ws;
if (!match_string(is,s))
is.setstate(std::ios::failbit);
return is;
}
inline std::istream&
match_internal(std::istream& is,const char c) {
char cc;
is >> cc;
if (cc!=c)
is.setstate(std::ios::failbit);
return is;
}
inline std::istream&
match_internal(std::istream& is,const int i) {
int num;
is >> num;
if (i!=num)
is.setstate(std::ios::failbit);
return is;
}
inline std::istream&
match_internal(std::istream& is,const unsigned i) {
unsigned num;
is >> num;
if (i!=num)
is.setstate(std::ios::failbit);
return is;
}
inline imanip<const char*>
match(const char* str) {
return imanip<const char*>(match_internal,str);
}
inline imanip<const char*>
match(const std::string& str) {
return imanip<const char*>(match_internal,str.c_str());
}
inline imanip<const char>
match(const char c) {
return imanip<const char>(match_internal,c);
}
inline imanip<const int>
match(const int i) {
return imanip<const int>(match_internal,i);
}
inline imanip<const unsigned>
match(const unsigned i) {
return imanip<const unsigned>(match_internal,i);
}
// Restore the string [s,s1[ to the input stream.
inline void
restore_string(std::istream& is,const char* s,const char *s1) {
while (s!=s1--)
is.putback(*s1);
}
// The string equivalent.
inline void
restore_string(std::istream& is,const std::string& s) {
restore_string(is,&*s.begin(),&*s.end());
}
// Like match but the matching is optional and the
// presence of the string is given in result.
inline std::istream&
match_string_internal(std::istream& is,const char* s,bool& res)
{
std::ios::iostate state = is.rdstate();
is >> std::ws;
const char* s1 = s;
res = match_string(is,s1);
if (!res) {
is.setstate(state);
restore_string(is,s,s1);
}
return is;
}
inline imanip2<const char*,bool&>
match_optional(const char* str,bool& res) {
return imanip2<const char*,bool&>(match_string_internal,str,res);
}
inline imanip2<const char*,bool&>
match_optional(const std::string& str,bool& res) {
return imanip2<const char*,bool&>(match_string_internal,str.c_str(),res);
}
// Eat the given string if present on an input stream.
// Example: To parse lines such as "x=156 y=34".
// cin >> eat("x=") >> x >> eat("y=") >> y;
// The difference with match is that it will silently
// ignore the strings if they are not on the stream
// and the stream will remain in the good state.
// So 156 34 will also be accepted as an input line.
// Note that x156 34 or any other variation will not
// be accepted.
inline std::istream&
eat_string_internal(std::istream& is,const char* s)
{
is >> std::ws;
const char* s1 = s;
if (!match_string(is,s1))
restore_string(is,s,s1);
return is;
}
inline imanip<const char*>
eat(const char* str) {
return imanip<const char*>(eat_string_internal,str);
}
inline imanip<const char*>
eat(const std::string& str) {
return imanip<const char*>(eat_string_internal,str.c_str());
}
// Skip everything until string s is found on the stream.
inline std::istream&
skip_to_internal(std::istream& is,const char* s)
{
const char* s1 = s;
while(is) {
is.ignore(std::numeric_limits<int>::max(),*s);
if (match_string(is,++s1))
break;
restore_string(is,s+1,s1);
s1 = s;
}
return is;
}
inline imanip<const char*>
skip_to(const char* str) {
return imanip<const char*>(skip_to_internal,str);
}
inline imanip<const char*>
skip_to(const std::string& str) {
return imanip<const char*>(skip_to_internal,str.c_str());
}
// An optional input is a field eventually put before the
// end of the line.
template <typename T>
inline std::istream&
optional_internal(std::istream& is,T& t) {
skip_spaces(is);
if (is.peek()!='\n')
is >> t;
return is;
}
template <typename T>
inline imanip<T&>
optional(T& t) {
return imanip<T&>(optional_internal,t);
}
// Force numeric reading.
template <typename T>
inline std::istream&
numeric_internal(std::istream& is,T& t) {
return is >> t;
}
inline std::istream&
numeric_internal(std::istream& is,char& t) {
int i;
is >> i;
t = static_cast<char>(i);
return is;
}
inline std::istream&
numeric_internal(std::istream& is,unsigned char& t) {
unsigned i;
is >> i;
t = static_cast<unsigned char>(i);
return is;
}
template <typename T>
inline imanip<T&>
numeric(T& t) {
return imanip<T&>(numeric_internal,t);
}
}
#endif // !IOUTILS_H
|