named_parameter.ipp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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 : implements model of named parameter
  12. // ***************************************************************************
  13. #ifndef BOOST_RT_CLA_NAMED_PARAMETER_IPP_062904GER
  14. #define BOOST_RT_CLA_NAMED_PARAMETER_IPP_062904GER
  15. // Boost.Runtime.Parameter
  16. #include <boost/test/utils/runtime/config.hpp>
  17. #include <boost/test/utils/runtime/cla/named_parameter.hpp>
  18. #include <boost/test/utils/runtime/cla/char_parameter.hpp>
  19. // Boost.Test
  20. #include <boost/test/utils/algorithm.hpp>
  21. namespace boost {
  22. namespace BOOST_RT_PARAM_NAMESPACE {
  23. namespace cla {
  24. // ************************************************************************** //
  25. // ************** string_name_policy ************** //
  26. // ************************************************************************** //
  27. BOOST_RT_PARAM_INLINE
  28. string_name_policy::string_name_policy()
  29. : basic_naming_policy( rtti::type_id<string_name_policy>() )
  30. , m_guess_name( false )
  31. {
  32. assign_op( p_prefix.value, BOOST_RT_PARAM_CSTRING_LITERAL( "-" ), 0 );
  33. }
  34. //____________________________________________________________________________//
  35. BOOST_RT_PARAM_INLINE bool
  36. string_name_policy::responds_to( cstring name ) const
  37. {
  38. std::pair<cstring::iterator,dstring::const_iterator> mm_pos;
  39. mm_pos = unit_test::mismatch( name.begin(), name.end(), p_name->begin(), p_name->end() );
  40. return mm_pos.first == name.end() && (m_guess_name || (mm_pos.second == p_name->end()) );
  41. }
  42. //____________________________________________________________________________//
  43. #ifdef BOOST_MSVC
  44. # pragma warning(push)
  45. # pragma warning(disable:4244)
  46. #endif
  47. BOOST_RT_PARAM_INLINE bool
  48. string_name_policy::conflict_with( identification_policy const& id ) const
  49. {
  50. if( id.p_type_id == p_type_id ) {
  51. string_name_policy const& snp = static_cast<string_name_policy const&>( id );
  52. if( p_name->empty() || snp.p_name->empty() )
  53. return false;
  54. if( p_prefix != snp.p_prefix )
  55. return false;
  56. std::pair<dstring::const_iterator,dstring::const_iterator> mm_pos =
  57. unit_test::mismatch( p_name->begin(), p_name->end(), snp.p_name->begin(), snp.p_name->end() );
  58. return mm_pos.first != p_name->begin() && // there is common substring
  59. ((m_guess_name && (mm_pos.second == snp.p_name->end()) ) || // that match other guy and I am guessing
  60. (snp.m_guess_name && (mm_pos.first == p_name->end()) )); // or me and the other guy is
  61. }
  62. if( id.p_type_id == rtti::type_id<char_name_policy>() ) {
  63. char_name_policy const& cnp = static_cast<char_name_policy const&>( id );
  64. return m_guess_name &&
  65. (p_prefix == cnp.p_prefix) &&
  66. unit_test::first_char( cstring( p_name ) ) == unit_test::first_char( cstring( cnp.p_name ) );
  67. }
  68. return false;
  69. }
  70. #ifdef BOOST_MSVC
  71. # pragma warning(pop)
  72. #endif
  73. //____________________________________________________________________________//
  74. BOOST_RT_PARAM_INLINE bool
  75. string_name_policy::match_name( argv_traverser& tr ) const
  76. {
  77. if( !m_guess_name )
  78. return basic_naming_policy::match_name( tr );
  79. cstring in = tr.input();
  80. std::pair<cstring::iterator,dstring::const_iterator> mm_pos;
  81. mm_pos = unit_test::mismatch( in.begin(), in.end(), p_name->begin(), p_name->end() );
  82. if( mm_pos.first == in.begin() )
  83. return false;
  84. tr.trim( mm_pos.first - in.begin() );
  85. return true;
  86. }
  87. //____________________________________________________________________________//
  88. } // namespace cla
  89. } // namespace BOOST_RT_PARAM_NAMESPACE
  90. } // namespace boost
  91. #endif // BOOST_RT_CLA_NAMED_PARAMETER_IPP_062904GER