00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifndef EXCEPTIONS_HEADER // Begin the Header Guard to prevent
00034 #define EXCEPTIONS_HEADER // multiple inclusions.
00035
00036 #include <exception>
00037 #include <string>
00038 #include <vector>
00039
00040 namespace commandl
00041 {
00042 class argument;
00043
00044
00045
00046
00047 class exception : public std::exception
00048 {
00049
00050
00051 public:
00052
00053
00054 exception( const std::string& what_message )
00055 : What( what_message )
00056 { }
00057
00058 virtual ~exception() throw()
00059 { }
00060
00061
00062 public:
00063
00064 virtual const char* what() const throw() { return What.c_str(); }
00065
00066
00067
00068 protected:
00069
00071 std::string What;
00072
00073 };
00074
00075
00076
00080 class argument_exception : public exception
00081 {
00082
00083
00084 public:
00085
00086
00087
00088
00089
00090
00091
00092 argument_exception (
00093 const std::string& what_message,
00094 commandl::argument* argument
00095 )
00096 : commandl::exception( what_message ),
00097 Arg_ptr( argument )
00098 { }
00099
00100 argument_exception (
00101 const std::string& what_message,
00102 commandl::argument* argument,
00103 const std::string& prefix,
00104 const std::string& key
00105 )
00106 : commandl::exception( what_message ),
00107 Arg_ptr( argument ),
00108 Prefix( prefix ),
00109 Key( key )
00110 { }
00111
00112 argument_exception (
00113 const std::string& what_message,
00114 commandl::argument* argument,
00115 const std::string& prefix,
00116 const std::string& key,
00117 const std::string& assign,
00118 const std::string& value
00119 )
00120 : commandl::exception( what_message ),
00121 Arg_ptr( argument ),
00122 Prefix( prefix ),
00123 Key( key ),
00124 Assign( assign )
00125 {
00126 Values.push_back( value );
00127 }
00128
00129 argument_exception (
00130 const std::string& what_message,
00131 commandl::argument* argument,
00132 const std::string& prefix,
00133 const std::string& key,
00134 const std::string& assign,
00135 const std::vector<std::string>& values
00136 )
00137 : commandl::exception( what_message ),
00138 Arg_ptr( argument ),
00139 Prefix( prefix ),
00140 Key( key ),
00141 Assign( assign ),
00142 Values( values )
00143 { }
00144
00145 virtual ~argument_exception() throw()
00146 { }
00147
00148
00149 public:
00150
00151 virtual argument* arg_ptr() const { return Arg_ptr; }
00152 virtual std::string prefix() const { return Prefix; }
00153 virtual std::string key() const { return Key; }
00154 virtual std::string assign() const { return Assign; }
00155 virtual std::vector<std::string> values() const { return Values; }
00156
00157
00158
00159 public:
00160
00161
00162
00163 protected:
00164
00165
00166
00167 private:
00168
00169
00170
00171 protected:
00172
00174 commandl::argument* Arg_ptr;
00175
00177 std::string Prefix;
00178
00180 std::string Key;
00181
00183 std::string Assign;
00184
00186 std::vector<std::string> Values;
00187
00188 };
00189
00190
00191
00195 class matcher_exception : public exception
00196 {
00197
00198
00199 public:
00200
00204 matcher_exception( const std::string& what_message )
00205 : commandl::exception( what_message )
00206 { }
00207
00215 matcher_exception (
00216 const std::string& what_message,
00217 const std::string& key
00218 )
00219 : commandl::exception( what_message ),
00220 Key( key )
00221 { }
00222
00223 virtual ~matcher_exception() throw()
00224 { }
00225
00226
00227 public:
00228
00229 virtual std::string key() const { return Key; }
00230
00231
00232
00233 public:
00234
00235
00236
00237 protected:
00238
00239
00240
00241 private:
00242
00243
00244
00245 protected:
00246
00247 std::string Key;
00248
00249
00250 };
00251
00252
00256 class parser_exception : public exception
00257 {
00258
00259
00260 public:
00261
00262 parser_exception( const std::string& what_message )
00263 : commandl::exception( what_message )
00264 { }
00265
00266 parser_exception
00267 (
00268 const std::string& what_message,
00269 const std::string& element
00270 )
00271 : commandl::exception( what_message ),
00272 Element( element )
00273 { }
00274
00275 virtual ~parser_exception() throw()
00276 { }
00277
00278
00279 public:
00280
00281 std::string element() const
00282 {
00283 return Element;
00284 }
00285
00286
00287 protected:
00288
00289 std::string Element;
00290
00291 };
00292
00293
00297 class no_prefix : public parser_exception
00298 {
00299
00300
00301 public:
00302
00303 no_prefix( const std::string& what_message )
00304 : parser_exception( what_message )
00305 { }
00306
00307 no_prefix( const std::string& what_message, const std::string& element )
00308 : parser_exception( what_message, element )
00309 { }
00310
00311 ~no_prefix() throw()
00312 { }
00313
00314
00315 };
00316
00317
00321 class stop_parsing: public parser_exception
00322 {
00323
00324
00325 public:
00326
00327 stop_parsing( const std::string& what_message )
00328 : parser_exception( what_message )
00329 { }
00330
00331 stop_parsing( const std::string& what_message, const std::string& element )
00332 : parser_exception( what_message, element )
00333 { }
00334
00335 ~stop_parsing() throw()
00336 { }
00337
00338 };
00339
00340
00345 class usage_exception: public parser_exception
00346 {
00347
00348
00349 public:
00350
00351 usage_exception( const std::string& what_message )
00352 : parser_exception( what_message )
00353 { }
00354
00355 usage_exception
00356 (
00357 const std::string& what_message,
00358 const std::string& element
00359 )
00360 : parser_exception( what_message, element )
00361 { }
00362
00363 ~usage_exception() throw()
00364 { }
00365
00366 };
00367
00368
00369
00373 class no_key: public parser_exception
00374 {
00375
00376
00377 public:
00378
00379 no_key( const std::string& what_message )
00380 : parser_exception( what_message )
00381 { }
00382
00383 no_key( const std::string& what_message, const std::string& element )
00384 : parser_exception( what_message, element )
00385 { }
00386
00387 ~no_key() throw()
00388 { }
00389
00390
00391 };
00392
00393
00394 }
00395
00396 #endif // End the Header Guard
00397