8#ifndef SEIMS_SIMPLE_TEXT_H
9#define SEIMS_SIMPLE_TEXT_H
19using namespace utils_array;
20using namespace utils_string;
21using namespace utils_filesystem;
39 void GetData(
int* n_row, T** data);
42 void Dump(std::ostream* fs);
54 throw ModelException(
"clsSimpleTxtData",
"ReadFile",
"The file " + filename +
55 " does not exist or has not read permission.");
58 myfile.open(filename.c_str(), std::ifstream::in);
61 if (myfile.is_open()) {
64 while (!myfile.eof()) {
68 getline(myfile, line);
70 if (line.empty() || line[0] ==
'#') {
74 if (!tokens.empty()) {
76 if (tokens[0].find_first_of(
"0123456789") == string::npos) {
79 data.emplace_back(T(strtod(tokens[0].c_str(), &end)));
86 data_ =
new(nothrow) T[row_];
88 for (
auto it = data.begin(); it < data.end(); ++it) {
103 if (
nullptr == fs)
return;
104 if (
nullptr == data_)
return;
105 for (
int i = 0; i < row_; i++) {
106 *fs << data_[i] << endl;
#define CVT_INT(param)
A reference to the postfix of executable file for RELWITHDEBINFO mode.
Definition: basic.h:325
Base type of all interfaces.
Definition: basic.h:407
Print the exception message.
Definition: basic.h:416
void GetData(int *n_row, T **data)
Get line number and data.
Definition: clsSimpleTxtData.h:111
clsSimpleTxtData(const string &filename)
Constructor, from text file read lines data.
Definition: clsSimpleTxtData.h:52
void Dump(std::ostream *fs)
Output lines data to ostream.
Definition: clsSimpleTxtData.h:102
~clsSimpleTxtData()
Destructor.
Definition: clsSimpleTxtData.h:97
read string line from text file
Definition: clsSimpleTxtData.h:30
void Release1DArray(T *&data)
Release DT_Array1D data.
Definition: utils_array.h:460
bool FileExists(string const &filename)
Return a flag indicating if the given file exists.
vector< string > SplitString(const string &item)
Splits the given string by spaces.
void TrimSpaces(string &str)
Trim Both leading and trailing spaces.
Common Cross-platform Geographic Library (CCGL)
The SEIMS related definitions and utilities header.
Template functions to initialize and release arrays.
File system related functions in CCGL.
Handling string related issues in CCGL.