blob: b626ee07b9b3d8066a75aa4eb5a41f521dde9655 [file] [log] [blame]
Jeff Thompsonef2d5a42013-08-22 19:09:24 -07001// (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 Thompson3d613fd2013-10-15 15:39:04 -070015#ifndef NDNBOOST_RT_CLA_NAMED_PARAMETER_IPP_062904GER
16#define NDNBOOST_RT_CLA_NAMED_PARAMETER_IPP_062904GER
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070017
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
27namespace ndnboost {
28
Jeff Thompson3d613fd2013-10-15 15:39:04 -070029namespace NDNBOOST_RT_PARAM_NAMESPACE {
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070030
31namespace cla {
32
33// ************************************************************************** //
34// ************** string_name_policy ************** //
35// ************************************************************************** //
36
Jeff Thompson3d613fd2013-10-15 15:39:04 -070037NDNBOOST_RT_PARAM_INLINE
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070038string_name_policy::string_name_policy()
39: basic_naming_policy( rtti::type_id<string_name_policy>() )
40, m_guess_name( false )
41{
Jeff Thompson3d613fd2013-10-15 15:39:04 -070042 assign_op( p_prefix.value, NDNBOOST_RT_PARAM_CSTRING_LITERAL( "-" ), 0 );
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070043}
44
45//____________________________________________________________________________//
46
Jeff Thompson3d613fd2013-10-15 15:39:04 -070047NDNBOOST_RT_PARAM_INLINE bool
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070048string_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 Thompson3d613fd2013-10-15 15:39:04 -070059#ifdef NDNBOOST_MSVC
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070060# pragma warning(push)
61# pragma warning(disable:4244)
62#endif
63
Jeff Thompson3d613fd2013-10-15 15:39:04 -070064NDNBOOST_RT_PARAM_INLINE bool
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070065string_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 Thompson3d613fd2013-10-15 15:39:04 -070095#ifdef NDNBOOST_MSVC
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070096# pragma warning(pop)
97#endif
98
99//____________________________________________________________________________//
100
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700101NDNBOOST_RT_PARAM_INLINE bool
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700102string_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 Thompson3d613fd2013-10-15 15:39:04 -0700125} // namespace NDNBOOST_RT_PARAM_NAMESPACE
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700126
127} // namespace ndnboost
128
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700129#endif // NDNBOOST_RT_CLA_NAMED_PARAMETER_IPP_062904GER