1
// (C) Copyright Gennadiy Rozental 2005-2008.
2
// Distributed under the Boost Software License, Version 1.0.
3
// (See accompanying file LICENSE_1_0.txt or copy at
4
// http://www.boost.org/LICENSE_1_0.txt)
6
// See http://www.boost.org/libs/test for the library home page.
10
// Version : $Revision: 49312 $
12
// Description : default algorithms for string to specific type convertions
13
// ***************************************************************************
15
#ifndef BOOST_RT_INTERPRET_ARGUMENT_VALUE_HPP_062604GER
16
#define BOOST_RT_INTERPRET_ARGUMENT_VALUE_HPP_062604GER
18
// Boost.Runtime.Parameter
19
#include <boost/test/utils/runtime/config.hpp>
20
#include <boost/test/utils/runtime/trace.hpp>
23
#include <boost/test/utils/basic_cstring/io.hpp>
24
#include <boost/test/utils/basic_cstring/compare.hpp>
27
#include <boost/optional.hpp>
28
#include <boost/lexical_cast.hpp>
31
// !! could we eliminate these includes?
36
namespace BOOST_RT_PARAM_NAMESPACE {
38
// ************************************************************************** //
39
// ************** runtime::interpret_argument_value ************** //
40
// ************************************************************************** //
41
// returns true if source is used false otherwise
45
struct interpret_argument_value_impl {
46
static bool _( cstring source, boost::optional<T>& res )
48
BOOST_RT_PARAM_TRACE( "In interpret_argument_value_impl<" << typeid(T).name() << ">" );
50
res = lexical_cast<T>( source );
52
BOOST_RT_PARAM_TRACE( "String " << source << " is interpreted as " << *res );
58
//____________________________________________________________________________//
62
struct interpret_argument_value_impl<dstring> {
63
static bool _( cstring source, boost::optional<dstring>& res )
65
BOOST_RT_PARAM_TRACE( "In interpret_argument_value_impl<dstring>" );
68
assign_op( *res, source, 0 );
74
//____________________________________________________________________________//
78
struct interpret_argument_value_impl<cstring> {
79
static bool _( cstring source, boost::optional<cstring>& res )
81
BOOST_RT_PARAM_TRACE( "In interpret_argument_value_impl<cstring>" );
89
//____________________________________________________________________________//
91
// specialization for type bool
93
struct interpret_argument_value_impl<bool> {
94
static bool _( cstring source, boost::optional<bool>& res )
96
BOOST_RT_PARAM_TRACE( "In interpret_argument_value_impl<bool>" );
98
static literal_cstring YES( BOOST_RT_PARAM_CSTRING_LITERAL( "YES" ) );
99
static literal_cstring Y( BOOST_RT_PARAM_CSTRING_LITERAL( "Y" ) );
100
static literal_cstring NO( BOOST_RT_PARAM_CSTRING_LITERAL( "NO" ) );
101
static literal_cstring N( BOOST_RT_PARAM_CSTRING_LITERAL( "N" ) );
102
static literal_cstring one( BOOST_RT_PARAM_CSTRING_LITERAL( "1" ) );
103
static literal_cstring zero( BOOST_RT_PARAM_CSTRING_LITERAL( "0" ) );
107
if( case_ins_eq( source, YES ) || case_ins_eq( source, Y ) || case_ins_eq( source, one ) ) {
111
else if( case_ins_eq( source, NO ) || case_ins_eq( source, N ) || case_ins_eq( source, zero ) ) {
122
//____________________________________________________________________________//
126
interpret_argument_value( cstring source, boost::optional<T>& res, long )
128
return interpret_argument_value_impl<T>::_( source, res );
131
//____________________________________________________________________________//
133
// specialization for list of values
136
interpret_argument_value( cstring source, boost::optional<std::list<T> >& res, int )
138
BOOST_RT_PARAM_TRACE( "In interpret_argument_value<std::list<T>>" );
140
res = std::list<T>();
142
while( !source.is_empty() ) {
143
// !! should we use token_iterator
144
cstring::iterator single_value_end = std::find( source.begin(), source.end(), BOOST_RT_PARAM_LITERAL( ',' ) );
146
boost::optional<T> value;
147
interpret_argument_value( cstring( source.begin(), single_value_end ), value, 0 );
149
res->push_back( *value );
151
source.trim_left( single_value_end + 1 );
157
//____________________________________________________________________________//
159
} // namespace BOOST_RT_PARAM_NAMESPACE
163
#endif // BOOST_RT_INTERPRET_ARGUMENT_VALUE_HPP_062604GER