id_policy.hpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. // See http://www.boost.org/libs/test for the library home page.
  6. //
  7. // File : $RCSfile$
  8. //
  9. // Version : $Revision: 57992 $
  10. //
  11. // Description : some generic identification policies definition
  12. // ***************************************************************************
  13. #ifndef BOOST_RT_CLA_ID_POLICY_HPP_062604GER
  14. #define BOOST_RT_CLA_ID_POLICY_HPP_062604GER
  15. // Boost.Runtime.Parameter
  16. #include <boost/test/utils/runtime/config.hpp>
  17. #include <boost/test/utils/runtime/cla/fwd.hpp>
  18. #include <boost/test/utils/runtime/cla/modifier.hpp>
  19. #include <boost/test/utils/runtime/cla/argv_traverser.hpp>
  20. #include <boost/test/utils/runtime/cla/iface/id_policy.hpp>
  21. // Boost.Test
  22. #include <boost/test/utils/class_properties.hpp>
  23. #include <boost/test/utils/rtti.hpp>
  24. namespace boost {
  25. namespace BOOST_RT_PARAM_NAMESPACE {
  26. namespace cla {
  27. // ************************************************************************** //
  28. // ************** naming_policy_base ************** //
  29. // ************************************************************************** //
  30. // model: <prefix> <name> <separtor>
  31. class basic_naming_policy : public identification_policy {
  32. public:
  33. // Public properties
  34. unit_test::readwrite_property<dstring> p_prefix;
  35. unit_test::readwrite_property<dstring> p_name;
  36. unit_test::readwrite_property<dstring> p_separator;
  37. // Policy interface
  38. virtual bool responds_to( cstring name ) const { return p_name == name; }
  39. virtual cstring id_2_report() const { return p_name.get(); }
  40. virtual void usage_info( format_stream& fs ) const;
  41. virtual bool matching( parameter const& p, argv_traverser& tr, bool primary ) const;
  42. // Accept modifier
  43. template<typename Modifier>
  44. void accept_modifier( Modifier const& m )
  45. {
  46. nfp::optionally_assign( p_prefix.value, m, prefix );
  47. nfp::optionally_assign( p_name.value, m, name );
  48. nfp::optionally_assign( p_separator.value, m, separator );
  49. }
  50. protected:
  51. explicit basic_naming_policy( rtti::id_t dyn_type )
  52. : identification_policy( dyn_type )
  53. {}
  54. BOOST_RT_PARAM_UNNEEDED_VIRTUAL ~basic_naming_policy() {}
  55. // Naming policy interface
  56. virtual bool match_prefix( argv_traverser& tr ) const;
  57. virtual bool match_name( argv_traverser& tr ) const;
  58. virtual bool match_separator( argv_traverser& tr, bool optional_value ) const;
  59. };
  60. // ************************************************************************** //
  61. // ************** dual_id_policy ************** //
  62. // ************************************************************************** //
  63. template<typename MostDerived,typename PrimaryId,typename SecondId>
  64. class dual_id_policy : public identification_policy {
  65. public:
  66. // Constructor
  67. dual_id_policy()
  68. : identification_policy( rtti::type_id<MostDerived>() )
  69. , m_primary()
  70. , m_secondary()
  71. {}
  72. // Policy interface
  73. virtual bool responds_to( cstring name ) const
  74. {
  75. return m_primary.responds_to( name ) || m_secondary.responds_to( name );
  76. }
  77. virtual bool conflict_with( identification_policy const& id_p ) const
  78. {
  79. return id_p.conflict_with( m_primary ) || id_p.conflict_with( m_secondary );
  80. }
  81. virtual cstring id_2_report() const
  82. {
  83. return m_primary.id_2_report();
  84. }
  85. virtual void usage_info( format_stream& fs ) const
  86. {
  87. fs << BOOST_RT_PARAM_LITERAL( '{' );
  88. m_primary.usage_info( fs );
  89. fs << BOOST_RT_PARAM_LITERAL( '|' );
  90. m_secondary.usage_info( fs );
  91. fs << BOOST_RT_PARAM_LITERAL( '}' );
  92. }
  93. virtual bool matching( parameter const& p, argv_traverser& tr, bool primary ) const
  94. {
  95. return m_primary.matching( p, tr, primary ) || m_secondary.matching( p, tr, primary );
  96. }
  97. // Accept modifier
  98. template<typename Modifier>
  99. void accept_modifier( Modifier const& m )
  100. {
  101. m_primary.accept_modifier( m );
  102. m_secondary.accept_modifier( m );
  103. }
  104. protected:
  105. BOOST_RT_PARAM_UNNEEDED_VIRTUAL ~dual_id_policy() {}
  106. // Data members
  107. PrimaryId m_primary;
  108. SecondId m_secondary;
  109. };
  110. } // namespace cla
  111. } // namespace BOOST_RT_PARAM_NAMESPACE
  112. } // namespace boost
  113. #ifndef BOOST_RT_PARAM_OFFLINE
  114. # define BOOST_RT_PARAM_INLINE inline
  115. # include <boost/test/utils/runtime/cla/id_policy.ipp>
  116. #endif
  117. #endif // BOOST_RT_CLA_ID_POLICY_HPP_062604GER