File indexing completed on 2025-01-18 09:50:15
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef BOOST_OPTION_DESCRIPTION_VP_2003_05_19
0009 #define BOOST_OPTION_DESCRIPTION_VP_2003_05_19
0010
0011 #include <boost/program_options/config.hpp>
0012 #include <boost/program_options/errors.hpp>
0013 #include <boost/program_options/value_semantic.hpp>
0014
0015 #include <boost/function.hpp>
0016 #include <boost/shared_ptr.hpp>
0017 #include <boost/detail/workaround.hpp>
0018 #include <boost/any.hpp>
0019
0020 #include <string>
0021 #include <vector>
0022 #include <set>
0023 #include <map>
0024 #include <stdexcept>
0025 #include <utility>
0026
0027 #include <iosfwd>
0028
0029 #if defined(BOOST_MSVC)
0030 # pragma warning (push)
0031 # pragma warning (disable:4251)
0032 #endif
0033
0034
0035
0036 namespace boost {
0037
0038 namespace program_options {
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048 class BOOST_PROGRAM_OPTIONS_DECL option_description {
0049 public:
0050
0051 option_description();
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077 option_description(const char* name,
0078 const value_semantic* s);
0079
0080
0081
0082 option_description(const char* name,
0083 const value_semantic* s,
0084 const char* description);
0085
0086 virtual ~option_description();
0087
0088 enum match_result { no_match, full_match, approximate_match };
0089
0090
0091
0092
0093 match_result match(const std::string& option, bool approx,
0094 bool long_ignore_case, bool short_ignore_case) const;
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104 const std::string& key(const std::string& option) const;
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114 std::string canonical_display_name(int canonical_option_style = 0) const;
0115
0116 const std::string& long_name() const;
0117
0118 const std::pair<const std::string*, std::size_t> long_names() const;
0119
0120
0121 const std::string& description() const;
0122
0123
0124 shared_ptr<const value_semantic> semantic() const;
0125
0126
0127 std::string format_name() const;
0128
0129
0130
0131 std::string format_parameter() const;
0132
0133 private:
0134
0135 option_description& set_names(const char* name);
0136
0137
0138
0139
0140
0141 std::string m_short_name;
0142
0143
0144
0145
0146
0147
0148
0149 std::vector<std::string> m_long_names;
0150
0151 std::string m_description;
0152
0153
0154
0155 shared_ptr<const value_semantic> m_value_semantic;
0156 };
0157
0158 class options_description;
0159
0160
0161
0162 class BOOST_PROGRAM_OPTIONS_DECL options_description_easy_init {
0163 public:
0164 options_description_easy_init(options_description* owner);
0165
0166 options_description_easy_init&
0167 operator()(const char* name,
0168 const char* description);
0169
0170 options_description_easy_init&
0171 operator()(const char* name,
0172 const value_semantic* s);
0173
0174 options_description_easy_init&
0175 operator()(const char* name,
0176 const value_semantic* s,
0177 const char* description);
0178
0179 private:
0180 options_description* owner;
0181 };
0182
0183
0184
0185
0186
0187
0188
0189
0190
0191 class BOOST_PROGRAM_OPTIONS_DECL options_description {
0192 public:
0193 static const unsigned m_default_line_length;
0194
0195
0196 options_description(unsigned line_length = m_default_line_length,
0197 unsigned min_description_length = m_default_line_length / 2);
0198
0199
0200
0201
0202
0203
0204
0205 options_description(const std::string& caption,
0206 unsigned line_length = m_default_line_length,
0207 unsigned min_description_length = m_default_line_length / 2);
0208
0209
0210
0211 void add(shared_ptr<option_description> desc);
0212
0213
0214
0215
0216
0217
0218 options_description& add(const options_description& desc);
0219
0220
0221
0222 unsigned get_option_column_width() const;
0223
0224 public:
0225
0226
0227
0228
0229
0230
0231 options_description_easy_init add_options();
0232
0233 const option_description& find(const std::string& name,
0234 bool approx,
0235 bool long_ignore_case = false,
0236 bool short_ignore_case = false) const;
0237
0238 const option_description* find_nothrow(const std::string& name,
0239 bool approx,
0240 bool long_ignore_case = false,
0241 bool short_ignore_case = false) const;
0242
0243
0244 const std::vector< shared_ptr<option_description> >& options() const;
0245
0246
0247
0248
0249 friend BOOST_PROGRAM_OPTIONS_DECL std::ostream& operator<<(std::ostream& os,
0250 const options_description& desc);
0251
0252
0253
0254 void print(std::ostream& os, unsigned width = 0) const;
0255
0256 private:
0257 #if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1800))
0258
0259 options_description& operator=(const options_description&);
0260 #endif
0261
0262 typedef std::map<std::string, int>::const_iterator name2index_iterator;
0263 typedef std::pair<name2index_iterator, name2index_iterator>
0264 approximation_range;
0265
0266
0267
0268 std::string m_caption;
0269 const unsigned m_line_length;
0270 const unsigned m_min_description_length;
0271
0272
0273
0274
0275 std::vector< shared_ptr<option_description> > m_options;
0276
0277
0278 #if BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, BOOST_TESTED_AT(313))
0279
0280
0281 std::vector<char> belong_to_group;
0282 #else
0283 std::vector<bool> belong_to_group;
0284 #endif
0285
0286 std::vector< shared_ptr<options_description> > groups;
0287
0288 };
0289
0290
0291 class BOOST_PROGRAM_OPTIONS_DECL duplicate_option_error : public error {
0292 public:
0293 duplicate_option_error(const std::string& xwhat) : error(xwhat) {}
0294 };
0295 }}
0296
0297 #if defined(BOOST_MSVC)
0298 # pragma warning (pop)
0299 #endif
0300
0301 #endif