Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 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) |
| 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 Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 15 | #ifndef NDNBOOST_RT_CLA_ID_POLICY_HPP_062604GER |
| 16 | #define NDNBOOST_RT_CLA_ID_POLICY_HPP_062604GER |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 17 | |
| 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 | |
| 31 | namespace ndnboost { |
| 32 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 33 | namespace NDNBOOST_RT_PARAM_NAMESPACE { |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 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 | // 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 | |
| 64 | protected: |
| 65 | explicit basic_naming_policy( rtti::id_t dyn_type ) |
| 66 | : identification_policy( dyn_type ) |
| 67 | {} |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 68 | NDNBOOST_RT_PARAM_UNNEEDED_VIRTUAL ~basic_naming_policy() {} |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 69 | |
| 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 | |
| 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 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 Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 105 | fs << NDNBOOST_RT_PARAM_LITERAL( '{' ); |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 106 | m_primary.usage_info( fs ); |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 107 | fs << NDNBOOST_RT_PARAM_LITERAL( '|' ); |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 108 | m_secondary.usage_info( fs ); |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 109 | fs << NDNBOOST_RT_PARAM_LITERAL( '}' ); |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 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 | // 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 | |
| 124 | protected: |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 125 | NDNBOOST_RT_PARAM_UNNEEDED_VIRTUAL ~dual_id_policy() {} |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 126 | |
| 127 | // Data members |
| 128 | PrimaryId m_primary; |
| 129 | SecondId m_secondary; |
| 130 | }; |
| 131 | |
| 132 | } // namespace cla |
| 133 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 134 | } // namespace NDNBOOST_RT_PARAM_NAMESPACE |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 135 | |
| 136 | } // namespace ndnboost |
| 137 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 138 | #ifndef NDNBOOST_RT_PARAM_OFFLINE |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 139 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 140 | # define NDNBOOST_RT_PARAM_INLINE inline |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 141 | # include <ndnboost/test/utils/runtime/cla/id_policy.ipp> |
| 142 | |
| 143 | #endif |
| 144 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 145 | #endif // NDNBOOST_RT_CLA_ID_POLICY_HPP_062604GER |