blob: 49a462dc2d1d4da85733caee1b5614af0e4f3dd9 [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 : some generic identification policies implementation
13// ***************************************************************************
14
Jeff Thompson3d613fd2013-10-15 15:39:04 -070015#ifndef NDNBOOST_RT_CLA_ID_POLICY_IPP_062904GER
16#define NDNBOOST_RT_CLA_ID_POLICY_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/id_policy.hpp>
22#include <ndnboost/test/utils/runtime/cla/parameter.hpp>
23
24namespace ndnboost {
25
Jeff Thompson3d613fd2013-10-15 15:39:04 -070026namespace NDNBOOST_RT_PARAM_NAMESPACE {
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070027
28namespace cla {
29
30// ************************************************************************** //
31// ************** basic_naming_policy ************** //
32// ************************************************************************** //
33
Jeff Thompson3d613fd2013-10-15 15:39:04 -070034NDNBOOST_RT_PARAM_INLINE void
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070035basic_naming_policy::usage_info( format_stream& fs ) const
36{
37 fs << p_prefix << p_name << p_separator;
38
39 if( p_separator->empty() )
Jeff Thompson3d613fd2013-10-15 15:39:04 -070040 fs << NDNBOOST_RT_PARAM_LITERAL( ' ' );
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070041}
42
43//____________________________________________________________________________//
44
Jeff Thompson3d613fd2013-10-15 15:39:04 -070045NDNBOOST_RT_PARAM_INLINE bool
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070046basic_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 Thompson3d613fd2013-10-15 15:39:04 -070057NDNBOOST_RT_PARAM_INLINE bool
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070058basic_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 Thompson3d613fd2013-10-15 15:39:04 -070069NDNBOOST_RT_PARAM_INLINE bool
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070070basic_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 Thompson3d613fd2013-10-15 15:39:04 -070095NDNBOOST_RT_PARAM_INLINE bool
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070096basic_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 Thompson3d613fd2013-10-15 15:39:04 -0700114} // namespace NDNBOOST_RT_PARAM_NAMESPACE
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700115
116} // namespace ndnboost
117
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700118#endif // NDNBOOST_RT_CLA_ID_POLICY_IPP_062904GER