Version: SMASH-3.1
inputfunctions.cc
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (c) 2014-2019,2021
4  * SMASH Team
5  *
6  * GNU General Public License (GPLv3 or later)
7  *
8  */
9 
10 #include "smash/inputfunctions.h"
11 
12 #include <sstream>
13 #include <vector>
14 
15 #include "smash/logging.h"
16 #include "smash/stringfunctions.h"
17 
18 namespace smash {
19 static constexpr int LInputParser = LogArea::InputParser::id;
20 
21 std::vector<Line> line_parser(const std::string &input) {
22  logg[LInputParser].trace() << SMASH_SOURCE_LOCATION << input;
23  std::istringstream input_stream(input);
24  std::vector<Line> lines;
25  lines.reserve(50);
26 
27  std::string line;
28  int line_number = 0;
29  while (std::getline(input_stream, line)) {
30  ++line_number;
31  const auto hash_pos = line.find('#');
32  if (hash_pos != std::string::npos) {
33  // Found a comment, remove it from the line and look further
34  line = line.substr(0, hash_pos);
35  }
36  if (line.find_first_not_of(" \t") == std::string::npos) {
37  // Only whitespace (or nothing) on this line. Next, please.
38  continue;
39  }
40  line = trim(line);
41  lines.emplace_back(line_number, std::move(line));
42  line = std::string();
43  }
44  return lines;
45 }
46 
47 } // namespace smash
#define SMASH_SOURCE_LOCATION
Hackery that is required to output the location in the source code where the log statement occurs.
Definition: logging.h:153
std::array< einhard::Logger<>, std::tuple_size< LogArea::AreaTuple >::value > logg
An array that stores all pre-configured Logger objects.
Definition: logging.cc:39
Definition: action.h:24
build_vector_< Line > line_parser(const std::string &input)
Helper function for parsing particles.txt and decaymodes.txt.
std::string trim(const std::string &s)
Strip leading and trailing whitespaces.
static constexpr int LInputParser