Version: SMASH-3.1
inputfunctions.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (c) 2014-2015,2017-2018,2020
4  * SMASH Team
5  *
6  * GNU General Public License (GPLv3 or later)
7  *
8  */
9 
10 #ifndef SRC_INCLUDE_SMASH_INPUTFUNCTIONS_H_
11 #define SRC_INCLUDE_SMASH_INPUTFUNCTIONS_H_
12 
13 #include <iostream>
14 #include <string>
15 #include <utility>
16 
17 #include "forwarddeclarations.h"
18 #include "particletype.h"
19 
20 namespace smash {
21 
23 struct Line { /*{{{*/
25  Line() = default;
27  Line(int n, std::string &&t) : number(n), text(std::move(t)) {}
29  int number;
31  std::string text;
32 }; /*}}}*/
33 
42 inline std::string build_error_string(std::string message, const Line &line) {
43  return message + " (on line " + std::to_string(line.number) + ": \"" +
44  line.text + "\")";
45 }
46 
56 build_vector_<Line> line_parser(const std::string &input);
57 
59 inline void ensure_all_read(std::istream &input, const Line &line) { /*{{{*/
60  std::string tmp;
61  input >> tmp;
62  if (!input.eof()) {
64  build_error_string("While loading the Particle data:\nGarbage (" + tmp +
65  ") at the remainder of the line.",
66  line));
67  }
68 } /*}}}*/
69 
80 inline std::string read_all(std::istream &&input) {
81  return {std::istreambuf_iterator<char>{input},
82  std::istreambuf_iterator<char>{}};
83 }
84 
91 inline bool has_crlf_line_ending(const std::string in) {
92  if (in.find("\r\n") != std::string::npos) {
93  return true;
94  }
95  return false;
96 }
97 
98 } // namespace smash
99 
100 #endif // SRC_INCLUDE_SMASH_INPUTFUNCTIONS_H_
constexpr int n
Neutron.
Definition: action.h:24
void ensure_all_read(std::istream &input, const Line &line)
Makes sure that nothing is left to read from this line.
build_vector_< Line > line_parser(const std::string &input)
Helper function for parsing particles.txt and decaymodes.txt.
bool has_crlf_line_ending(const std::string in)
Check if a line in the string ends with \r\n.
std::string read_all(std::istream &&input)
Utility function to read a complete input stream (e.g.
std::string build_error_string(std::string message, const Line &line)
Builds a meaningful error message.
Line consists of a line number and the contents of that line.
int number
Line number.
std::string text
Line content.
Line()=default
Initialize line with empty string and number.
Line(int n, std::string &&t)
Initialize a line with line number n and text t.