QNANO
Reader.h
1 #ifndef QNANO_NEW_READER_DEFINED_H
2 #define QNANO_NEW_READER_DEFINED_H
3 
4 #include <iostream>
5 #include <iomanip>
6 #include <fstream>
7 #include <sstream>
8 #include <cstdlib>
9 #include <complex>
10 #include <vector>
11 #include <string>
12 #include "tools/Vec3d.h"
13 
14 class Reader{
15 public:
16 
17  static bool string_starts_with(const std::string &str, const std::string &start);
18  static void check_open(std::ifstream &f,const std::string &fname);
19  static bool file_exists(const std::string &filename);
20  static std::string find_resource_file(const std::string &resources_dir, const std::string &resourcename, const std::string &default_suffix=".dat");
21  static std::string find_resource_file_nocheck(const std::string &resources_dir, const std::string &resourcename, const std::string &default_suffix=".dat");
22  static std::string trim(const std::string &s, const std::string &ws=" \t");
23 
24 
25  static bool isDouble(const std::string &s);
26  static bool isBool(const std::string &s);
27  static bool checkForDouble(const std::string &s,double *d);
28  static bool checkForDouble(std::istream & ssin,double *d);
29  static double readDouble(const std::string &s, const std::string &field="");
30  static double readDouble(std::istream &ssin, const std::string &field="");
31  static std::complex<double> readComplex(std::istream &ssin, const std::string &field="");
32  static std::complex<double> readComplex(const std::string &s, const std::string &field="");
33  static bool readBool(const std::string &s,const std::string &field="");
34  static bool readBool(std::istream &ssin, const std::string &field="");
35  static size_t readSizeT(const std::string &s, const std::string &field="");
36  static std::string toString(double d);
37 
38  static size_t countLinesInFile(const std::string &fname);
39  static bool lineIsRelevant(const std::string & line);
40  static bool getRelevantLine(std::istream &istr, std::string & line);
41  static bool getRelevantLineTokens(std::istream &istr, std::vector<std::string> & toks);
42  static bool getRelevantLineVecXd(std::istream &istr, std::vector<double> & v);
43  static size_t countRelevantLinesInFile(const std::string &fname);
44 
45 
46  static std::string search_next_line_starting_with(std::istream &f, const std::string &search);
47  static std::string search_first_line_starting_with(const std::string &filename, const std::string &search);
48  static std::string search_first_line_starting_with_check(const std::string &filename, const std::string &search);
49  static std::vector<std::string> search_lines_starting_with(const std::string &filename, const std::string &search);
50 
51  static std::string token(const std::string &str, int i);
52  static std::vector<std::string> tokenize(const std::string & line);
53  static std::vector<double> line_to_VecXd(const std::string & line,size_t col=0);
54  static std::vector<double> StringVec_to_VecXd(const std::vector<std::string> & stingvec,size_t col=0);
55 
56  static double read_double_parameter_from_file(const std::string &filename, const std::string &search, double def, bool *found=NULL);
57 
58 
59  static double check_read_double_parameter_from_file(const std::string &filename, const std::string &search);
60  static bool read_bool_parameter_from_file(const std::string &filename, const std::string &search, bool def);
61  static bool check_read_bool_parameter_from_file(const std::string &filename, const std::string &search);
62  static std::string read_string_parameter_from_file(const std::string &filename, const std::string &search, const std::string &def);
63  static std::string check_read_string_parameter_from_file(const std::string &filename, const std::string &search);
64 
65  static std::string check_read_parameter_line_from_file(const std::string &filename, const std::string &search);
66 
67 
68  static double check_line_is_double_parameter(const std::string &line, const std::string &parameter, const std::string &context="");
69 
70  static std::string to_string(int i);
71  static std::string condenseDouble(const double d, int figure=8);
72  static std::string condenseComplex(const std::complex<double> d, int figure=8);
73 
74  static Vec3d StringVec_to_Vec3d(const std::vector<std::string> sv, const std::string &add_to_error_msg);
75 
76 
77  static std::string filename_from_pattern(const std::string &filename_pattern, int i);
78  static void replace_in_string(std::string &str, const std::string &pattern, const std::string &replace);
79  static std::string get_base_dir(const std::string &filename);
80  static std::string remove_dir(const std::string &filename);
81  static std::string remove_dir_and_dotdat(const std::string &filename);
82 
83  static int get_nr_relevant_lines_in_file(const std::string &filename);
84 };
85 
86 #endif
Definition: Reader.h:14
Class to store positions and to handle operations on 3d vectors.
Definition: Vec3d.h:9