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,;\r\x0D\x0A");
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
00174 string searching_;
00175
00176 public:
00177 ConfigStreams();
00178 ConfigStreams(const vector<string>& files);
00179 ConfigStreams(string file0);
00180 ConfigStreams(string file0, string file1);
00181 ConfigStreams(string file0, string file1, string file2);
00182
00183 ~ConfigStreams();
00184
00185 vector<ConfigStream*>& GetStreams();
00186 vector<ConfigStream*>::iterator GetCurrent();
00187
00188 void AddFile(string file);
00189
00190 void NoSection();
00191 void SetSection(string section);
00192 string GetSection() const;
00193
00194 bool Discard(string line) const;
00195 ConfigStreams& SkipDiscarded();
00196
00197 ConfigStreams& SkipDelimiters();
00198 string RemoveDelimiters(const string& str) const;
00199
00200 ConfigStreams& Skip();
00201
00202 bool IsEmpty();
00203
00204 ConfigStreams& Rewind();
00205
00206 string GetFullLine();
00207 bool GetFullLine(string& line);
00208 string PeekFullLine();
00209 string PeekFullLine(streampos& position);
00210 bool PeekFullLine(string& line);
00211 void SkipFullLines(int nb);
00212
00213 string GetRawLine();
00214 string GetLine();
00215 bool GetLine(string& line);
00216 string PeekLine();
00217 string PeekLine(streampos& position);
00218 bool PeekLine(string& line);
00219 void SkipLines(int nb);
00220
00221 bool Find(string element);
00222 bool FindFromBeginning(string element);
00223
00224 string GetRawElement();
00225 string GetElement();
00226 template <class T>
00227 bool GetElement(T& element);
00228 string PeekElement();
00229 template <class T>
00230 bool PeekElement(T& element);
00231 void SkipElements(int nb);
00232
00233 double GetNumber();
00234 template <class T>
00235 bool GetNumber(T& number);
00236 double PeekNumber();
00237 template <class T>
00238 bool PeekNumber(T& number);
00239 void SkipNumbers(int nb);
00240
00241 string GetValue(string name);
00242 string PeekValue(string name);
00243
00244 template <class T>
00245 bool GetValue(string name, T& value);
00246 template <class T>
00247 bool PeekValue(string name, T& value);
00248
00249 bool GetValue(string name, string& value);
00250 bool PeekValue(string name, string& value);
00251
00252 bool GetValue(string name, bool& value);
00253 bool PeekValue(string name, bool& value);
00254
00255 private:
00256 bool IsSection(string str) const;
00257 string FileNames() const;
00258 };
00259
00260 }
00261
00262
00263 #define TALOS_FILE_FILES_HXX
00264 #endif