12
12
#include < boost/any.hpp>
13
13
#include < boost/function/function1.hpp>
14
14
#include < boost/lexical_cast.hpp>
15
+ #include < boost/smart_ptr/enable_shared_from_this.hpp>
15
16
16
17
#include < string>
17
18
#include < vector>
@@ -178,7 +179,8 @@ namespace boost { namespace program_options {
178
179
179
180
/* * Class which handles value of a specific type. */
180
181
template <class T , class charT = char >
181
- class typed_value : public value_semantic_codecvt_helper <charT>
182
+ class typed_value : public enable_shared_from_this <typed_value<T, charT>>,
183
+ public value_semantic_codecvt_helper<charT>
182
184
#ifndef BOOST_NO_RTTI
183
185
, public typed_value_base
184
186
#endif
@@ -196,11 +198,11 @@ namespace boost { namespace program_options {
196
198
if none is explicitly specified. The type 'T' should
197
199
provide operator<< for ostream.
198
200
*/
199
- typed_value* default_value (const T& v)
201
+ shared_ptr< typed_value> default_value (const T& v)
200
202
{
201
203
m_default_value = boost::any (v);
202
204
m_default_value_as_text = boost::lexical_cast<std::string>(v);
203
- return this ;
205
+ return this -> shared_from_this () ;
204
206
}
205
207
206
208
/* * Specifies default value, which will be used
@@ -209,30 +211,30 @@ namespace boost { namespace program_options {
209
211
but textual representation of default value must be provided
210
212
by the user.
211
213
*/
212
- typed_value* default_value (const T& v, const std::string& textual)
214
+ shared_ptr< typed_value> default_value (const T& v, const std::string& textual)
213
215
{
214
216
m_default_value = boost::any (v);
215
217
m_default_value_as_text = textual;
216
- return this ;
218
+ return this -> shared_from_this () ;
217
219
}
218
220
219
221
/* * Specifies an implicit value, which will be used
220
222
if the option is given, but without an adjacent value.
221
223
Using this implies that an explicit value is optional,
222
224
*/
223
- typed_value* implicit_value (const T &v)
225
+ shared_ptr< typed_value> implicit_value (const T &v)
224
226
{
225
227
m_implicit_value = boost::any (v);
226
228
m_implicit_value_as_text =
227
229
boost::lexical_cast<std::string>(v);
228
- return this ;
230
+ return this -> shared_from_this () ;
229
231
}
230
232
231
233
/* * Specifies the name used to to the value in help message. */
232
- typed_value* value_name (const std::string& name)
234
+ shared_ptr< typed_value> value_name (const std::string& name)
233
235
{
234
236
m_value_name = name;
235
- return this ;
237
+ return this -> shared_from_this () ;
236
238
}
237
239
238
240
/* * Specifies an implicit value, which will be used
@@ -245,36 +247,36 @@ namespace boost { namespace program_options {
245
247
operator<< for ostream, but textual representation of default
246
248
value must be provided by the user.
247
249
*/
248
- typed_value* implicit_value (const T &v, const std::string& textual)
250
+ shared_ptr< typed_value> implicit_value (const T &v, const std::string& textual)
249
251
{
250
252
m_implicit_value = boost::any (v);
251
253
m_implicit_value_as_text = textual;
252
- return this ;
254
+ return this -> shared_from_this () ;
253
255
}
254
256
255
257
/* * Specifies a function to be called when the final value
256
258
is determined. */
257
- typed_value* notifier (function1<void , const T&> f)
259
+ shared_ptr< typed_value> notifier (function1<void , const T&> f)
258
260
{
259
261
m_notifier = f;
260
- return this ;
262
+ return this -> shared_from_this () ;
261
263
}
262
264
263
265
/* * Specifies that the value is composing. See the 'is_composing'
264
266
method for explanation.
265
267
*/
266
- typed_value* composing ()
268
+ shared_ptr< typed_value> composing ()
267
269
{
268
270
m_composing = true ;
269
- return this ;
271
+ return this -> shared_from_this () ;
270
272
}
271
273
272
274
/* * Specifies that the value can span multiple tokens.
273
275
*/
274
- typed_value* multitoken ()
276
+ shared_ptr< typed_value> multitoken ()
275
277
{
276
278
m_multitoken = true ;
277
- return this ;
279
+ return this -> shared_from_this () ;
278
280
}
279
281
280
282
/* * Specifies that no tokens may be provided as the value of
@@ -284,17 +286,17 @@ namespace boost { namespace program_options {
284
286
'implicit_value' method should be also used. In most
285
287
cases, you can use the 'bool_switch' function instead of
286
288
using this method. */
287
- typed_value* zero_tokens ()
289
+ shared_ptr< typed_value> zero_tokens ()
288
290
{
289
291
m_zero_tokens = true ;
290
- return this ;
292
+ return this -> shared_from_this () ;
291
293
}
292
294
293
295
/* * Specifies that the value must occur. */
294
- typed_value* required ()
296
+ shared_ptr< typed_value> required ()
295
297
{
296
298
m_required = true ;
297
- return this ;
299
+ return this -> shared_from_this () ;
298
300
}
299
301
300
302
public: // value semantic overrides
@@ -381,39 +383,39 @@ namespace boost { namespace program_options {
381
383
value of option into program variable.
382
384
*/
383
385
template <class T >
384
- typed_value<T>*
386
+ shared_ptr< typed_value<T>>
385
387
value ();
386
388
387
389
/* * @overload
388
390
*/
389
391
template <class T >
390
- typed_value<T>*
392
+ shared_ptr< typed_value<T>>
391
393
value (T* v);
392
394
393
395
/* * Creates a typed_value<T> instance. This function is the primary
394
396
method to create value_semantic instance for a specific type, which
395
397
can later be passed to 'option_description' constructor.
396
398
*/
397
399
template <class T >
398
- typed_value<T, wchar_t >*
400
+ shared_ptr< typed_value<T, wchar_t >>
399
401
wvalue ();
400
402
401
403
/* * @overload
402
404
*/
403
405
template <class T >
404
- typed_value<T, wchar_t >*
406
+ shared_ptr< typed_value<T, wchar_t >>
405
407
wvalue (T* v);
406
408
407
409
/* * Works the same way as the 'value<bool>' function, but the created
408
410
value_semantic won't accept any explicit value. So, if the option
409
411
is present on the command line, the value will be 'true'.
410
412
*/
411
- BOOST_PROGRAM_OPTIONS_DECL typed_value<bool >*
413
+ BOOST_PROGRAM_OPTIONS_DECL shared_ptr< typed_value<bool >>
412
414
bool_switch ();
413
415
414
416
/* * @overload
415
417
*/
416
- BOOST_PROGRAM_OPTIONS_DECL typed_value<bool >*
418
+ BOOST_PROGRAM_OPTIONS_DECL shared_ptr< typed_value<bool >>
417
419
bool_switch (bool * v);
418
420
419
421
}}
0 commit comments