RCS file: /cvsroot/boost/boost/boost/program_options/value_semantic.hpp,v
retrieving revision 1.13
diff -u -r1.13 value_semantic.hpp
|
|
|
204 | 204 | return this; |
205 | 205 | } |
206 | 206 | |
| 207 | typed_value* implicit_value(const T &v) |
| 208 | { |
| 209 | m_implicit_value = boost::any(v); |
| 210 | m_implicit_value_as_text = |
| 211 | boost::lexical_cast<std::string>(v); |
| 212 | return this; |
| 213 | } |
| 214 | |
| 215 | typed_value* implicit_value(const T &v, const std::string& textual) |
| 216 | { |
| 217 | m_implicit_value = boost::any(v); |
| 218 | m_implicit_value_as_text = textual; |
| 219 | return this; |
| 220 | } |
| 221 | |
207 | 222 | /** Specifies a function to be called when the final value |
208 | 223 | is determined. */ |
209 | 224 | typed_value* notifier(function1<void, const T&> f) |
… |
… |
|
243 | 258 | |
244 | 259 | unsigned min_tokens() const |
245 | 260 | { |
246 | | if (m_zero_tokens) { |
| 261 | if (m_zero_tokens || !m_implicit_value.empty()) { |
247 | 262 | return 0; |
248 | 263 | } else { |
249 | 264 | return 1; |
… |
… |
|
301 | 316 | // as boost::optional to avoid unnecessary instantiations. |
302 | 317 | boost::any m_default_value; |
303 | 318 | std::string m_default_value_as_text; |
| 319 | boost::any m_implicit_value; |
| 320 | std::string m_implicit_value_as_text; |
304 | 321 | bool m_composing, m_implicit, m_multitoken, m_zero_tokens; |
305 | 322 | boost::function1<void, const T&> m_notifier; |
306 | 323 | }; |
RCS file: /cvsroot/boost/boost/boost/program_options/detail/value_semantic.hpp,v
retrieving revision 1.15
diff -u -r1.15 value_semantic.hpp
|
|
|
16 | 16 | std::string |
17 | 17 | typed_value<T, charT>::name() const |
18 | 18 | { |
19 | | if (!m_default_value.empty() && !m_default_value_as_text.empty()) { |
| 19 | if (!m_implicit_value.empty() && !m_implicit_value_as_text.empty()) { |
| 20 | return "[=arg] (=" + m_implicit_value_as_text + ")"; |
| 21 | } |
| 22 | else if (!m_default_value.empty() && !m_default_value_as_text.empty()) { |
20 | 23 | return arg + " (=" + m_default_value_as_text + ")"; |
21 | | } else { |
| 24 | } |
| 25 | else { |
22 | 26 | return arg; |
23 | 27 | } |
24 | 28 | } |
… |
… |
|
27 | 31 | void |
28 | 32 | typed_value<T, charT>::notify(const boost::any& value_store) const |
29 | 33 | { |
30 | | const T* value = boost::any_cast<const T>(&value_store); |
| 34 | const T* value; |
| 35 | if (value_store.empty()) |
| 36 | value = boost::any_cast<const T>(&m_implicit_value); |
| 37 | else |
| 38 | value = boost::any_cast<const T>(&value_store); |
31 | 39 | if (m_store_to) { |
32 | 40 | *m_store_to = *value; |
33 | 41 | } |
… |
… |
|
148 | 156 | xparse(boost::any& value_store, |
149 | 157 | const std::vector<std::basic_string<charT> >& new_tokens) const |
150 | 158 | { |
151 | | validate(value_store, new_tokens, (T*)0, 0); |
| 159 | if (!new_tokens.empty() || m_implicit_value.empty()) |
| 160 | validate(value_store, new_tokens, (T*)0, 0); |
152 | 161 | } |
153 | 162 | |
154 | 163 | template<class T> |
RCS file: /cvsroot/boost/boost/libs/program_options/src/cmdline.cpp,v
retrieving revision 1.23
diff -u -r1.23 cmdline.cpp
|
|
|
329 | 329 | |
330 | 330 | max_tokens -= opt.value.size(); |
331 | 331 | |
| 332 | // A value is optional if min_tokens == 0, but max_tokens > 0. |
| 333 | // If a value is optional, it must appear in opt.value (because |
| 334 | // it was 'adjacent'. Otherwise, remove the expectation of a |
| 335 | // non-adjacent value. |
| 336 | if (min_tokens == 0 && max_tokens > 0 && opt.value.empty()) |
| 337 | --max_tokens; |
| 338 | |
332 | 339 | // Everything's OK, move the values to the result. |
333 | 340 | for(;!other_tokens.empty() && max_tokens--; ) { |
334 | 341 | opt.value.push_back(other_tokens[0]); |