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: 54633 $ |
| 11 | // |
| 12 | // Description : implements model of named parameter |
| 13 | // *************************************************************************** |
| 14 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 15 | #ifndef NDNBOOST_RT_CLA_NAMED_PARAMETER_IPP_062904GER |
| 16 | #define NDNBOOST_RT_CLA_NAMED_PARAMETER_IPP_062904GER |
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/named_parameter.hpp> |
| 22 | #include <ndnboost/test/utils/runtime/cla/char_parameter.hpp> |
| 23 | |
| 24 | // Boost.Test |
| 25 | #include <ndnboost/test/utils/algorithm.hpp> |
| 26 | |
| 27 | namespace ndnboost { |
| 28 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 29 | namespace NDNBOOST_RT_PARAM_NAMESPACE { |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 30 | |
| 31 | namespace cla { |
| 32 | |
| 33 | // ************************************************************************** // |
| 34 | // ************** string_name_policy ************** // |
| 35 | // ************************************************************************** // |
| 36 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 37 | NDNBOOST_RT_PARAM_INLINE |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 38 | string_name_policy::string_name_policy() |
| 39 | : basic_naming_policy( rtti::type_id<string_name_policy>() ) |
| 40 | , m_guess_name( false ) |
| 41 | { |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 42 | assign_op( p_prefix.value, NDNBOOST_RT_PARAM_CSTRING_LITERAL( "-" ), 0 ); |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | //____________________________________________________________________________// |
| 46 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 47 | NDNBOOST_RT_PARAM_INLINE bool |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 48 | string_name_policy::responds_to( cstring name ) const |
| 49 | { |
| 50 | std::pair<cstring::iterator,dstring::const_iterator> mm_pos; |
| 51 | |
| 52 | mm_pos = unit_test::mismatch( name.begin(), name.end(), p_name->begin(), p_name->end() ); |
| 53 | |
| 54 | return mm_pos.first == name.end() && (m_guess_name || (mm_pos.second == p_name->end()) ); |
| 55 | } |
| 56 | |
| 57 | //____________________________________________________________________________// |
| 58 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 59 | #ifdef NDNBOOST_MSVC |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 60 | # pragma warning(push) |
| 61 | # pragma warning(disable:4244) |
| 62 | #endif |
| 63 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 64 | NDNBOOST_RT_PARAM_INLINE bool |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 65 | string_name_policy::conflict_with( identification_policy const& id ) const |
| 66 | { |
| 67 | if( id.p_type_id == p_type_id ) { |
| 68 | string_name_policy const& snp = static_cast<string_name_policy const&>( id ); |
| 69 | |
| 70 | if( p_name->empty() || snp.p_name->empty() ) |
| 71 | return false; |
| 72 | |
| 73 | if( p_prefix != snp.p_prefix ) |
| 74 | return false; |
| 75 | |
| 76 | std::pair<dstring::const_iterator,dstring::const_iterator> mm_pos = |
| 77 | unit_test::mismatch( p_name->begin(), p_name->end(), snp.p_name->begin(), snp.p_name->end() ); |
| 78 | |
| 79 | return mm_pos.first != p_name->begin() && // there is common substring |
| 80 | ((m_guess_name && (mm_pos.second == snp.p_name->end()) ) || // that match other guy and I am guessing |
| 81 | (snp.m_guess_name && (mm_pos.first == p_name->end()) )); // or me and the other guy is |
| 82 | } |
| 83 | |
| 84 | if( id.p_type_id == rtti::type_id<char_name_policy>() ) { |
| 85 | char_name_policy const& cnp = static_cast<char_name_policy const&>( id ); |
| 86 | |
| 87 | return m_guess_name && |
| 88 | (p_prefix == cnp.p_prefix) && |
| 89 | unit_test::first_char( cstring( p_name ) ) == unit_test::first_char( cstring( cnp.p_name ) ); |
| 90 | } |
| 91 | |
| 92 | return false; |
| 93 | } |
| 94 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 95 | #ifdef NDNBOOST_MSVC |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 96 | # pragma warning(pop) |
| 97 | #endif |
| 98 | |
| 99 | //____________________________________________________________________________// |
| 100 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 101 | NDNBOOST_RT_PARAM_INLINE bool |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 102 | string_name_policy::match_name( argv_traverser& tr ) const |
| 103 | { |
| 104 | if( !m_guess_name ) |
| 105 | return basic_naming_policy::match_name( tr ); |
| 106 | |
| 107 | cstring in = tr.input(); |
| 108 | |
| 109 | std::pair<cstring::iterator,dstring::const_iterator> mm_pos; |
| 110 | |
| 111 | mm_pos = unit_test::mismatch( in.begin(), in.end(), p_name->begin(), p_name->end() ); |
| 112 | |
| 113 | if( mm_pos.first == in.begin() ) |
| 114 | return false; |
| 115 | |
| 116 | tr.trim( mm_pos.first - in.begin() ); |
| 117 | |
| 118 | return true; |
| 119 | } |
| 120 | |
| 121 | //____________________________________________________________________________// |
| 122 | |
| 123 | } // namespace cla |
| 124 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 125 | } // namespace NDNBOOST_RT_PARAM_NAMESPACE |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 126 | |
| 127 | } // namespace ndnboost |
| 128 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 129 | #endif // NDNBOOST_RT_CLA_NAMED_PARAMETER_IPP_062904GER |