00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
#ifndef TALOS_FILE_FILES_HXX
00022
00023
00024
namespace Talos
00025 {
00026
00027
bool exists(string file_name);
00028
unsigned long file_size(string file_name);
00029
unsigned long stream_size(istream& stream);
00030
bool is_empty(istream& stream);
00031
bool has_element(istream& stream);
00032
00034 class ExtStream:
public ifstream
00035 {
00036
protected:
00038 string
file_name_;
00040 string
comments_;
00042 string
delimiters_;
00043
00044
public:
00045
ExtStream();
00046
ExtStream(string file_name,
00047 string comments =
"#%",
00048 string delimiters =
" \t:=|\n,;");
00049
00050
virtual ~ExtStream();
00051
00052
bool Discard(string line)
const;
00053
ExtStream&
SkipDiscarded();
00054
00055
void SetDelimiters(string delimiters);
00056
void SetComments(string comments);
00057
00058 string
GetDelimiters() const;
00059 string GetComments() const;
00060 string GetFileName() const;
00061
00062
ExtStream& SkipDelimiters();
00063 string RemoveDelimiters(const string& str) const;
00064
00065
ExtStream& Skip();
00066
00067
void Open(string file_name, openmode mode = in);
00068
void Close();
00069
00070
bool IsEmpty();
00071
00072
ExtStream& Rewind();
00073
00074 string GetFullLine();
00075
bool GetFullLine(string& line);
00076 string PeekFullLine();
00077 string PeekFullLine(streampos& position);
00078
bool PeekFullLine(string& line);
00079
void SkipFullLines(
int nb);
00080
00081 virtual string GetLine();
00082 virtual
bool GetLine(string& line);
00083 virtual string PeekLine();
00084 virtual string PeekLine(streampos& position);
00085 virtual
bool PeekLine(string& line);
00086
void SkipLines(
int nb);
00087
00088
bool Find(string element);
00089
bool FindFromBeginning(string element);
00090
00091 virtual string GetElement();
00092 template <class T>
00093
bool GetElement(T& element);
00094 template <class T>
00095
bool GetRawElement(T& element);
00096 string PeekElement();
00097 template <class T>
00098
bool PeekElement(T& element);
00099
void SkipElements(
int nb);
00100
00101
double GetNumber();
00102 template <class T>
00103
bool GetNumber(T& number);
00104
double PeekNumber();
00105 template <class T>
00106
bool PeekNumber(T& number);
00107
void SkipNumbers(
int nb);
00108
00109 string GetValue(string name);
00110 string PeekValue(string name);
00111
00112 template <class T>
00113
bool GetValue(string name, T& value);
00114 template <class T>
00115
bool PeekValue(string name, T& value);
00116
00117
bool GetValue(string name, string& value);
00118
bool PeekValue(string name, string& value);
00119
00120
bool GetValue(string name,
bool& value);
00121
bool PeekValue(string name,
bool& value);
00122 };
00123
00125 class
ConfigStream: public
ExtStream
00126 {
00127
protected:
00128 string markup_tags_;
00129
00130
public:
00131
ConfigStream();
00132
ConfigStream(string file_name,
00133 string comments =
"#%",
00134 string delimiters =
" \t:=|\n,;",
00135 string markup_tags =
"<>$");
00136
00137
void SetMarkupTags(string markup_tags);
00138 string GetMarkupTags()
const;
00139
00140
virtual string
GetElement();
00141
00142
virtual string
GetLine();
00143
virtual bool GetLine(string& line);
00144 };
00145
00147 class ConfigStreams
00148 {
00149
protected:
00150 vector<ConfigStream*> streams_;
00151 vector<ConfigStream*>::iterator current_;
00152
00153
public:
00154
ConfigStreams();
00155
ConfigStreams(
const vector<string>& files);
00156
ConfigStreams(string file0);
00157
ConfigStreams(string file0, string file1);
00158
ConfigStreams(string file0, string file1, string file2);
00159
00160 ~
ConfigStreams();
00161
00162 vector<ConfigStream*>& GetStreams();
00163 vector<ConfigStream*>::iterator GetCurrent();
00164
00165
void AddFile(string file);
00166
00167
bool Discard(string line)
const;
00168
ConfigStreams&
SkipDiscarded();
00169
00170
ConfigStreams&
SkipDelimiters();
00171 string
RemoveDelimiters(
const string& str)
const;
00172
00173
ConfigStreams&
Skip();
00174
00175
bool IsEmpty();
00176
00177
ConfigStreams&
Rewind();
00178
00179 string
GetFullLine();
00180
bool GetFullLine(string& line);
00181 string
PeekFullLine();
00182 string
PeekFullLine(streampos& position);
00183
bool PeekFullLine(string& line);
00184
void SkipFullLines(
int nb);
00185
00186 string GetRawLine();
00187 string
GetLine();
00188
bool GetLine(string& line);
00189 string
PeekLine();
00190 string
PeekLine(streampos& position);
00191
bool PeekLine(string& line);
00192
void SkipLines(
int nb);
00193
00194
bool Find(string element);
00195
bool FindFromBeginning(string element);
00196
00197 string
GetRawElement();
00198 string
GetElement();
00199
template <
class T>
00200
bool GetElement(T& element);
00201 string
PeekElement();
00202
template <
class T>
00203
bool PeekElement(T& element);
00204
void SkipElements(
int nb);
00205
00206
double GetNumber();
00207
template <
class T>
00208
bool GetNumber(T& number);
00209
double PeekNumber();
00210
template <
class T>
00211
bool PeekNumber(T& number);
00212
void SkipNumbers(
int nb);
00213
00214 string
GetValue(string name);
00215 string
PeekValue(string name);
00216
00217
template <
class T>
00218
bool GetValue(string name, T& value);
00219
template <
class T>
00220
bool PeekValue(string name, T& value);
00221
00222
bool GetValue(string name, string& value);
00223
bool PeekValue(string name, string& value);
00224
00225
bool GetValue(string name,
bool& value);
00226
bool PeekValue(string name,
bool& value);
00227 };
00228
00229 }
00230
00231
00232
#define TALOS_FILE_FILES_HXX
00233
#endif