File indexing completed on 2025-01-18 09:50:15
0001
0002
0003
0004
0005
0006
0007 #ifndef BOOST_VARIABLES_MAP_VP_2003_05_19
0008 #define BOOST_VARIABLES_MAP_VP_2003_05_19
0009
0010 #include <boost/program_options/config.hpp>
0011
0012 #include <boost/any.hpp>
0013 #include <boost/shared_ptr.hpp>
0014
0015 #include <string>
0016 #include <map>
0017 #include <set>
0018
0019 #if defined(BOOST_MSVC)
0020 # pragma warning (push)
0021 # pragma warning (disable:4251)
0022 #endif
0023
0024 namespace boost { namespace program_options {
0025
0026 template<class charT>
0027 class basic_parsed_options;
0028
0029 class value_semantic;
0030 class variables_map;
0031
0032
0033
0034
0035
0036
0037
0038 BOOST_PROGRAM_OPTIONS_DECL
0039 void store(const basic_parsed_options<char>& options, variables_map& m,
0040 bool utf8 = false);
0041
0042
0043
0044
0045
0046
0047 BOOST_PROGRAM_OPTIONS_DECL
0048 void store(const basic_parsed_options<wchar_t>& options,
0049 variables_map& m);
0050
0051
0052
0053 BOOST_PROGRAM_OPTIONS_DECL void notify(variables_map& m);
0054
0055
0056
0057
0058 class BOOST_PROGRAM_OPTIONS_DECL variable_value {
0059 public:
0060 variable_value() : m_defaulted(false) {}
0061 variable_value(const boost::any& xv, bool xdefaulted)
0062 : v(xv), m_defaulted(xdefaulted)
0063 {}
0064
0065
0066
0067 template<class T>
0068 const T& as() const {
0069 return boost::any_cast<const T&>(v);
0070 }
0071
0072 template<class T>
0073 T& as() {
0074 return boost::any_cast<T&>(v);
0075 }
0076
0077
0078 bool empty() const;
0079
0080
0081 bool defaulted() const;
0082
0083 const boost::any& value() const;
0084
0085
0086 boost::any& value();
0087 private:
0088 boost::any v;
0089 bool m_defaulted;
0090
0091
0092
0093
0094
0095 shared_ptr<const value_semantic> m_value_semantic;
0096
0097 friend BOOST_PROGRAM_OPTIONS_DECL
0098 void store(const basic_parsed_options<char>& options,
0099 variables_map& m, bool);
0100
0101 friend class BOOST_PROGRAM_OPTIONS_DECL variables_map;
0102 };
0103
0104
0105
0106 class BOOST_PROGRAM_OPTIONS_DECL abstract_variables_map {
0107 public:
0108 abstract_variables_map();
0109 abstract_variables_map(const abstract_variables_map* next);
0110
0111 virtual ~abstract_variables_map() {}
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127 const variable_value& operator[](const std::string& name) const;
0128
0129
0130
0131 void next(abstract_variables_map* next);
0132
0133 private:
0134
0135
0136 virtual const variable_value& get(const std::string& name) const = 0;
0137
0138 const abstract_variables_map* m_next;
0139 };
0140
0141
0142
0143
0144
0145
0146 class BOOST_PROGRAM_OPTIONS_DECL variables_map : public abstract_variables_map,
0147 public std::map<std::string, variable_value>
0148 {
0149 public:
0150 variables_map();
0151 variables_map(const abstract_variables_map* next);
0152
0153
0154 const variable_value& operator[](const std::string& name) const
0155 { return abstract_variables_map::operator[](name); }
0156
0157
0158 void clear();
0159
0160 void notify();
0161
0162 private:
0163
0164
0165 const variable_value& get(const std::string& name) const;
0166
0167
0168
0169 std::set<std::string> m_final;
0170
0171 friend BOOST_PROGRAM_OPTIONS_DECL
0172 void store(const basic_parsed_options<char>& options,
0173 variables_map& xm,
0174 bool utf8);
0175
0176
0177
0178
0179
0180 std::map<std::string, std::string> m_required;
0181 };
0182
0183
0184
0185
0186
0187
0188 inline bool
0189 variable_value::empty() const
0190 {
0191 return v.empty();
0192 }
0193
0194 inline bool
0195 variable_value::defaulted() const
0196 {
0197 return m_defaulted;
0198 }
0199
0200 inline
0201 const boost::any&
0202 variable_value::value() const
0203 {
0204 return v;
0205 }
0206
0207 inline
0208 boost::any&
0209 variable_value::value()
0210 {
0211 return v;
0212 }
0213
0214 }}
0215
0216 #if defined(BOOST_MSVC)
0217 # pragma warning (pop)
0218 #endif
0219
0220 #endif