id_policy.ipp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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: 54633 $
  10. //
  11. // Description : some generic identification policies implementation
  12. // ***************************************************************************
  13. #ifndef BOOST_RT_CLA_ID_POLICY_IPP_062904GER
  14. #define BOOST_RT_CLA_ID_POLICY_IPP_062904GER
  15. // Boost.Runtime.Parameter
  16. #include <boost/test/utils/runtime/config.hpp>
  17. #include <boost/test/utils/runtime/cla/id_policy.hpp>
  18. #include <boost/test/utils/runtime/cla/parameter.hpp>
  19. namespace boost {
  20. namespace BOOST_RT_PARAM_NAMESPACE {
  21. namespace cla {
  22. // ************************************************************************** //
  23. // ************** basic_naming_policy ************** //
  24. // ************************************************************************** //
  25. BOOST_RT_PARAM_INLINE void
  26. basic_naming_policy::usage_info( format_stream& fs ) const
  27. {
  28. fs << p_prefix << p_name << p_separator;
  29. if( p_separator->empty() )
  30. fs << BOOST_RT_PARAM_LITERAL( ' ' );
  31. }
  32. //____________________________________________________________________________//
  33. BOOST_RT_PARAM_INLINE bool
  34. basic_naming_policy::match_prefix( argv_traverser& tr ) const
  35. {
  36. if( !tr.match_front( p_prefix.get() ) )
  37. return false;
  38. tr.trim( p_prefix->size() );
  39. return true;
  40. }
  41. //____________________________________________________________________________//
  42. BOOST_RT_PARAM_INLINE bool
  43. basic_naming_policy::match_name( argv_traverser& tr ) const
  44. {
  45. if( !tr.match_front( p_name.get() ) )
  46. return false;
  47. tr.trim( p_name->size() );
  48. return true;
  49. }
  50. //____________________________________________________________________________//
  51. BOOST_RT_PARAM_INLINE bool
  52. basic_naming_policy::match_separator( argv_traverser& tr, bool optional_value ) const
  53. {
  54. if( p_separator->empty() ) {
  55. if( !tr.token().is_empty() )
  56. return false;
  57. tr.trim( 1 );
  58. }
  59. else {
  60. if( !tr.match_front( p_separator.get() ) ) {
  61. // if parameter has optional value separator is optional as well
  62. if( optional_value && ( tr.eoi() || tr.match_front( ' ' ) ) ) {
  63. return true;
  64. }
  65. return false;
  66. }
  67. tr.trim( p_separator->size() );
  68. }
  69. return true;
  70. }
  71. //____________________________________________________________________________//
  72. BOOST_RT_PARAM_INLINE bool
  73. basic_naming_policy::matching( parameter const& p, argv_traverser& tr, bool ) const
  74. {
  75. if( !match_prefix( tr ) )
  76. return false;
  77. if( !match_name( tr ) )
  78. return false;
  79. if( !match_separator( tr, p.p_optional_value ) )
  80. return false;
  81. return true;
  82. }
  83. //____________________________________________________________________________//
  84. } // namespace cla
  85. } // namespace BOOST_RT_PARAM_NAMESPACE
  86. } // namespace boost
  87. #endif // BOOST_RT_CLA_ID_POLICY_IPP_062904GER