errors.h
Go to the documentation of this file.
00001 //
00002 //  Copyright (c) Benjamin Kaufmann 2004
00003 //
00004 //  This is free software; you can redistribute it and/or modify
00005 //  it under the terms of the GNU General Public License as published by
00006 //  the Free Software Foundation; either version 2 of the License, or
00007 //  (at your option) any later version. 
00008 // 
00009 //  This file is distributed in the hope that it will be useful,
00010 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 //  GNU General Public License for more details.
00013 //
00014 //  You should have received a copy of the GNU General Public License
00015 //  along with this file; if not, write to the Free Software
00016 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017 //
00018 //
00019 // NOTE: ProgramOptions is inspired by Boost.Program_options
00020 //       see: www.boost.org/libs/program_options
00021 //
00022 #ifndef PROGRAM_OPTIONS_ERRORS_H_INCLUDED
00023 #define PROGRAM_OPTIONS_ERRORS_H_INCLUDED
00024 #include <stdexcept>
00025 #include <string>
00026 namespace ProgramOptions {
00027 
00029 class Error : public std::logic_error {
00030 public:
00031         explicit Error(const std::string& what) : std::logic_error(what) {}
00032 };
00033 
00035 class SyntaxError : public Error {
00036 public:
00037         enum Type {
00038                 missing_value,
00039                 extra_value,
00040                 invalid_format
00041         };
00042         SyntaxError(Type t, const std::string& key);
00043         ~SyntaxError() throw () {}
00044         Type               type() const { return type_; }
00045         const std::string& key()  const { return key_;  }
00046 private:
00047         std::string key_;
00048         Type        type_;
00049 };
00050 
00052 class ContextError : public Error {
00053 public:
00054         enum Type {
00055                 duplicate_option,
00056                 unknown_option,
00057                 ambiguous_option,
00058                 unknown_group,
00059         };
00060         ContextError(const std::string& ctx, Type t, const std::string& key, const std::string& desc = "");
00061         ~ContextError() throw () {}
00062         Type               type() const { return type_; }
00063         const std::string& key()  const { return key_;  }
00064         const std::string& ctx()  const { return ctx_;  }
00065 private:
00066         std::string ctx_;
00067         std::string key_;
00068         Type        type_;
00069 };
00070 
00071 class DuplicateOption : public ContextError {
00072 public:
00073         DuplicateOption(const std::string& ctx, const std::string& key) : ContextError(ctx, ContextError::duplicate_option, key) {}
00074         ~DuplicateOption() throw () {}
00075 };
00076 class UnknownOption : public ContextError {
00077 public:
00078         UnknownOption(const std::string& ctx, const std::string& key) : ContextError(ctx, ContextError::unknown_option, key) {}
00079         ~UnknownOption() throw () {}
00080 };
00081 class AmbiguousOption : public ContextError {
00082 public:
00083         AmbiguousOption(const std::string& ctx, const std::string& key, const std::string& alt) : ContextError(ctx, ContextError::ambiguous_option, key, alt) {}
00084         ~AmbiguousOption() throw () {}
00085 };
00086 
00088 class ValueError : public Error {
00089 public:
00090         enum Type {
00091                 multiple_occurences,
00092                 invalid_default,
00093                 invalid_value
00094         };
00095         ValueError(const std::string& ctx, Type t, const std::string& opt, const std::string& value);
00096         ~ValueError() throw () {}
00097         Type               type() const { return type_; }
00098         const std::string& key()  const { return key_;  }
00099         const std::string& ctx()  const { return ctx_;  }
00100         const std::string& value()const { return value_;}
00101 private:
00102         std::string ctx_;
00103         std::string key_;
00104         std::string value_;
00105         Type        type_;
00106 };
00107 
00108 
00109 }
00110 #endif


clasp
Author(s): Benjamin Kaufmann
autogenerated on Thu Aug 27 2015 12:41:39