1 | // (C) Copyright Gennadiy Rozental 2005.
|
---|
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)
|
---|
5 |
|
---|
6 | // See http://www.boost.org/libs/test for the library home page.
|
---|
7 | //
|
---|
8 | // File : $RCSfile: parameter.hpp,v $
|
---|
9 | //
|
---|
10 | // Version : $Revision: 1.1 $
|
---|
11 | //
|
---|
12 | // Description : defines model of formal parameter
|
---|
13 | // ***************************************************************************
|
---|
14 |
|
---|
15 | #ifndef BOOST_RT_CLA_PARAMETER_HPP_062604GER
|
---|
16 | #define BOOST_RT_CLA_PARAMETER_HPP_062604GER
|
---|
17 |
|
---|
18 | // Boost.Runtime.Parameter
|
---|
19 | #include <boost/test/utils/runtime/config.hpp>
|
---|
20 |
|
---|
21 | #include <boost/test/utils/runtime/fwd.hpp>
|
---|
22 | #include <boost/test/utils/runtime/parameter.hpp>
|
---|
23 | #include <boost/test/utils/runtime/validation.hpp>
|
---|
24 |
|
---|
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>
|
---|
29 |
|
---|
30 | // Boost.Test
|
---|
31 | #include <boost/test/utils/rtti.hpp>
|
---|
32 |
|
---|
33 | namespace boost {
|
---|
34 |
|
---|
35 | namespace BOOST_RT_PARAM_NAMESPACE {
|
---|
36 |
|
---|
37 | namespace cla {
|
---|
38 |
|
---|
39 | // ************************************************************************** //
|
---|
40 | // ************** runtime::cla::parameter ************** //
|
---|
41 | // ************************************************************************** //
|
---|
42 |
|
---|
43 | class parameter : public BOOST_RT_PARAM_NAMESPACE::parameter {
|
---|
44 | public:
|
---|
45 | parameter( identification_policy& ID, argument_factory& F )
|
---|
46 | : p_optional( false )
|
---|
47 | , p_multiplicable( false )
|
---|
48 | , p_optional_value( false )
|
---|
49 | , m_id_policy( ID )
|
---|
50 | , m_arg_factory( F )
|
---|
51 | {}
|
---|
52 |
|
---|
53 | // Destructor
|
---|
54 | virtual ~parameter() {}
|
---|
55 |
|
---|
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;
|
---|
60 |
|
---|
61 | // parameter properties modification
|
---|
62 | template<typename Modifier>
|
---|
63 | void accept_modifier( Modifier const& m )
|
---|
64 | {
|
---|
65 | if( m.has( optional_m ) )
|
---|
66 | p_optional.value = true;
|
---|
67 |
|
---|
68 | if( m.has( required_m ) )
|
---|
69 | p_optional.value = false;
|
---|
70 |
|
---|
71 | if( m.has( multiplicable_m ) )
|
---|
72 | p_multiplicable.value = true;
|
---|
73 |
|
---|
74 | if( m.has( optional_value_m ) )
|
---|
75 | p_optional_value.value = true;
|
---|
76 |
|
---|
77 | nfp::optionally_assign( p_description.value, m, description );
|
---|
78 | }
|
---|
79 |
|
---|
80 | // access methods
|
---|
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; }
|
---|
84 |
|
---|
85 |
|
---|
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
|
---|
89 | {
|
---|
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 | p.m_id_policy.conflict_with( m_id_policy );
|
---|
93 | }
|
---|
94 | cstring id_2_report() const { return m_id_policy.id_2_report(); }
|
---|
95 | void usage_info( format_stream& fs ) const
|
---|
96 | {
|
---|
97 | m_id_policy.usage_info( fs );
|
---|
98 | if( p_optional_value )
|
---|
99 | fs << BOOST_RT_PARAM_LITERAL( '[' );
|
---|
100 |
|
---|
101 | m_arg_factory.argument_usage_info( fs );
|
---|
102 |
|
---|
103 | if( p_optional_value )
|
---|
104 | fs << BOOST_RT_PARAM_LITERAL( ']' );
|
---|
105 | }
|
---|
106 |
|
---|
107 | // argument match/produce based on input
|
---|
108 | bool matching( argv_traverser& tr, bool primary ) const
|
---|
109 | {
|
---|
110 | return m_id_policy.matching( *this, tr, primary );
|
---|
111 | }
|
---|
112 |
|
---|
113 | // argument production based on different source
|
---|
114 | void produce_argument( argv_traverser& tr )
|
---|
115 | {
|
---|
116 | m_id_policy.matching( *this, tr, true ); // !! could we save this position somehow
|
---|
117 | m_actual_argument = m_arg_factory.produce_using( *this, tr );
|
---|
118 | }
|
---|
119 | void produce_argument( parser const& p )
|
---|
120 | {
|
---|
121 | m_actual_argument = m_arg_factory.produce_using( *this, p );
|
---|
122 | }
|
---|
123 |
|
---|
124 | private:
|
---|
125 | //Data members
|
---|
126 | identification_policy& m_id_policy;
|
---|
127 | argument_factory& m_arg_factory;
|
---|
128 | argument_ptr m_actual_argument;
|
---|
129 | };
|
---|
130 |
|
---|
131 | //____________________________________________________________________________//
|
---|
132 |
|
---|
133 | template<typename Parameter,typename Modifier>
|
---|
134 | inline shared_ptr<Parameter>
|
---|
135 | operator-( shared_ptr<Parameter> p, Modifier const& m )
|
---|
136 | {
|
---|
137 | p->accept_modifier( m );
|
---|
138 |
|
---|
139 | return p;
|
---|
140 | }
|
---|
141 |
|
---|
142 | //____________________________________________________________________________//
|
---|
143 |
|
---|
144 | } // namespace cla
|
---|
145 |
|
---|
146 | } // namespace BOOST_RT_PARAM_NAMESPACE
|
---|
147 |
|
---|
148 | } // namespace boost
|
---|
149 |
|
---|
150 | // ************************************************************************** //
|
---|
151 | // Revision History:
|
---|
152 | //
|
---|
153 | // $Log: parameter.hpp,v $
|
---|
154 | // Revision 1.1 2005/04/12 06:42:43 rogeeff
|
---|
155 | // Runtime.Param library initial commit
|
---|
156 | //
|
---|
157 | // ************************************************************************** //
|
---|
158 |
|
---|
159 | #endif // BOOST_RT_CLA_PARAMETER_HPP_062604GER
|
---|