1// (C) Copyright Gennadiy Rozental 2005-2014. 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$ 11// 12// Description : some generic identification policies implementation 13// *************************************************************************** 14 15#ifndef BOOST_TEST_UTILS_RUNTIME_CLA_ID_POLICY_IPP 16#define BOOST_TEST_UTILS_RUNTIME_CLA_ID_POLICY_IPP 17 18// Boost.Runtime.Parameter 19#include <boost/test/utils/runtime/config.hpp> 20 21#include <boost/test/utils/runtime/cla/id_policy.hpp> 22#include <boost/test/utils/runtime/cla/parameter.hpp> 23 24namespace boost { 25 26namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE { 27 28namespace cla { 29 30// ************************************************************************** // 31// ************** basic_naming_policy ************** // 32// ************************************************************************** // 33 34BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE void 35basic_naming_policy::usage_info( format_stream& fs ) const 36{ 37 fs << p_prefix << p_name << p_separator; 38 39 if( p_separator->empty() ) 40 fs << BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( ' ' ); 41} 42 43//____________________________________________________________________________// 44 45BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE bool 46basic_naming_policy::match_prefix( argv_traverser& tr ) const 47{ 48 if( !tr.match_front( p_prefix.get() ) ) 49 return false; 50 51 tr.trim( p_prefix->size() ); 52 return true; 53} 54 55//____________________________________________________________________________// 56 57BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE bool 58basic_naming_policy::match_name( argv_traverser& tr ) const 59{ 60 if( !tr.match_front( p_name.get() ) ) 61 return false; 62 63 tr.trim( p_name->size() ); 64 return true; 65} 66 67//____________________________________________________________________________// 68 69BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE bool 70basic_naming_policy::match_separator( argv_traverser& tr, bool optional_value ) const 71{ 72 if( p_separator->empty() ) { 73 if( !tr.token().is_empty() ) 74 return false; 75 76 tr.trim( 1 ); 77 } 78 else { 79 if( !tr.match_front( p_separator.get() ) ) { 80 // if parameter has optional value separator is optional as well 81 if( optional_value && ( tr.eoi() || tr.match_front( ' ' ) ) ) { 82 return true; 83 } 84 return false; 85 } 86 87 tr.trim( p_separator->size() ); 88 } 89 90 return true; 91} 92 93//____________________________________________________________________________// 94 95BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE bool 96basic_naming_policy::matching( parameter const& p, argv_traverser& tr, bool ) const 97{ 98 if( !match_prefix( tr ) ) 99 return false; 100 101 if( !match_name( tr ) ) 102 return false; 103 104 if( !match_separator( tr, p.p_optional_value ) ) 105 return false; 106 107 return true; 108} 109 110//____________________________________________________________________________// 111 112} // namespace cla 113 114} // namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE 115 116} // namespace boost 117 118#endif // BOOST_TEST_UTILS_RUNTIME_CLA_ID_POLICY_IPP 119