blob: 2f587b45c7304037bf31be31b9b6557754afda93 [file] [log] [blame]
Jeff Thompsonef2d5a42013-08-22 19:09:24 -07001// (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)
5
6// See http://www.boost.org/libs/test for the library home page.
7//
8// File : $RCSfile$
9//
10// Version : $Revision: 57992 $
11//
12// Description : some generic identification policies definition
13// ***************************************************************************
14
Jeff Thompson3d613fd2013-10-15 15:39:04 -070015#ifndef NDNBOOST_RT_CLA_ID_POLICY_HPP_062604GER
16#define NDNBOOST_RT_CLA_ID_POLICY_HPP_062604GER
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070017
18// Boost.Runtime.Parameter
19#include <ndnboost/test/utils/runtime/config.hpp>
20
21#include <ndnboost/test/utils/runtime/cla/fwd.hpp>
22#include <ndnboost/test/utils/runtime/cla/modifier.hpp>
23#include <ndnboost/test/utils/runtime/cla/argv_traverser.hpp>
24
25#include <ndnboost/test/utils/runtime/cla/iface/id_policy.hpp>
26
27// Boost.Test
28#include <ndnboost/test/utils/class_properties.hpp>
29#include <ndnboost/test/utils/rtti.hpp>
30
31namespace ndnboost {
32
Jeff Thompson3d613fd2013-10-15 15:39:04 -070033namespace NDNBOOST_RT_PARAM_NAMESPACE {
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070034
35namespace cla {
36
37// ************************************************************************** //
38// ************** naming_policy_base ************** //
39// ************************************************************************** //
40// model: <prefix> <name> <separtor>
41
42class basic_naming_policy : public identification_policy {
43public:
44 // Public properties
45 unit_test::readwrite_property<dstring> p_prefix;
46 unit_test::readwrite_property<dstring> p_name;
47 unit_test::readwrite_property<dstring> p_separator;
48
49 // Policy interface
50 virtual bool responds_to( cstring name ) const { return p_name == name; }
51 virtual cstring id_2_report() const { return p_name.get(); }
52 virtual void usage_info( format_stream& fs ) const;
53 virtual bool matching( parameter const& p, argv_traverser& tr, bool primary ) const;
54
55 // Accept modifier
56 template<typename Modifier>
57 void accept_modifier( Modifier const& m )
58 {
59 nfp::optionally_assign( p_prefix.value, m, prefix );
60 nfp::optionally_assign( p_name.value, m, name );
61 nfp::optionally_assign( p_separator.value, m, separator );
62 }
63
64protected:
65 explicit basic_naming_policy( rtti::id_t dyn_type )
66 : identification_policy( dyn_type )
67 {}
Jeff Thompson3d613fd2013-10-15 15:39:04 -070068 NDNBOOST_RT_PARAM_UNNEEDED_VIRTUAL ~basic_naming_policy() {}
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070069
70 // Naming policy interface
71 virtual bool match_prefix( argv_traverser& tr ) const;
72 virtual bool match_name( argv_traverser& tr ) const;
73 virtual bool match_separator( argv_traverser& tr, bool optional_value ) const;
74};
75
76// ************************************************************************** //
77// ************** dual_id_policy ************** //
78// ************************************************************************** //
79
80template<typename MostDerived,typename PrimaryId,typename SecondId>
81class dual_id_policy : public identification_policy {
82public:
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 id_p.conflict_with( m_primary ) || id_p.conflict_with( m_secondary );
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 {
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700105 fs << NDNBOOST_RT_PARAM_LITERAL( '{' );
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700106 m_primary.usage_info( fs );
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700107 fs << NDNBOOST_RT_PARAM_LITERAL( '|' );
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700108 m_secondary.usage_info( fs );
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700109 fs << NDNBOOST_RT_PARAM_LITERAL( '}' );
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700110 }
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 // Accept modifier
117 template<typename Modifier>
118 void accept_modifier( Modifier const& m )
119 {
120 m_primary.accept_modifier( m );
121 m_secondary.accept_modifier( m );
122 }
123
124protected:
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700125 NDNBOOST_RT_PARAM_UNNEEDED_VIRTUAL ~dual_id_policy() {}
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700126
127 // Data members
128 PrimaryId m_primary;
129 SecondId m_secondary;
130};
131
132} // namespace cla
133
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700134} // namespace NDNBOOST_RT_PARAM_NAMESPACE
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700135
136} // namespace ndnboost
137
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700138#ifndef NDNBOOST_RT_PARAM_OFFLINE
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700139
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700140# define NDNBOOST_RT_PARAM_INLINE inline
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700141# include <ndnboost/test/utils/runtime/cla/id_policy.ipp>
142
143#endif
144
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700145#endif // NDNBOOST_RT_CLA_ID_POLICY_HPP_062604GER