1
// (C) Copyright Gennadiy Rozental 2005-2008.
2
// Use, modification, and distribution are subject to the
3
// Boost Software License, Version 1.0. (See accompanying file
4
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6
// See http://www.boost.org/libs/test for the library home page.
10
// Version : $Revision: 54633 $
12
// Description : defines model of formal parameter
13
// ***************************************************************************
15
#ifndef BOOST_RT_CLA_PARAMETER_HPP_062604GER
16
#define BOOST_RT_CLA_PARAMETER_HPP_062604GER
18
// Boost.Runtime.Parameter
19
#include <boost/test/utils/runtime/config.hpp>
21
#include <boost/test/utils/runtime/fwd.hpp>
22
#include <boost/test/utils/runtime/parameter.hpp>
23
#include <boost/test/utils/runtime/validation.hpp>
25
#include <boost/test/utils/runtime/cla/fwd.hpp>
26
#include <boost/test/utils/runtime/cla/modifier.hpp>
27
#include <boost/test/utils/runtime/cla/iface/argument_factory.hpp>
28
#include <boost/test/utils/runtime/cla/iface/id_policy.hpp>
31
#include <boost/test/utils/rtti.hpp>
35
namespace BOOST_RT_PARAM_NAMESPACE {
39
// ************************************************************************** //
40
// ************** runtime::cla::parameter ************** //
41
// ************************************************************************** //
43
class parameter : public BOOST_RT_PARAM_NAMESPACE::parameter {
45
parameter( identification_policy& ID, argument_factory& F, bool optional_value = false )
47
, p_multiplicable( false )
48
, p_optional_value( optional_value )
54
virtual ~parameter() {}
56
unit_test::readwrite_property<bool> p_optional;
57
unit_test::readwrite_property<bool> p_multiplicable;
58
unit_test::readwrite_property<bool> p_optional_value;
59
unit_test::readwrite_property<dstring> p_description;
61
// parameter properties modification
62
template<typename Modifier>
63
void accept_modifier( Modifier const& m )
65
if( m.has( optional_m ) )
66
p_optional.value = true;
68
if( m.has( required_m ) )
69
p_optional.value = false;
71
if( m.has( multiplicable_m ) )
72
p_multiplicable.value = true;
74
if( m.has( optional_value_m ) )
75
p_optional_value.value = true;
77
nfp::optionally_assign( p_description.value, m, description );
81
bool has_argument() const { return m_actual_argument; }
82
argument const& actual_argument() const { return *m_actual_argument; }
83
argument_ptr actual_argument() { return m_actual_argument; }
86
// identification interface
87
bool responds_to( cstring name ) const { return m_id_policy.responds_to( name ); }
88
bool conflict_with( parameter const& p ) const
90
return (id_2_report() == p.id_2_report() && !id_2_report().is_empty()) ||
91
m_id_policy.conflict_with( p.m_id_policy ) ||
92
((m_id_policy.p_type_id != p.m_id_policy.p_type_id) && p.m_id_policy.conflict_with( m_id_policy ));
94
cstring id_2_report() const { return m_id_policy.id_2_report(); }
95
void usage_info( format_stream& fs ) const
97
m_id_policy.usage_info( fs );
98
if( p_optional_value )
99
fs << BOOST_RT_PARAM_LITERAL( '[' );
101
m_arg_factory.argument_usage_info( fs );
103
if( p_optional_value )
104
fs << BOOST_RT_PARAM_LITERAL( ']' );
107
// argument match/produce based on input
108
bool matching( argv_traverser& tr, bool primary ) const
110
return m_id_policy.matching( *this, tr, primary );
113
// argument production based on different source
114
void produce_argument( argv_traverser& tr )
116
m_id_policy.matching( *this, tr, true ); // !! can we save this position somehow
117
m_actual_argument = m_arg_factory.produce_using( *this, tr );
119
void produce_argument( parser const& p )
121
m_actual_argument = m_arg_factory.produce_using( *this, p );
126
identification_policy& m_id_policy;
127
argument_factory& m_arg_factory;
128
argument_ptr m_actual_argument;
131
//____________________________________________________________________________//
133
template<typename Parameter,typename Modifier>
134
inline shared_ptr<Parameter>
135
operator-( shared_ptr<Parameter> p, Modifier const& m )
137
p->accept_modifier( m );
142
//____________________________________________________________________________//
146
} // namespace BOOST_RT_PARAM_NAMESPACE
150
#endif // BOOST_RT_CLA_PARAMETER_HPP_062604GER