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 : some generic identification policies implementation |
| 13 | // *************************************************************************** |
| 14 | |
| 15 | #ifndef BOOST_RT_CLA_ID_POLICY_IPP_062904GER |
| 16 | #define BOOST_RT_CLA_ID_POLICY_IPP_062904GER |
| 17 | |
| 18 | // Boost.Runtime.Parameter |
| 19 | #include <ndnboost/test/utils/runtime/config.hpp> |
| 20 | |
| 21 | #include <ndnboost/test/utils/runtime/cla/id_policy.hpp> |
| 22 | #include <ndnboost/test/utils/runtime/cla/parameter.hpp> |
| 23 | |
| 24 | namespace ndnboost { |
| 25 | |
| 26 | namespace BOOST_RT_PARAM_NAMESPACE { |
| 27 | |
| 28 | namespace cla { |
| 29 | |
| 30 | // ************************************************************************** // |
| 31 | // ************** basic_naming_policy ************** // |
| 32 | // ************************************************************************** // |
| 33 | |
| 34 | BOOST_RT_PARAM_INLINE void |
| 35 | basic_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_RT_PARAM_LITERAL( ' ' ); |
| 41 | } |
| 42 | |
| 43 | //____________________________________________________________________________// |
| 44 | |
| 45 | BOOST_RT_PARAM_INLINE bool |
| 46 | basic_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 | |
| 57 | BOOST_RT_PARAM_INLINE bool |
| 58 | basic_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 | |
| 69 | BOOST_RT_PARAM_INLINE bool |
| 70 | basic_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 | |
| 95 | BOOST_RT_PARAM_INLINE bool |
| 96 | basic_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_RT_PARAM_NAMESPACE |
| 115 | |
| 116 | } // namespace ndnboost |
| 117 | |
| 118 | #endif // BOOST_RT_CLA_ID_POLICY_IPP_062904GER |