24 #ifndef _FILEPARSER_HPP_ 25 #define _FILEPARSER_HPP_ 36 #include <boost/numeric/ublas/vector.hpp> 46 FileParser(std::string filename,
int prec = 10);
51 void open(
bool readMode);
58 void setPrecision(
int prec);
62 void write(std::string name, std::string value);
63 void read(std::string name, std::string &value);
64 std::string read(std::string name);
67 void write(std::string name,
const std::vector<std::string> &arr,
const std::vector<int> &dims);
68 void read(std::string name, std::vector<std::string> &arr, std::vector<int> &dims);
71 template <
typename T>
void write(std::string name, T value){
72 std::string str = FileParser::to_string<T>(value);
75 template <
typename T>
void read(std::string name, T &value){
76 value = to_value<T>(FileParser::read(name));
80 template <
typename T>
void readOrWrite(std::string name, T&value){
93 void write_chars(std::string name,
char* value);
94 void read_chars(std::string name,
char* value);
95 void readOrWrite(std::string name,
char* value);
97 void write_ublas(std::string name, boost::numeric::ublas::vector<double> &values);
98 void read_ublas(std::string name, boost::numeric::ublas::vector<double> &values);
99 void readOrWrite(std::string name, boost::numeric::ublas::vector<double> &values);
101 void write_vecOfvec(std::string name, std::vector<boost::numeric::ublas::vector<double> > &values);
102 void read_vecOfvec(std::string name, std::vector<boost::numeric::ublas::vector<double> > &values);
103 void readOrWrite(std::string name, std::vector<boost::numeric::ublas::vector<double> > &values);
105 void write_double_array(std::string name,
double values[],
size_t length);
106 void read_double_array(std::string name,
double values[],
size_t length);
107 void readOrWrite(std::string name,
double values[],
size_t length);
110 template <
typename T>
111 std::string to_string(T value)
113 std::ostringstream os;
114 os << std::setprecision(precision) << value ;
118 template <
typename T>
119 T to_value(std::string str)
121 std::istringstream ss(str);
123 return (ss >> std::setprecision(precision) >> result) ? result : 0;
127 bool movePointer(std::string name, std::string &content);
128 bool startsWith(std::string all, std::string sub);
131 void parseArray(std::string contents, std::vector<std::string> &arr, std::vector<int> &dims);
134 std::string filename;
135 std::ofstream output;
138 std::string currentLine;
Namespace of the library interface.
Functions to parse strings.