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: id_policy.hpp,v $
|
---|
9 | //
|
---|
10 | // Version : $Revision: 1.1 $
|
---|
11 | //
|
---|
12 | // Description : some generic identification policies definition
|
---|
13 | // ***************************************************************************
|
---|
14 |
|
---|
15 | #ifndef BOOST_RT_CLA_ID_POLICY_HPP_062604GER
|
---|
16 | #define BOOST_RT_CLA_ID_POLICY_HPP_062604GER
|
---|
17 |
|
---|
18 | // Boost.Runtime.Parameter
|
---|
19 | #include <boost/test/utils/runtime/config.hpp>
|
---|
20 |
|
---|
21 | #include <boost/test/utils/runtime/cla/fwd.hpp>
|
---|
22 | #include <boost/test/utils/runtime/cla/modifier.hpp>
|
---|
23 | #include <boost/test/utils/runtime/cla/argv_traverser.hpp>
|
---|
24 |
|
---|
25 | #include <boost/test/utils/runtime/cla/iface/id_policy.hpp>
|
---|
26 |
|
---|
27 | // Boost.Test
|
---|
28 | #include <boost/test/utils/class_properties.hpp>
|
---|
29 | #include <boost/test/utils/rtti.hpp>
|
---|
30 |
|
---|
31 | namespace boost {
|
---|
32 |
|
---|
33 | namespace BOOST_RT_PARAM_NAMESPACE {
|
---|
34 |
|
---|
35 | namespace cla {
|
---|
36 |
|
---|
37 | // ************************************************************************** //
|
---|
38 | // ************** naming_policy_base ************** //
|
---|
39 | // ************************************************************************** //
|
---|
40 | // model: <prefix> <name> <separtor>
|
---|
41 |
|
---|
42 | class basic_naming_policy : public identification_policy {
|
---|
43 | public:
|
---|
44 | // Policy interface
|
---|
45 | virtual bool responds_to( cstring name ) const { return m_name == name; }
|
---|
46 | virtual cstring id_2_report() const { return m_name; }
|
---|
47 | virtual void usage_info( format_stream& fs ) const;
|
---|
48 | virtual bool matching( parameter const& p, argv_traverser& tr, bool primary ) const;
|
---|
49 |
|
---|
50 | // Accept modifer
|
---|
51 | template<typename Modifier>
|
---|
52 | void accept_modifier( Modifier const& m )
|
---|
53 | {
|
---|
54 | nfp::optionally_assign( m_prefix, m, prefix );
|
---|
55 | nfp::optionally_assign( m_name, m, name );
|
---|
56 | nfp::optionally_assign( m_separator, m, separator );
|
---|
57 | }
|
---|
58 |
|
---|
59 | protected:
|
---|
60 | explicit basic_naming_policy( rtti::id_t const& dyn_type )
|
---|
61 | : identification_policy( dyn_type )
|
---|
62 | {}
|
---|
63 | BOOST_RT_PARAM_UNNEEDED_VIRTUAL ~basic_naming_policy() {}
|
---|
64 |
|
---|
65 | // Naming policy interface
|
---|
66 | virtual bool match_prefix( argv_traverser& tr ) const;
|
---|
67 | virtual bool match_name( argv_traverser& tr ) const;
|
---|
68 | virtual bool match_separator( argv_traverser& tr ) const;
|
---|
69 |
|
---|
70 | // Data members
|
---|
71 | dstring m_prefix;
|
---|
72 | dstring m_name;
|
---|
73 | dstring m_separator;
|
---|
74 | };
|
---|
75 |
|
---|
76 | // ************************************************************************** //
|
---|
77 | // ************** dual_id_policy ************** //
|
---|
78 | // ************************************************************************** //
|
---|
79 |
|
---|
80 | template<typename MostDerived,typename PrimaryId,typename SecondId>
|
---|
81 | class dual_id_policy : public identification_policy {
|
---|
82 | public:
|
---|
83 | // Constructor
|
---|
84 | dual_id_policy()
|
---|
85 | : identification_policy( rtti::type_id<MostDerived>() )
|
---|
86 | , m_primary()
|
---|
87 | , m_secondary()
|
---|
88 | {}
|
---|
89 |
|
---|
90 | // Policy interface
|
---|
91 | virtual bool responds_to( cstring name ) const
|
---|
92 | {
|
---|
93 | return m_primary.responds_to( name ) || m_secondary.responds_to( name );
|
---|
94 | }
|
---|
95 | virtual bool conflict_with( identification_policy const& id_p ) const
|
---|
96 | {
|
---|
97 | return m_primary.conflict_with( id_p ) || m_secondary.conflict_with( id_p );
|
---|
98 | }
|
---|
99 | virtual cstring id_2_report() const
|
---|
100 | {
|
---|
101 | return m_primary.id_2_report();
|
---|
102 | }
|
---|
103 | virtual void usage_info( format_stream& fs ) const
|
---|
104 | {
|
---|
105 | fs << BOOST_RT_PARAM_LITERAL( '{' );
|
---|
106 | m_primary.usage_info( fs );
|
---|
107 | fs << BOOST_RT_PARAM_LITERAL( '|' );
|
---|
108 | m_secondary.usage_info( fs );
|
---|
109 | fs << BOOST_RT_PARAM_LITERAL( '}' );
|
---|
110 | }
|
---|
111 | virtual bool matching( parameter const& p, argv_traverser& tr, bool primary ) const
|
---|
112 | {
|
---|
113 | return m_primary.matching( p, tr, primary ) || m_secondary.matching( p, tr, primary );
|
---|
114 | }
|
---|
115 |
|
---|
116 | protected:
|
---|
117 | BOOST_RT_PARAM_UNNEEDED_VIRTUAL ~dual_id_policy() {}
|
---|
118 |
|
---|
119 | // Data members
|
---|
120 | PrimaryId m_primary;
|
---|
121 | SecondId m_secondary;
|
---|
122 | };
|
---|
123 |
|
---|
124 | } // namespace cla
|
---|
125 |
|
---|
126 | } // namespace BOOST_RT_PARAM_NAMESPACE
|
---|
127 |
|
---|
128 | } // namespace boost
|
---|
129 |
|
---|
130 | #ifndef BOOST_RT_PARAM_OFFLINE
|
---|
131 |
|
---|
132 | # define BOOST_RT_PARAM_INLINE inline
|
---|
133 | # include <boost/test/utils/runtime/cla/id_policy.ipp>
|
---|
134 |
|
---|
135 | #endif
|
---|
136 |
|
---|
137 | // ************************************************************************** //
|
---|
138 | // Revision History:
|
---|
139 | //
|
---|
140 | // $Log: id_policy.hpp,v $
|
---|
141 | // Revision 1.1 2005/04/12 06:42:43 rogeeff
|
---|
142 | // Runtime.Param library initial commit
|
---|
143 | //
|
---|
144 | // ************************************************************************** //
|
---|
145 |
|
---|
146 | #endif // BOOST_RT_CLA_ID_POLICY_HPP_062604GER
|
---|