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 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 15 | #ifndef NDNBOOST_RT_CLA_ID_POLICY_IPP_062904GER |
| 16 | #define NDNBOOST_RT_CLA_ID_POLICY_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/id_policy.hpp> |
| 22 | #include <ndnboost/test/utils/runtime/cla/parameter.hpp> |
| 23 | |
| 24 | namespace ndnboost { |
| 25 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 26 | namespace NDNBOOST_RT_PARAM_NAMESPACE { |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 27 | |
| 28 | namespace cla { |
| 29 | |
| 30 | // ************************************************************************** // |
| 31 | // ************** basic_naming_policy ************** // |
| 32 | // ************************************************************************** // |
| 33 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 34 | NDNBOOST_RT_PARAM_INLINE void |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 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() ) |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 40 | fs << NDNBOOST_RT_PARAM_LITERAL( ' ' ); |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | //____________________________________________________________________________// |
| 44 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 45 | NDNBOOST_RT_PARAM_INLINE bool |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 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 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 57 | NDNBOOST_RT_PARAM_INLINE bool |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 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 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 69 | NDNBOOST_RT_PARAM_INLINE bool |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 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 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 95 | NDNBOOST_RT_PARAM_INLINE bool |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 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 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 114 | } // namespace NDNBOOST_RT_PARAM_NAMESPACE |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 115 | |
| 116 | } // namespace ndnboost |
| 117 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 118 | #endif // NDNBOOST_RT_CLA_ID_POLICY_IPP_062904GER |