All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Macros Pages
parse_file.hpp
Go to the documentation of this file.
1 //=======================================================================
2 // Copyright (c)
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See
5 // accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
7 //=======================================================================
15 #ifndef PAAL_PARSE_FILE_HPP
16 #define PAAL_PARSE_FILE_HPP
17 
18 #include <cassert>
19 #include <fstream>
20 #include <istream>
21 #include <limits>
22 
23 namespace paal {
24 
33 template <typename Functor> void parse(std::istream &input_stream, Functor f) {
34  assert(input_stream.good());
35  while (input_stream.good()) {
36  std::string first_token;
37  input_stream >> first_token;
38  if (first_token == "") {
39  return;
40  }
41  if (first_token[0] == '#') {
42  input_stream.ignore(std::numeric_limits<std::streamsize>::max(),
43  '\n');
44  continue;
45  }
46  f(first_token, input_stream);
47  }
48 }
49 
56 template <typename Functor> void parse(const std::string &filename, Functor f) {
57  std::ifstream input_stream(filename);
58  parse(input_stream, f);
59 }
60 
61 }
62 #endif // PAAL_PARSE_FILE_HPP
void parse(std::istream &input_stream, Functor f)
parses stream ignoring empty lines or beginning with &#39;#&#39;
Definition: parse_file.hpp:33