source: NonGTP/Boost/boost/test/utils/runtime/cla/named_parameter.ipp @ 857

Revision 857, 4.3 KB checked in by igarcia, 18 years ago (diff)
Line 
1//  (C) Copyright Gennadiy Rozental 2005.
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: named_parameter.ipp,v $
9//
10//  Version     : $Revision: 1.2 $
11//
12//  Description : implements model of named parameter
13// ***************************************************************************
14
15#ifndef BOOST_RT_CLA_NAMED_PARAMETER_IPP_062904GER
16#define BOOST_RT_CLA_NAMED_PARAMETER_IPP_062904GER
17
18// Boost.Runtime.Parameter
19#include <boost/test/utils/runtime/config.hpp>
20
21#include <boost/test/utils/runtime/cla/named_parameter.hpp>
22#include <boost/test/utils/runtime/cla/char_parameter.hpp>
23
24// Boost.Test
25#include <boost/test/utils/algorithm.hpp>
26
27namespace boost {
28
29namespace BOOST_RT_PARAM_NAMESPACE {
30
31namespace cla {
32
33// ************************************************************************** //
34// **************              string_name_policy              ************** //
35// ************************************************************************** //
36
37BOOST_RT_PARAM_INLINE
38string_name_policy::string_name_policy()
39: basic_naming_policy( rtti::type_id<string_name_policy>() )
40, m_guess_name( false )
41{
42    assign_op( m_prefix, BOOST_RT_PARAM_CSTRING_LITERAL( "-" ), 0 );
43}
44
45//____________________________________________________________________________//
46
47BOOST_RT_PARAM_INLINE bool
48string_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(), m_name.begin(), m_name.end() );
53
54    return mm_pos.first == name.end() && (m_guess_name || (mm_pos.second == m_name.end()) );
55}
56
57//____________________________________________________________________________//
58
59BOOST_RT_PARAM_INLINE bool
60string_name_policy::conflict_with( identification_policy const& id ) const
61{
62    if( id.p_type_id == p_type_id ) {
63        string_name_policy const& snp = static_cast<string_name_policy const&>( id );
64
65        if( m_name.empty() || snp.m_name.empty() )
66            return false;
67
68        std::pair<dstring::const_iterator,dstring::const_iterator> mm_pos =
69            unit_test::mismatch( m_name.begin(), m_name.end(), snp.m_name.begin(), snp.m_name.end() );
70
71        return mm_pos.first != m_name.begin()                              &&  // there is common substring
72                (m_guess_name       || (mm_pos.first  == m_name.end()) )   &&  // that match me
73                (snp.m_guess_name   || (mm_pos.second == snp.m_name.end()) );  // and snp
74    }
75   
76    if( id.p_type_id == rtti::type_id<char_name_policy>() ) {
77        char_name_policy const& cnp = static_cast<char_name_policy const&>( id );
78   
79        return m_guess_name && unit_test::first_char( cstring( m_name ) ) == unit_test::first_char( cnp.id_2_report() );
80    }
81   
82    return false;   
83}
84
85//____________________________________________________________________________//
86
87BOOST_RT_PARAM_INLINE bool
88string_name_policy::match_name( argv_traverser& tr ) const
89{
90    if( !m_guess_name )
91        return basic_naming_policy::match_name( tr );
92    else {
93        cstring in = tr.input();
94
95        std::pair<cstring::iterator,dstring::const_iterator> mm_pos;
96       
97        mm_pos = unit_test::mismatch( in.begin(), in.end(), m_name.begin(), m_name.end() );
98
99        if( mm_pos.first == in.begin() )
100            return false;
101
102        tr.trim( mm_pos.first - in.begin() );
103    }
104
105    return true;
106}
107
108//____________________________________________________________________________//
109
110} // namespace cla
111
112} // namespace BOOST_RT_PARAM_NAMESPACE
113
114} // namespace boost
115
116// ************************************************************************** //
117//   Revision History:
118//
119//   $Log: named_parameter.ipp,v $
120//   Revision 1.2  2005/04/12 07:01:36  rogeeff
121//   exclude polymorphic_downcast
122//
123//   Revision 1.1  2005/04/12 06:42:43  rogeeff
124//   Runtime.Param library initial commit
125//
126// ************************************************************************** //
127
128#endif // BOOST_RT_CLA_NAMED_PARAMETER_IPP_062904GER
Note: See TracBrowser for help on using the repository browser.