00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef PALUDIS_GUARD_PALUDIS_CONFIG_FILE_HH
00021 #define PALUDIS_GUARD_PALUDIS_CONFIG_FILE_HH 1
00022
00023 #include <paludis/util/config_file-fwd.hh>
00024 #include <paludis/util/map-fwd.hh>
00025 #include <paludis/util/exception.hh>
00026 #include <paludis/util/instantiation_policy.hh>
00027 #include <paludis/util/private_implementation_pattern.hh>
00028 #include <paludis/util/options-fwd.hh>
00029 #include <paludis/util/wrapped_forward_iterator-fwd.hh>
00030 #include <paludis/util/fs_entry-fwd.hh>
00031
00032 #include <iosfwd>
00033 #include <string>
00034 #include <tr1/memory>
00035 #include <tr1/functional>
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047 namespace paludis
00048 {
00049
00050
00051
00052
00053
00054
00055
00056 class PALUDIS_VISIBLE ConfigFileError :
00057 public ConfigurationError
00058 {
00059 public:
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070 ConfigFileError(const std::string & filename, const std::string & message) throw ();
00071
00072
00073
00074
00075
00076
00077 ConfigFileError(const std::string & message) throw ();
00078
00079
00080 };
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094 class PALUDIS_VISIBLE ConfigFile
00095 {
00096 public:
00097
00098
00099
00100
00101
00102
00103
00104 class PALUDIS_VISIBLE Source :
00105 private PrivateImplementationPattern<Source>
00106 {
00107 public:
00108
00109
00110
00111 Source(const FSEntry &);
00112 Source(const std::string &);
00113 Source(std::istream &);
00114
00115 Source(const Source &);
00116 const Source & operator= (const Source &);
00117
00118 ~Source();
00119
00120
00121
00122
00123
00124
00125 const std::string & text() const PALUDIS_ATTRIBUTE((warn_unused_result));
00126
00127
00128
00129
00130 const std::string & filename() const PALUDIS_ATTRIBUTE((warn_unused_result));
00131 };
00132
00133
00134
00135
00136 virtual ~ConfigFile() = 0;
00137
00138
00139 };
00140
00141
00142
00143
00144
00145
00146
00147
00148 typedef Options<LineConfigFileOption> LineConfigFileOptions;
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163 class PALUDIS_VISIBLE LineConfigFile :
00164 public ConfigFile,
00165 private PrivateImplementationPattern<LineConfigFile>
00166 {
00167 public:
00168
00169
00170
00171 LineConfigFile(const Source &, const LineConfigFileOptions &);
00172
00173 ~LineConfigFile();
00174
00175
00176
00177
00178
00179
00180 struct ConstIteratorTag;
00181 typedef WrappedForwardIterator<ConstIteratorTag, const std::string> ConstIterator;
00182
00183 ConstIterator begin() const PALUDIS_ATTRIBUTE((warn_unused_result));
00184 ConstIterator end() const PALUDIS_ATTRIBUTE((warn_unused_result));
00185
00186
00187 };
00188
00189
00190
00191
00192
00193
00194
00195 typedef Options<KeyValueConfigFileOption> KeyValueConfigFileOptions;
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216 class PALUDIS_VISIBLE KeyValueConfigFile :
00217 public ConfigFile,
00218 private PrivateImplementationPattern<KeyValueConfigFile>
00219 {
00220 public:
00221 typedef std::tr1::function<std::string (const KeyValueConfigFile &, const std::string &)> DefaultFunction;
00222 typedef std::tr1::function<std::string (const KeyValueConfigFile &,
00223 const std::string & var, const std::string & old_value, const std::string & new_value)> TransformationFunction;
00224
00225 static std::string no_defaults(const KeyValueConfigFile &, const std::string &);
00226 static std::string no_transformation(const KeyValueConfigFile &, const std::string &, const std::string &, const std::string &);
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236 KeyValueConfigFile(
00237 const Source &,
00238 const KeyValueConfigFileOptions &,
00239 const DefaultFunction &,
00240 const TransformationFunction &
00241 );
00242
00243 ~KeyValueConfigFile();
00244
00245
00246
00247
00248
00249
00250 struct ConstIteratorTag;
00251 typedef WrappedForwardIterator<ConstIteratorTag,
00252 const std::pair<const std::string, std::string> > ConstIterator;
00253 ConstIterator begin() const PALUDIS_ATTRIBUTE((warn_unused_result));
00254 ConstIterator end() const PALUDIS_ATTRIBUTE((warn_unused_result));
00255
00256
00257
00258
00259
00260
00261 std::string get(const std::string &) const PALUDIS_ATTRIBUTE((warn_unused_result));
00262
00263 const KeyValueConfigFileOptions & options() const PALUDIS_ATTRIBUTE((warn_unused_result));
00264 const DefaultFunction & default_function() const PALUDIS_ATTRIBUTE((warn_unused_result));
00265 const TransformationFunction & transformation_function() const PALUDIS_ATTRIBUTE((warn_unused_result));
00266 };
00267
00268 #ifdef PALUDIS_HAVE_EXTERN_TEMPLATE
00269 extern template class PrivateImplementationPattern<ConfigFile::Source>;
00270 extern template class PrivateImplementationPattern<LineConfigFile>;
00271 extern template class PrivateImplementationPattern<KeyValueConfigFile>;
00272 #endif
00273
00274 }
00275
00276 #endif