Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/boost/program_options/errors.hpp @ 56

Last change on this file since 56 was 29, checked in by landauf, 17 years ago

updated boost from 1_33_1 to 1_34_1

File size: 4.6 KB
Line 
1// Copyright Vladimir Prus 2002-2004.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt
4// or copy at http://www.boost.org/LICENSE_1_0.txt)
5
6
7#ifndef BOOST_ERRORS_VP_2003_01_02
8#define BOOST_ERRORS_VP_2003_01_02
9
10#include <boost/program_options/config.hpp>
11
12#include <string>
13#include <stdexcept>
14#include <vector>
15
16
17
18namespace boost { namespace program_options {
19
20    /** Base class for all errors in the library. */
21    class BOOST_PROGRAM_OPTIONS_DECL error : public std::logic_error {
22    public:
23        error(const std::string& what) : std::logic_error(what) {}
24    };
25
26    class BOOST_PROGRAM_OPTIONS_DECL invalid_syntax : public error {
27    public:
28        invalid_syntax(const std::string& tokens, const std::string& msg)
29        : error(std::string(msg).append(" in '").append(tokens).append("'")),
30          tokens(tokens), msg(msg)                       
31        {}
32
33        // gcc says that throw specification on dtor is loosened
34        // without this line
35        ~invalid_syntax() throw() {}
36
37        // TODO: copy ctor might throw
38        std::string tokens, msg;
39    };
40
41    /** Class thrown when option name is not recognized. */
42    class BOOST_PROGRAM_OPTIONS_DECL unknown_option : public error {
43    public:
44        unknown_option(const std::string& name)
45        : error(std::string("unknown option ").append(name)) 
46        {}
47    };
48
49    /** Class thrown when there's ambiguity amoung several possible options. */
50    class BOOST_PROGRAM_OPTIONS_DECL ambiguous_option : public error {
51    public:
52        ambiguous_option(const std::string& name, 
53                         const std::vector<std::string>& alternatives)
54        : error(std::string("ambiguous option ").append(name)),
55          alternatives(alternatives)
56        {}
57
58        ~ambiguous_option() throw() {}
59
60        // TODO: copy ctor might throw
61        std::vector<std::string> alternatives;
62    };
63
64    /** Class thrown when there are several option values, but
65        user called a method which cannot return them all. */
66    class BOOST_PROGRAM_OPTIONS_DECL multiple_values : public error {
67    public:
68        multiple_values(const std::string& what) : error(what) {}
69    };
70
71    /** Class thrown when there are several occurrences of an
72        option, but user called a method which cannot return
73        them all. */
74    class BOOST_PROGRAM_OPTIONS_DECL multiple_occurrences : public error {
75    public:
76        multiple_occurrences(const std::string& what) : error(what) {}
77    };
78
79    /** Class thrown when value of option is incorrect. */
80    class BOOST_PROGRAM_OPTIONS_DECL validation_error : public error {
81    public:
82        validation_error(const std::string& what) : error(what) {}
83        ~validation_error() throw() {}
84        void set_option_name(const std::string& option);
85
86        const char* what() const throw();
87    private:
88        mutable std::string m_message; // For on-demand formatting in 'what'
89        std::string m_option_name; // The name of the option which
90                                   // caused the exception.
91    };
92
93    class BOOST_PROGRAM_OPTIONS_DECL invalid_option_value 
94        : public validation_error
95    {
96    public:
97        invalid_option_value(const std::string& value);
98#ifndef BOOST_NO_STD_WSTRING
99        invalid_option_value(const std::wstring& value);
100#endif
101    };
102
103    /** Class thrown when there are too many positional options. */
104    class BOOST_PROGRAM_OPTIONS_DECL too_many_positional_options_error : public error {
105    public:
106        too_many_positional_options_error(const std::string& what) 
107        : error(what) {}
108    };
109
110    /** Class thrown when there are too few positional options. */
111    class BOOST_PROGRAM_OPTIONS_DECL too_few_positional_options_error : public error {
112    public:
113        too_few_positional_options_error(const std::string& what) 
114        : error(what) {}
115    };
116
117    class BOOST_PROGRAM_OPTIONS_DECL invalid_command_line_syntax : public invalid_syntax {
118    public:
119        enum kind_t {
120            long_not_allowed = 30,
121            long_adjacent_not_allowed,
122            short_adjacent_not_allowed,
123            empty_adjacent_parameter,
124            missing_parameter,
125            extra_parameter
126        };
127
128        invalid_command_line_syntax(const std::string& tokens, kind_t kind);
129        kind_t kind() const;
130    protected:
131        static std::string error_message(kind_t kind);
132    private:
133        kind_t m_kind;       
134    };
135
136    class BOOST_PROGRAM_OPTIONS_DECL invalid_command_line_style : public error {
137    public:
138        invalid_command_line_style(const std::string& msg)
139        : error(msg)
140        {}
141    };
142
143}}
144
145
146#endif
Note: See TracBrowser for help on using the repository browser.