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
00045 string searching_;
00046
00047 public:
00048 ExtStream();
00049 ExtStream(string file_name,
00050 string comments = "#%",
00051 string delimiters = " \t:=|\n,;");
00052
00053 virtual ~ExtStream();
00054
00055 bool Discard(string line) const;
00056 ExtStream& SkipDiscarded();
00057
00058 void SetDelimiters(string delimiters);
00059 void SetComments(string comments);
00060
00061 string GetDelimiters() const;
00062 string GetComments() const;
00063 string GetFileName() const;
00064
00065 ExtStream& SkipDelimiters();
00066 string RemoveDelimiters(const string& str) const;
00067
00068 ExtStream& Skip();
00069
00070 void Open(string file_name, openmode mode = in);
00071 void Close();
00072
00073 bool IsEmpty();
00074
00075 ExtStream& Rewind();
00076
00077 string GetFullLine();
00078 bool GetFullLine(string& line);
00079 string PeekFullLine();
00080 string PeekFullLine(streampos& position);
00081 bool PeekFullLine(string& line);
00082 void SkipFullLines(int nb);
00083
00084 virtual string GetLine();
00085 virtual bool GetLine(string& line);
00086 virtual string PeekLine();
00087 virtual string PeekLine(streampos& position);
00088 virtual bool PeekLine(string& line);
00089 void SkipLines(int nb);
00090
00091 bool Find(string element);
00092 bool FindFromBeginning(string element);
00093
00094 virtual string GetElement();
00095 template <class T>
00096 bool GetElement(T& element);
00097 template <class T>
00098 bool GetRawElement(T& element);
00099 string PeekElement();
00100 template <class T>
00101 bool PeekElement(T& element);
00102 void SkipElements(int nb);
00103
00104 double GetNumber();
00105 template <class T>
00106 bool GetNumber(T& number);
00107 double PeekNumber();
00108 template <class T>
00109 bool PeekNumber(T& number);
00110 void SkipNumbers(int nb);
00111
00112 string GetValue(string name);
00113 string PeekValue(string name);
00114
00115 template <class T>
00116 bool GetValue(string name, T& value);
00117 template <class T>
00118 bool PeekValue(string name, T& value);
00119
00120 bool GetValue(string name, string& value);
00121 bool PeekValue(string name, string& value);
00122
00123 bool GetValue(string name, bool& value);
00124 bool PeekValue(string name, bool& value);
00125 };
00126
00128 class ConfigStream: public ExtStream
00129 {
00130 protected:
00131 string markup_tags_;
00132 string section_;
00133
00134 public:
00135 ConfigStream();
00136 ConfigStream(string file_name,
00137 string comments = "#%",
00138 string delimiters = " \t:=|\n,;",
00139 string markup_tags = "<>$");
00140
00141 void NoSection();
00142 void SetSection(string section);
00143 string GetSection() const;
00144
00145 void SetMarkupTags(string markup_tags);
00146 string GetMarkupTags() const;
00147
00148 bool IsEmpty();
00149
00150 bool Find(string element);
00151 bool FindFromBeginning(string element);
00152
00153 virtual string GetElement();
00154
00155 virtual string GetLine();
00156 virtual bool GetLine(string& line);
00157
00158 private:
00159 bool IsSection(string str) const;
00160
00161 friend class ConfigStreams;
00162 };
00163
00165 class ConfigStreams
00166 {
00167 protected:
00168 vector<ConfigStream*> streams_;
00169 vector<ConfigStream*>::iterator current_;
00170
00171 string section_;
00172
00173 public:
00174 ConfigStreams();
00175 ConfigStreams(const vector<string>& files);
00176 ConfigStreams(string file0);
00177 ConfigStreams(string file0, string file1);
00178 ConfigStreams(string file0, string file1, string file2);
00179
00180 ~ConfigStreams();
00181
00182 vector<ConfigStream*>& GetStreams();
00183 vector<ConfigStream*>::iterator GetCurrent();
00184
00185 void AddFile(string file);
00186
00187 void NoSection();
00188 void SetSection(string section);
00189 string GetSection() const;
00190
00191 bool Discard(string line) const;
00192 ConfigStreams& SkipDiscarded();
00193
00194 ConfigStreams& SkipDelimiters();
00195 string RemoveDelimiters(const string& str) const;
00196
00197 ConfigStreams& Skip();
00198
00199 bool IsEmpty();
00200
00201 ConfigStreams& Rewind();
00202
00203 string GetFullLine();
00204 bool GetFullLine(string& line);
00205 string PeekFullLine();
00206 string PeekFullLine(streampos& position);
00207 bool PeekFullLine(string& line);
00208 void SkipFullLines(int nb);
00209
00210 string GetRawLine();
00211 string GetLine();
00212 bool GetLine(string& line);
00213 string PeekLine();
00214 string PeekLine(streampos& position);
00215 bool PeekLine(string& line);
00216 void SkipLines(int nb);
00217
00218 bool Find(string element);
00219 bool FindFromBeginning(string element);
00220
00221 string GetRawElement();
00222 string GetElement();
00223 template <class T>
00224 bool GetElement(T& element);
00225 string PeekElement();
00226 template <class T>
00227 bool PeekElement(T& element);
00228 void SkipElements(int nb);
00229
00230 double GetNumber();
00231 template <class T>
00232 bool GetNumber(T& number);
00233 double PeekNumber();
00234 template <class T>
00235 bool PeekNumber(T& number);
00236 void SkipNumbers(int nb);
00237
00238 string GetValue(string name);
00239 string PeekValue(string name);
00240
00241 template <class T>
00242 bool GetValue(string name, T& value);
00243 template <class T>
00244 bool PeekValue(string name, T& value);
00245
00246 bool GetValue(string name, string& value);
00247 bool PeekValue(string name, string& value);
00248
00249 bool GetValue(string name, bool& value);
00250 bool PeekValue(string name, bool& value);
00251
00252 private:
00253 bool IsSection(string str) const;
00254 };
00255
00256 }
00257
00258
00259 #define TALOS_FILE_FILES_HXX
00260 #endif