diff options
Diffstat (limited to 'boost/test/utils/runtime/cla')
33 files changed, 493 insertions, 2780 deletions
diff --git a/boost/test/utils/runtime/cla/argument_factory.hpp b/boost/test/utils/runtime/cla/argument_factory.hpp deleted file mode 100644 index 6683540612..0000000000 --- a/boost/test/utils/runtime/cla/argument_factory.hpp +++ /dev/null @@ -1,216 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. -// Use, modification, and distribution are subject to the -// Boost Software License, Version 1.0. (See accompanying file -// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - -// See http://www.boost.org/libs/test for the library home page. -// -// File : $RCSfile$ -// -// Version : $Revision$ -// -// Description : generic typed_argument_factory implementation -// *************************************************************************** - -#ifndef BOOST_TEST_UTILS_RUNTIME_CLA_ARGUMENT_FACTORY_HPP -#define BOOST_TEST_UTILS_RUNTIME_CLA_ARGUMENT_FACTORY_HPP - -// Boost.Runtime.Parameter -#include <boost/test/utils/runtime/config.hpp> - -#include <boost/test/utils/runtime/fwd.hpp> -#include <boost/test/utils/runtime/validation.hpp> -#include <boost/test/utils/runtime/argument.hpp> -#include <boost/test/utils/runtime/trace.hpp> -#include <boost/test/utils/runtime/interpret_argument_value.hpp> - -#include <boost/test/utils/runtime/cla/fwd.hpp> -#include <boost/test/utils/runtime/cla/value_generator.hpp> -#include <boost/test/utils/runtime/cla/value_handler.hpp> -#include <boost/test/utils/runtime/cla/validation.hpp> -#include <boost/test/utils/runtime/cla/argv_traverser.hpp> -#include <boost/test/utils/runtime/cla/detail/argument_value_usage.hpp> - -#include <boost/test/utils/runtime/cla/iface/argument_factory.hpp> - -// Boost -#include <boost/optional.hpp> -#include <boost/function/function2.hpp> - -namespace boost { - -namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE { - -namespace cla { - -// ************************************************************************** // -// ************** default_value_interpreter ************** // -// ************************************************************************** // - -namespace rt_cla_detail { - -struct default_value_interpreter { - template<typename T> - void operator()( argv_traverser& tr, boost::optional<T>& value ) - { - if( interpret_argument_value( tr.token(), value, 0 ) ) - tr.next_token(); - } -}; - -} // namespace rt_cla_detail - -// ************************************************************************** // -// ************** typed_argument_factory ************** // -// ************************************************************************** // - -template<typename T> -struct typed_argument_factory : public argument_factory { - // Constructor - typed_argument_factory() - : m_value_interpreter( rt_cla_detail::default_value_interpreter() ) - {} - BOOST_TEST_UTILS_RUNTIME_PARAM_UNNEEDED_VIRTUAL ~typed_argument_factory() {} - - // properties modification - template<typename Modifier> - void accept_modifier( Modifier const& m ) - { - optionally_assign( m_value_handler, m, handler ); - optionally_assign( m_value_interpreter, m, interpreter ); - - if( m.has( default_value ) ) { - BOOST_TEST_UTILS_RUNTIME_PARAM_VALIDATE_LOGIC( !m_value_generator, - BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( "multiple value generators for parameter" ) ); - - T const& dv_ref = m[default_value]; - m_value_generator = rt_cla_detail::const_generator<T>( dv_ref ); - } - - if( m.has( default_refer_to ) ) { - BOOST_TEST_UTILS_RUNTIME_PARAM_VALIDATE_LOGIC( !m_value_generator, - BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( "multiple value generators for parameter" ) ); - - cstring ref_id = m[default_refer_to]; - m_value_generator = rt_cla_detail::ref_generator<T>( ref_id ); - } - - if( m.has( assign_to ) ) { - BOOST_TEST_UTILS_RUNTIME_PARAM_VALIDATE_LOGIC( !m_value_handler, - BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( "multiple value handlers for parameter" ) ); - - m_value_handler = rt_cla_detail::assigner<T>( m[assign_to] ); - } - } - - // Argument factory implementation - virtual argument_ptr produce_using( parameter& p, argv_traverser& tr ); - virtual argument_ptr produce_using( parameter& p, parser const& ); - virtual void argument_usage_info( format_stream& fs ); - -// !! private? - // Data members - boost::function<void (parameter const&,T&)> m_value_handler; - boost::function<void (parser const&,boost::optional<T>&)> m_value_generator; - boost::function<void (argv_traverser&,boost::optional<T>&)> m_value_interpreter; -}; - -//____________________________________________________________________________// - -template<typename T> -inline argument_ptr -typed_argument_factory<T>::produce_using( parameter& p, argv_traverser& tr ) -{ - boost::optional<T> value; - - BOOST_TEST_IMPL_TRY { - m_value_interpreter( tr, value ); - } - BOOST_TEST_IMPL_CATCHALL() { // !! should we do that? - BOOST_TEST_UTILS_RUNTIME_PARAM_TRACE( "Fail to parse argument value" ); - - if( !p.p_optional_value ) - BOOST_TEST_IMPL_RETHROW; - } - - argument_ptr actual_arg = p.actual_argument(); - - BOOST_TEST_UTILS_RUNTIME_CLA_VALIDATE_INPUT( !!value || p.p_optional_value, tr, - BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( "Argument value missing for parameter " ) << p.id_2_report() ); - - BOOST_TEST_UTILS_RUNTIME_CLA_VALIDATE_INPUT( !actual_arg || p.p_multiplicable, tr, - BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( "Unexpected repetition of the parameter " ) << p.id_2_report() ); - - if( !!value && !!m_value_handler ) - m_value_handler( p, *value ); - - if( !p.p_multiplicable ) - actual_arg.reset( p.p_optional_value && (rtti::type_id<T>() != rtti::type_id<bool>()) - ? static_cast<argument*>(new typed_argument<boost::optional<T> >( p, value )) - : static_cast<argument*>(new typed_argument<T>( p, *value )) ); - else { - typedef std::list<boost::optional<T> > optional_list; - - if( !actual_arg ) - actual_arg.reset( p.p_optional_value - ? static_cast<argument*>(new typed_argument<optional_list>( p )) - : static_cast<argument*>(new typed_argument<std::list<T> >( p )) ); - - if( p.p_optional_value ) { - optional_list& values = arg_value<optional_list>( *actual_arg ); - - values.push_back( value ); - } - else { - std::list<T>& values = arg_value<std::list<T> >( *actual_arg ); - - values.push_back( *value ); - } - } - - return actual_arg; -} - -//____________________________________________________________________________// - -template<typename T> -inline argument_ptr -typed_argument_factory<T>::produce_using( parameter& p, parser const& pa ) -{ - argument_ptr actual_arg; - - if( !m_value_generator ) - return actual_arg; - - boost::optional<T> value; - m_value_generator( pa, value ); - - if( !value ) - return actual_arg; - - if( !!m_value_handler ) - m_value_handler( p, *value ); - - actual_arg.reset( new typed_argument<T>( p, *value ) ); - - return actual_arg; -} - -//____________________________________________________________________________// - -template<typename T> -inline void -typed_argument_factory<T>::argument_usage_info( format_stream& fs ) -{ - rt_cla_detail::argument_value_usage( fs, 0, reinterpret_cast<T*>(0) ); -} - -//____________________________________________________________________________// - -} // namespace boost - -} // namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE - -} // namespace cla - -#endif // BOOST_TEST_UTILS_RUNTIME_CLA_ARGUMENT_FACTORY_HPP diff --git a/boost/test/utils/runtime/cla/argv_traverser.cpp b/boost/test/utils/runtime/cla/argv_traverser.cpp deleted file mode 100644 index 9716b8fb9c..0000000000 --- a/boost/test/utils/runtime/cla/argv_traverser.cpp +++ /dev/null @@ -1,16 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. -// Use, modification, and distribution are subject to the -// Boost Software License, Version 1.0. (See accompanying file -// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - -// See http://www.boost.org/libs/test for the library home page. -// -// File : $RCSfile$ -// -// Version : $Revision$ -// -// Description : offline implementation for argc/argv traverser -// *************************************************************************** - -#define BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE -#include <boost/test/utils/runtime/cla/argv_traverser.ipp> diff --git a/boost/test/utils/runtime/cla/argv_traverser.hpp b/boost/test/utils/runtime/cla/argv_traverser.hpp index 6f6e03dfc8..10fb67bde4 100644 --- a/boost/test/utils/runtime/cla/argv_traverser.hpp +++ b/boost/test/utils/runtime/cla/argv_traverser.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. +// (C) Copyright Gennadiy Rozental 2001. // Use, modification, and distribution are subject to the // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -15,86 +15,91 @@ #ifndef BOOST_TEST_UTILS_RUNTIME_CLA_ARGV_TRAVERSER_HPP #define BOOST_TEST_UTILS_RUNTIME_CLA_ARGV_TRAVERSER_HPP -// Boost.Runtime.Parameter -#include <boost/test/utils/runtime/config.hpp> +// Boost.Test Runtime parameters +#include <boost/test/utils/runtime/fwd.hpp> -// Boost.Test -#include <boost/test/utils/class_properties.hpp> - -// Boost -#include <boost/noncopyable.hpp> -#include <boost/shared_array.hpp> +#include <boost/test/detail/suppress_warnings.hpp> namespace boost { - -namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE { - +namespace runtime { namespace cla { // ************************************************************************** // // ************** runtime::cla::argv_traverser ************** // // ************************************************************************** // -class argv_traverser : noncopyable { - class parser; +class argv_traverser { + typedef char const** argv_type; public: - // Constructor - argv_traverser(); - - // public_properties - unit_test::readwrite_property<bool> p_ignore_mismatch; - unit_test::readwrite_property<char_type> p_separator; - - // argc+argv <-> internal buffer exchange - void init( int argc, char_type** argv ); - void remainder( int& argc, char_type** argv ); - - // token based parsing - cstring token() const; - void next_token(); - - // whole input parsing - cstring input() const; - void trim( std::size_t size ); - bool match_front( cstring ); - bool match_front( char_type c ); - bool eoi() const; - - // transaction logic support - void commit(); - void rollback(); - - // current position access; used to save some reference points in input - std::size_t input_pos() const; - - // returns true if mismatch detected during input parsing handled successfully - bool handle_mismatch(); + /// Constructs traverser based on argc/argv pair + /// argv is taken "by reference" and later can be + /// updated in remainder method + argv_traverser( int argc, argv_type argv ) + : m_argc( argc ) + , m_curr_token( 0 ) + , m_token_size( 0 ) + , m_argv( argv ) + { + // save program name + save_token(); + } + + /// Returns new argc + int remainder() + { + return m_argc; + } + + /// Returns true, if we reached end on input + bool eoi() const + { + return m_curr_token == m_argc; + } + + /// Returns current token in the input + cstring current_token() + { + if( eoi() ) + return cstring(); + + return cstring( m_argv[m_curr_token], m_token_size ); + } + + /// Saves current token for remainder + void save_token() + { + ++m_curr_token; + + if( !eoi() ) + m_token_size = ::strlen( m_argv[m_curr_token] ); + } + + /// Commit current token and iterate to next one + void next_token() + { + if( !eoi() ) { + for( std::size_t i = m_curr_token; i < m_argc-1; ++i ) + m_argv[i] = m_argv[i + 1]; + + --m_argc; + + m_token_size = ::strlen( m_argv[m_curr_token] ); + } + } private: - // Data members - dstring m_buffer; - cstring m_work_buffer; - cstring m_token; - cstring::iterator m_commited_end; - - shared_array<char_type> m_remainder; - std::size_t m_remainder_size; + // Data members + std::size_t m_argc; // total number of arguments + std::size_t m_curr_token; // current token index in argv + std::size_t m_token_size; // current token size + argv_type m_argv; // all arguments }; } // namespace cla - -} // namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE - +} // namespace runtime } // namespace boost -#ifndef BOOST_TEST_UTILS_RUNTIME_PARAM_OFFLINE - -#ifndef BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE -# define BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE inline -#endif -# include <boost/test/utils/runtime/cla/argv_traverser.ipp> - -#endif +#include <boost/test/detail/enable_warnings.hpp> #endif // BOOST_TEST_UTILS_RUNTIME_CLA_ARGV_TRAVERSER_HPP diff --git a/boost/test/utils/runtime/cla/argv_traverser.ipp b/boost/test/utils/runtime/cla/argv_traverser.ipp deleted file mode 100644 index d1ae93be82..0000000000 --- a/boost/test/utils/runtime/cla/argv_traverser.ipp +++ /dev/null @@ -1,212 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. -// Use, modification, and distribution are subject to the -// Boost Software License, Version 1.0. (See accompanying file -// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - -// See http://www.boost.org/libs/test for the library home page. -// -// File : $RCSfile$ -// -// Version : $Revision$ -// -// Description : implements facility to hide input traversing details -// *************************************************************************** - -#ifndef BOOST_TEST_UTILS_RUNTIME_CLA_ARGV_TRAVERSER_IPP -#define BOOST_TEST_UTILS_RUNTIME_CLA_ARGV_TRAVERSER_IPP - -// Boost.Runtime.Parameter -#include <boost/test/utils/runtime/trace.hpp> - -#include <boost/test/utils/runtime/cla/argv_traverser.hpp> - -// STL -#include <memory> -#include <cstring> - -#ifdef BOOST_NO_STDC_NAMESPACE -namespace std { using ::memcpy; } -#endif - -namespace boost { - -namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE { - -namespace cla { - -// ************************************************************************** // -// ************** runtime::cla::argv_traverser ************** // -// ************************************************************************** // - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE -argv_traverser::argv_traverser() -: p_ignore_mismatch( false ), p_separator( BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( ' ' ) ) -{ -} - -//____________________________________________________________________________// - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE void -argv_traverser::init( int argc, char_type** argv ) -{ - m_buffer.clear(); - - for( int index = 1; index < argc; ++index ) { - m_buffer += argv[index]; - if( index != argc-1 ) - m_buffer += BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( ' ' ); - } - - m_remainder.reset( new char_type[m_buffer.size()+1] ); - m_remainder_size = 0; - m_work_buffer = m_buffer; - m_commited_end = m_work_buffer.begin(); - - BOOST_TEST_UTILS_RUNTIME_PARAM_TRACE( "Input buffer: " << m_buffer ); - - next_token(); -} - -//____________________________________________________________________________// - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE void -argv_traverser::remainder( int& argc, char_type** argv ) -{ - argc = 1; - std::size_t pos = 0; - while(pos < m_remainder_size ) { - argv[argc++] = m_remainder.get() + pos; - - pos = static_cast<size_t>(std::find( m_remainder.get() + pos, m_remainder.get() + m_remainder_size, - BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( ' ' ) ) - - m_remainder.get()); - m_remainder[pos++] = BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( '\0' ); - } -} - -//____________________________________________________________________________// - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE cstring -argv_traverser::token() const -{ - return m_token; -} - -//____________________________________________________________________________// - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE void -argv_traverser::next_token() -{ - if( m_work_buffer.is_empty() ) - return; - - m_work_buffer.trim_left( m_token.size() ); // skip remainder of current token - - if( m_work_buffer.size() != m_buffer.size() ) // !! is there a better way to identify first token - m_work_buffer.trim_left( 1 ); // skip separator if not first token; - - m_token.assign( m_work_buffer.begin(), - std::find( m_work_buffer.begin(), m_work_buffer.end(), p_separator ) ); -} - -//____________________________________________________________________________// - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE cstring -argv_traverser::input() const -{ - return m_work_buffer; -} - -//____________________________________________________________________________// - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE void -argv_traverser::trim( std::size_t size ) -{ - m_work_buffer.trim_left( size ); - - if( size <= m_token.size() ) - m_token.trim_left( size ); - else { - m_token.assign( m_work_buffer.begin(), - std::find( m_work_buffer.begin(), m_work_buffer.end(), p_separator ) ); - } -} - -//____________________________________________________________________________// - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE bool -argv_traverser::match_front( cstring str ) -{ - return m_work_buffer.size() < str.size() ? false : m_work_buffer.substr( 0, str.size() ) == str; -} - -//____________________________________________________________________________// - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE bool -argv_traverser::match_front( char_type c ) -{ - return first_char( m_work_buffer ) == c; -} - -//____________________________________________________________________________// - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE bool -argv_traverser::eoi() const -{ - return m_work_buffer.is_empty(); -} - -//____________________________________________________________________________// - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE void -argv_traverser::commit() -{ - m_commited_end = m_work_buffer.begin(); -} - -//____________________________________________________________________________// - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE void -argv_traverser::rollback() -{ - m_work_buffer.assign( m_commited_end, m_work_buffer.end() ); - m_token.assign( m_work_buffer.begin(), - std::find( m_work_buffer.begin(), m_work_buffer.end(), p_separator ) ); - -} - -//____________________________________________________________________________// - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE std::size_t -argv_traverser::input_pos() const -{ - return static_cast<std::size_t>(m_work_buffer.begin() - m_commited_end); -} - -//____________________________________________________________________________// - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE bool -argv_traverser::handle_mismatch() -{ - if( !p_ignore_mismatch ) - return false; - - std::memcpy( m_remainder.get() + m_remainder_size, token().begin(), token().size() ); - m_remainder_size += token().size(); - m_remainder[m_remainder_size++] = p_separator; - - next_token(); - commit(); - - return true; -} - -//____________________________________________________________________________// - -} // namespace cla - -} // namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE - -} // namespace boost - -#endif // BOOST_TEST_UTILS_RUNTIME_CLA_ARGV_TRAVERSER_IPP diff --git a/boost/test/utils/runtime/cla/basic_parameter.hpp b/boost/test/utils/runtime/cla/basic_parameter.hpp deleted file mode 100644 index 817b12a301..0000000000 --- a/boost/test/utils/runtime/cla/basic_parameter.hpp +++ /dev/null @@ -1,85 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. -// Use, modification, and distribution are subject to the -// Boost Software License, Version 1.0. (See accompanying file -// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - -// See http://www.boost.org/libs/test for the library home page. -// -// File : $RCSfile$ -// -// Version : $Revision$ -// -// Description : generic custom parameter generator -// *************************************************************************** - -#ifndef BOOST_TEST_UTILS_RUNTIME_CLA_BASIC_PARAMETER_HPP -#define BOOST_TEST_UTILS_RUNTIME_CLA_BASIC_PARAMETER_HPP - -// Boost.Runtime.Parameter -#include <boost/test/utils/runtime/config.hpp> - -#include <boost/test/utils/runtime/cla/typed_parameter.hpp> - -// Boost.Test -#include <boost/test/utils/rtti.hpp> - -// Boost -#include <boost/utility/base_from_member.hpp> - -namespace boost { - -namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE { - -namespace cla { - -// ************************************************************************** // -// ************** runtime::cla::basic_parameter ************** // -// ************************************************************************** // - -template<typename T, typename IdPolicy> -class basic_parameter : private base_from_member<IdPolicy>, public typed_parameter<T> { -public: - // Constructors - explicit basic_parameter( cstring n ) - : base_from_member<IdPolicy>() - , typed_parameter<T>( base_from_member<IdPolicy>::member ) - { - this->accept_modifier( name = n ); - } - - // parameter properties modification - template<typename Modifier> - void accept_modifier( Modifier const& m ) - { - typed_parameter<T>::accept_modifier( m ); - - base_from_member<IdPolicy>::member.accept_modifier( m ); - } -}; - -//____________________________________________________________________________// - -#define BOOST_TEST_UTILS_RUNTIME_CLA_NAMED_PARAM_GENERATORS( param_type ) \ -template<typename T> \ -inline shared_ptr<param_type ## _t<T> > \ -param_type( cstring name = cstring() ) \ -{ \ - return shared_ptr<param_type ## _t<T> >( new param_type ## _t<T>( name ) ); \ -} \ - \ -inline shared_ptr<param_type ## _t<cstring> > \ -param_type( cstring name = cstring() ) \ -{ \ - return shared_ptr<param_type ## _t<cstring> >( new param_type ## _t<cstring>( name ) ); \ -} \ -/**/ - -//____________________________________________________________________________// - -} // namespace cla - -} // namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE - -} // namespace boost - -#endif // BOOST_TEST_UTILS_RUNTIME_CLA_BASIC_PARAMETER_HPP diff --git a/boost/test/utils/runtime/cla/char_parameter.cpp b/boost/test/utils/runtime/cla/char_parameter.cpp deleted file mode 100644 index 6e85fe4136..0000000000 --- a/boost/test/utils/runtime/cla/char_parameter.cpp +++ /dev/null @@ -1,16 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. -// Use, modification, and distribution are subject to the -// Boost Software License, Version 1.0. (See accompanying file -// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - -// See http://www.boost.org/libs/test for the library home page. -// -// File : $RCSfile$ -// -// Version : $Revision$ -// -// Description : offline implementation of char parameter -// *************************************************************************** - -#define BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE -#include <boost/test/utils/runtime/cla/char_parameter.ipp> diff --git a/boost/test/utils/runtime/cla/char_parameter.hpp b/boost/test/utils/runtime/cla/char_parameter.hpp deleted file mode 100644 index 0e2928b1af..0000000000 --- a/boost/test/utils/runtime/cla/char_parameter.hpp +++ /dev/null @@ -1,100 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. -// Use, modification, and distribution are subject to the -// Boost Software License, Version 1.0. (See accompanying file -// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - -// See http://www.boost.org/libs/test for the library home page. -// -// File : $RCSfile$ -// -// Version : $Revision$ -// -// Description : defines model of parameter with single char name -// *************************************************************************** - -#ifndef BOOST_TEST_UTILS_RUNTIME_CLA_CHAR_PARAMETER_HPP -#define BOOST_TEST_UTILS_RUNTIME_CLA_CHAR_PARAMETER_HPP - -// Boost.Runtime.Parameter -#include <boost/test/utils/runtime/config.hpp> -#include <boost/test/utils/runtime/validation.hpp> - -#include <boost/test/utils/runtime/cla/basic_parameter.hpp> -#include <boost/test/utils/runtime/cla/id_policy.hpp> - -namespace boost { - -namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE { - -namespace cla { - -// ************************************************************************** // -// ************** char_name_policy ************** // -// ************************************************************************** // - -class char_name_policy : public basic_naming_policy { -public: - // Constructor - char_name_policy(); - BOOST_TEST_UTILS_RUNTIME_PARAM_UNNEEDED_VIRTUAL ~char_name_policy() {} - - // policy interface - virtual bool conflict_with( identification_policy const& ) const; - - // Accept modifier - template<typename Modifier> - void accept_modifier( Modifier const& m ) - { - basic_naming_policy::accept_modifier( m ); - - BOOST_TEST_UTILS_RUNTIME_PARAM_VALIDATE_LOGIC( p_name->size() <= 1, "Invalid parameter name " << p_name ); - } -}; - -// ************************************************************************** // -// ************** runtime::cla::char_parameter ************** // -// ************************************************************************** // - -template<typename T> -class char_parameter_t : public basic_parameter<T,char_name_policy> { - typedef basic_parameter<T,char_name_policy> base; -public: - // Constructors - explicit char_parameter_t( char_type name ) : base( cstring( &name, 1 ) ) {} -}; - -//____________________________________________________________________________// - -template<typename T> -inline shared_ptr<char_parameter_t<T> > -char_parameter( char_type name ) -{ - return shared_ptr<char_parameter_t<T> >( new char_parameter_t<T>( name ) ); -} - -//____________________________________________________________________________// - -inline shared_ptr<char_parameter_t<cstring> > -char_parameter( char_type name ) -{ - return shared_ptr<char_parameter_t<cstring> >( new char_parameter_t<cstring>( name ) ); -} - -//____________________________________________________________________________// - -} // namespace cla - -} // namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE - -} // namespace boost - -#ifndef BOOST_TEST_UTILS_RUNTIME_PARAM_OFFLINE - -#ifndef BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE -# define BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE inline -#endif -# include <boost/test/utils/runtime/cla/char_parameter.ipp> - -#endif - -#endif // BOOST_TEST_UTILS_RUNTIME_CLA_CHAR_PARAMETER_HPP diff --git a/boost/test/utils/runtime/cla/char_parameter.ipp b/boost/test/utils/runtime/cla/char_parameter.ipp deleted file mode 100644 index 398ce79ac4..0000000000 --- a/boost/test/utils/runtime/cla/char_parameter.ipp +++ /dev/null @@ -1,57 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. -// Use, modification, and distribution are subject to the -// Boost Software License, Version 1.0. (See accompanying file -// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - -// See http://www.boost.org/libs/test for the library home page. -// -// File : $RCSfile$ -// -// Version : $Revision$ -// -// Description : implements model of parameter with single char name -// *************************************************************************** - -#ifndef BOOST_TEST_UTILS_RUNTIME_CLA_CHAR_PARAMETER_IPP -#define BOOST_TEST_UTILS_RUNTIME_CLA_CHAR_PARAMETER_IPP - -// Boost.Runtime.Parameter -#include <boost/test/utils/runtime/config.hpp> - -#include <boost/test/utils/runtime/cla/char_parameter.hpp> - -namespace boost { - -namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE { - -namespace cla { - -// ************************************************************************** // -// ************** char_name_policy ************** // -// ************************************************************************** // - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE -char_name_policy::char_name_policy() -: basic_naming_policy( rtti::type_id<char_name_policy>() ) -{ - assign_op( p_prefix.value, BOOST_TEST_UTILS_RUNTIME_PARAM_CSTRING_LITERAL( "-" ), 0 ); -} - -//____________________________________________________________________________// - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE bool -char_name_policy::conflict_with( identification_policy const& id ) const -{ - return id.p_type_id == p_type_id && - p_name == static_cast<char_name_policy const&>( id ).p_name; -} - -//____________________________________________________________________________// - -} // namespace cla - -} // namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE - -} // namespace boost - -#endif // BOOST_TEST_UTILS_RUNTIME_CLA_CHAR_PARAMETER_IPP diff --git a/boost/test/utils/runtime/cla/detail/argument_value_usage.hpp b/boost/test/utils/runtime/cla/detail/argument_value_usage.hpp deleted file mode 100644 index a70b6d1fb7..0000000000 --- a/boost/test/utils/runtime/cla/detail/argument_value_usage.hpp +++ /dev/null @@ -1,81 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. -// Distributed under the Boost Software License, Version 1.0. -// (See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) - -// See http://www.boost.org/libs/test for the library home page. -// -// File : $RCSfile$ -// -// Version : $Revision$ -// -// Description : argument usage printing helpers -// *************************************************************************** - -#ifndef BOOST_TEST_UTILS_RUNTIME_CLA_ARGUMENT_VALUE_USAGE_HPP -#define BOOST_TEST_UTILS_RUNTIME_CLA_ARGUMENT_VALUE_USAGE_HPP - -// Boost.Runtime.Parameter -#include <boost/test/utils/runtime/config.hpp> -#include <boost/test/utils/runtime/cla/argv_traverser.hpp> - -// Boost.Test -#include <boost/test/utils/basic_cstring/io.hpp> -#include <boost/test/utils/basic_cstring/compare.hpp> - -#include <boost/lexical_cast.hpp> - -// STL -// !! can we eliminate these includes? -#include <list> - -namespace boost { - -namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE { - -namespace cla { - -namespace rt_cla_detail { - -// ************************************************************************** // -// ************** argument_value_usage ************** // -// ************************************************************************** // - -// generic case -template<typename T> -inline void -argument_value_usage( format_stream& fs, long, T* = 0 ) -{ - fs << BOOST_TEST_UTILS_RUNTIME_PARAM_CSTRING_LITERAL( "<value>" ); -} - -//____________________________________________________________________________// - -// specialization for list of values -template<typename T> -inline void -argument_value_usage( format_stream& fs, int, std::list<T>* = 0 ) -{ - fs << BOOST_TEST_UTILS_RUNTIME_PARAM_CSTRING_LITERAL( "(<value1>, ..., <valueN>)" ); -} - -//____________________________________________________________________________// - -// specialization for type bool -inline void -argument_value_usage( format_stream& fs, int, bool* = 0 ) -{ - fs << BOOST_TEST_UTILS_RUNTIME_PARAM_CSTRING_LITERAL( "yes|y|no|n" ); -} - -//____________________________________________________________________________// - -} // namespace rt_cla_detail - -} // namespace cla - -} // namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE - -} // namespace boost - -#endif // BOOST_TEST_UTILS_RUNTIME_CLA_ARGUMENT_VALUE_USAGE_HPP diff --git a/boost/test/utils/runtime/cla/dual_name_parameter.cpp b/boost/test/utils/runtime/cla/dual_name_parameter.cpp deleted file mode 100644 index ab034ff04c..0000000000 --- a/boost/test/utils/runtime/cla/dual_name_parameter.cpp +++ /dev/null @@ -1,16 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. -// Use, modification, and distribution are subject to the -// Boost Software License, Version 1.0. (See accompanying file -// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - -// See http://www.boost.org/libs/test for the library home page. -// -// File : $RCSfile$ -// -// Version : $Revision$ -// -// Description : offline implementation of generic parameter with dual naming -// *************************************************************************** - -#define BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE -#include <boost/test/utils/runtime/cla/dual_name_parameter.ipp> diff --git a/boost/test/utils/runtime/cla/dual_name_parameter.hpp b/boost/test/utils/runtime/cla/dual_name_parameter.hpp deleted file mode 100644 index 789b67ad1d..0000000000 --- a/boost/test/utils/runtime/cla/dual_name_parameter.hpp +++ /dev/null @@ -1,98 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. -// Use, modification, and distribution are subject to the -// Boost Software License, Version 1.0. (See accompanying file -// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - -// See http://www.boost.org/libs/test for the library home page. -// -// File : $RCSfile$ -// -// Version : $Revision$ -// -// Description : defines model of generic parameter with dual naming -// *************************************************************************** - -#ifndef BOOST_TEST_UTILS_RUNTIME_CLA_DUAL_NAME_PARAMETER_HPP -#define BOOST_TEST_UTILS_RUNTIME_CLA_DUAL_NAME_PARAMETER_HPP - -// Boost.Runtime.Parameter -#include <boost/test/utils/runtime/config.hpp> - -#include <boost/test/utils/runtime/cla/named_parameter.hpp> -#include <boost/test/utils/runtime/cla/char_parameter.hpp> - -namespace boost { - -namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE { - -namespace cla { - -// ************************************************************************** // -// ************** dual_name_policy ************** // -// ************************************************************************** // - -class dual_name_policy : public dual_id_policy<dual_name_policy,string_name_policy,char_name_policy> { -public: - dual_name_policy(); - - // Accept modifier - template<typename Modifier> - void accept_modifier( Modifier const& m ) - { - if( m.has( prefix ) ) { - set_prefix( m[prefix] ); - m.erase( prefix ); - } - - if( m.has( name ) ) { - set_name( m[name] ); - m.erase( name ); - } - - if( m.has( separator ) ) { - set_separator( m[separator] ); - m.erase( separator ); - } - - dual_id_policy<dual_name_policy,string_name_policy,char_name_policy>::accept_modifier( m ); - } -private: - void set_prefix( cstring ); - void set_name( cstring ); - void set_separator( cstring ); -}; - -// ************************************************************************** // -// ************** runtime::cla::dual_name_parameter ************** // -// ************************************************************************** // - -template<typename T> -class dual_name_parameter_t : public basic_parameter<T,dual_name_policy> { - typedef basic_parameter<T,dual_name_policy> base; -public: - // Constructors - explicit dual_name_parameter_t( cstring name ) : base( name ) {} -}; - -//____________________________________________________________________________// - -BOOST_TEST_UTILS_RUNTIME_CLA_NAMED_PARAM_GENERATORS( dual_name_parameter ) - -//____________________________________________________________________________// - -} // namespace cla - -} // namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE - -} // namespace boost - -#ifndef BOOST_TEST_UTILS_RUNTIME_PARAM_OFFLINE - -#ifndef BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE -# define BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE inline -#endif -# include <boost/test/utils/runtime/cla/dual_name_parameter.ipp> - -#endif - -#endif // BOOST_TEST_UTILS_RUNTIME_CLA_DUAL_NAME_PARAMETER_HPP diff --git a/boost/test/utils/runtime/cla/dual_name_parameter.ipp b/boost/test/utils/runtime/cla/dual_name_parameter.ipp deleted file mode 100644 index e39d132d62..0000000000 --- a/boost/test/utils/runtime/cla/dual_name_parameter.ipp +++ /dev/null @@ -1,90 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. -// Use, modification, and distribution are subject to the -// Boost Software License, Version 1.0. (See accompanying file -// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - -// See http://www.boost.org/libs/test for the library home page. -// -// File : $RCSfile$ -// -// Version : $Revision$ -// -// Description : implements model of generic parameter with dual naming -// *************************************************************************** - -#ifndef BOOST_TEST_UTILS_RUNTIME_CLA_DUAL_NAME_PARAMETER_IPP -#define BOOST_TEST_UTILS_RUNTIME_CLA_DUAL_NAME_PARAMETER_IPP - -// Boost.Runtime.Parameter -#include <boost/test/utils/runtime/config.hpp> -#include <boost/test/utils/runtime/validation.hpp> - -#include <boost/test/utils/runtime/cla/dual_name_parameter.hpp> - -namespace boost { - -namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE { - -namespace cla { - -// ************************************************************************** // -// ************** dual_name_policy ************** // -// ************************************************************************** // - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE -dual_name_policy::dual_name_policy() -{ - m_primary.accept_modifier( prefix = BOOST_TEST_UTILS_RUNTIME_PARAM_CSTRING_LITERAL( "--" ) ); - m_secondary.accept_modifier( prefix = BOOST_TEST_UTILS_RUNTIME_PARAM_CSTRING_LITERAL( "-" ) ); -} - -//____________________________________________________________________________// - -namespace { - -template<typename K> -inline void -split( string_name_policy& snp, char_name_policy& cnp, cstring src, K const& k ) -{ - cstring::iterator sep = std::find( src.begin(), src.end(), BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( '|' ) ); - - if( sep != src.begin() ) - snp.accept_modifier( k = cstring( src.begin(), sep ) ); - - if( sep != src.end() ) - cnp.accept_modifier( k = cstring( sep+1, src.end() ) ); -} - -} // local namespace - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE void -dual_name_policy::set_prefix( cstring src ) -{ - split( m_primary, m_secondary, src, prefix ); -} - -//____________________________________________________________________________// - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE void -dual_name_policy::set_name( cstring src ) -{ - split( m_primary, m_secondary, src, name ); -} - -//____________________________________________________________________________// - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE void -dual_name_policy::set_separator( cstring src ) -{ - split( m_primary, m_secondary, src, separator ); -} - -//____________________________________________________________________________// - -} // namespace cla - -} // namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE - -} // namespace boost - -#endif // BOOST_TEST_UTILS_RUNTIME_CLA_DUAL_NAME_PARAMETER_IPP diff --git a/boost/test/utils/runtime/cla/fwd.hpp b/boost/test/utils/runtime/cla/fwd.hpp deleted file mode 100644 index df02974345..0000000000 --- a/boost/test/utils/runtime/cla/fwd.hpp +++ /dev/null @@ -1,55 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. -// Use, modification, and distribution are subject to the -// Boost Software License, Version 1.0. (See accompanying file -// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - -// See http://www.boost.org/libs/test for the library home page. -// -// File : $RCSfile$ -// -// Version : $Revision$ -// -// Description : cla subsystem forward declarations -// *************************************************************************** - -#ifndef BOOST_TEST_UTILS_RUNTIME_CLA_FWD_HPP -#define BOOST_TEST_UTILS_RUNTIME_CLA_FWD_HPP - -// Boost.Runtime.Parameter -#include <boost/test/utils/runtime/config.hpp> - -// Boost -#include <boost/shared_ptr.hpp> - -namespace boost { - -namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE { - -namespace cla { - -class parser; -class parameter; -typedef shared_ptr<parameter> parameter_ptr; -class naming_policy; -typedef shared_ptr<naming_policy> naming_policy_ptr; -class argv_traverser; - -namespace rt_cla_detail { - -template<typename T> class const_generator; -template<typename T> class ref_generator; - -template<typename T> class assigner; - -class named_parameter_base; -class positional_parameter_base; - -} // namespace rt_cla_detail - -} // namespace cla - -} // namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE - -} // namespace boost - -#endif // BOOST_TEST_UTILS_RUNTIME_CLA_FWD_HPP diff --git a/boost/test/utils/runtime/cla/id_policy.cpp b/boost/test/utils/runtime/cla/id_policy.cpp deleted file mode 100644 index b000e26f94..0000000000 --- a/boost/test/utils/runtime/cla/id_policy.cpp +++ /dev/null @@ -1,16 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. -// Use, modification, and distribution are subject to the -// Boost Software License, Version 1.0. (See accompanying file -// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - -// See http://www.boost.org/libs/test for the library home page. -// -// File : $RCSfile$ -// -// Version : $Revision$ -// -// Description : some generic identification policies offline implementation -// *************************************************************************** - -#define BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE -#include <boost/test/utils/runtime/cla/id_policy.ipp> diff --git a/boost/test/utils/runtime/cla/id_policy.hpp b/boost/test/utils/runtime/cla/id_policy.hpp deleted file mode 100644 index 3308b07c61..0000000000 --- a/boost/test/utils/runtime/cla/id_policy.hpp +++ /dev/null @@ -1,147 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. -// Use, modification, and distribution are subject to the -// Boost Software License, Version 1.0. (See accompanying file -// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - -// See http://www.boost.org/libs/test for the library home page. -// -// File : $RCSfile$ -// -// Version : $Revision$ -// -// Description : some generic identification policies definition -// *************************************************************************** - -#ifndef BOOST_TEST_UTILS_RUNTIME_CLA_ID_POLICY_HPP -#define BOOST_TEST_UTILS_RUNTIME_CLA_ID_POLICY_HPP - -// Boost.Runtime.Parameter -#include <boost/test/utils/runtime/config.hpp> - -#include <boost/test/utils/runtime/cla/fwd.hpp> -#include <boost/test/utils/runtime/cla/modifier.hpp> -#include <boost/test/utils/runtime/cla/argv_traverser.hpp> - -#include <boost/test/utils/runtime/cla/iface/id_policy.hpp> - -// Boost.Test -#include <boost/test/utils/class_properties.hpp> -#include <boost/test/utils/rtti.hpp> - -namespace boost { - -namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE { - -namespace cla { - -// ************************************************************************** // -// ************** naming_policy_base ************** // -// ************************************************************************** // -// model: <prefix> <name> <separtor> - -class basic_naming_policy : public identification_policy { -public: - // Public properties - unit_test::readwrite_property<dstring> p_prefix; - unit_test::readwrite_property<dstring> p_name; - unit_test::readwrite_property<dstring> p_separator; - - // Policy interface - virtual bool responds_to( cstring name ) const { return p_name == name; } - virtual cstring id_2_report() const { return p_name.get(); } - virtual void usage_info( format_stream& fs ) const; - virtual bool matching( parameter const& p, argv_traverser& tr, bool primary ) const; - - // Accept modifier - template<typename Modifier> - void accept_modifier( Modifier const& m ) - { - nfp::optionally_assign( p_prefix.value, m, prefix ); - nfp::optionally_assign( p_name.value, m, name ); - nfp::optionally_assign( p_separator.value, m, separator ); - } - -protected: - explicit basic_naming_policy( rtti::id_t dyn_type ) - : identification_policy( dyn_type ) - {} - BOOST_TEST_UTILS_RUNTIME_PARAM_UNNEEDED_VIRTUAL ~basic_naming_policy() {} - - // Naming policy interface - virtual bool match_prefix( argv_traverser& tr ) const; - virtual bool match_name( argv_traverser& tr ) const; - virtual bool match_separator( argv_traverser& tr, bool optional_value ) const; -}; - -// ************************************************************************** // -// ************** dual_id_policy ************** // -// ************************************************************************** // - -template<typename MostDerived,typename PrimaryId,typename SecondId> -class dual_id_policy : public identification_policy { -public: - // Constructor - dual_id_policy() - : identification_policy( rtti::type_id<MostDerived>() ) - , m_primary() - , m_secondary() - {} - - // Policy interface - virtual bool responds_to( cstring name ) const - { - return m_primary.responds_to( name ) || m_secondary.responds_to( name ); - } - virtual bool conflict_with( identification_policy const& id_p ) const - { - return id_p.conflict_with( m_primary ) || id_p.conflict_with( m_secondary ); - } - virtual cstring id_2_report() const - { - return m_primary.id_2_report(); - } - virtual void usage_info( format_stream& fs ) const - { - fs << BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( '{' ); - m_primary.usage_info( fs ); - fs << BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( '|' ); - m_secondary.usage_info( fs ); - fs << BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( '}' ); - } - virtual bool matching( parameter const& p, argv_traverser& tr, bool primary ) const - { - return m_primary.matching( p, tr, primary ) || m_secondary.matching( p, tr, primary ); - } - - // Accept modifier - template<typename Modifier> - void accept_modifier( Modifier const& m ) - { - m_primary.accept_modifier( m ); - m_secondary.accept_modifier( m ); - } - -protected: - BOOST_TEST_UTILS_RUNTIME_PARAM_UNNEEDED_VIRTUAL ~dual_id_policy() {} - - // Data members - PrimaryId m_primary; - SecondId m_secondary; -}; - -} // namespace cla - -} // namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE - -} // namespace boost - -#ifndef BOOST_TEST_UTILS_RUNTIME_PARAM_OFFLINE - -#ifndef BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE -# define BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE inline -#endif -# include <boost/test/utils/runtime/cla/id_policy.ipp> - -#endif - -#endif // BOOST_TEST_UTILS_RUNTIME_CLA_ID_POLICY_HPP diff --git a/boost/test/utils/runtime/cla/id_policy.ipp b/boost/test/utils/runtime/cla/id_policy.ipp deleted file mode 100644 index 879ccfd1e1..0000000000 --- a/boost/test/utils/runtime/cla/id_policy.ipp +++ /dev/null @@ -1,118 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. -// Use, modification, and distribution are subject to the -// Boost Software License, Version 1.0. (See accompanying file -// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - -// See http://www.boost.org/libs/test for the library home page. -// -// File : $RCSfile$ -// -// Version : $Revision$ -// -// Description : some generic identification policies implementation -// *************************************************************************** - -#ifndef BOOST_TEST_UTILS_RUNTIME_CLA_ID_POLICY_IPP -#define BOOST_TEST_UTILS_RUNTIME_CLA_ID_POLICY_IPP - -// Boost.Runtime.Parameter -#include <boost/test/utils/runtime/config.hpp> - -#include <boost/test/utils/runtime/cla/id_policy.hpp> -#include <boost/test/utils/runtime/cla/parameter.hpp> - -namespace boost { - -namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE { - -namespace cla { - -// ************************************************************************** // -// ************** basic_naming_policy ************** // -// ************************************************************************** // - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE void -basic_naming_policy::usage_info( format_stream& fs ) const -{ - fs << p_prefix << p_name << p_separator; - - if( p_separator->empty() ) - fs << BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( ' ' ); -} - -//____________________________________________________________________________// - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE bool -basic_naming_policy::match_prefix( argv_traverser& tr ) const -{ - if( !tr.match_front( p_prefix.get() ) ) - return false; - - tr.trim( p_prefix->size() ); - return true; -} - -//____________________________________________________________________________// - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE bool -basic_naming_policy::match_name( argv_traverser& tr ) const -{ - if( !tr.match_front( p_name.get() ) ) - return false; - - tr.trim( p_name->size() ); - return true; -} - -//____________________________________________________________________________// - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE bool -basic_naming_policy::match_separator( argv_traverser& tr, bool optional_value ) const -{ - if( p_separator->empty() ) { - if( !tr.token().is_empty() ) - return false; - - tr.trim( 1 ); - } - else { - if( !tr.match_front( p_separator.get() ) ) { - // if parameter has optional value separator is optional as well - if( optional_value && ( tr.eoi() || tr.match_front( ' ' ) ) ) { - return true; - } - return false; - } - - tr.trim( p_separator->size() ); - } - - return true; -} - -//____________________________________________________________________________// - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE bool -basic_naming_policy::matching( parameter const& p, argv_traverser& tr, bool ) const -{ - if( !match_prefix( tr ) ) - return false; - - if( !match_name( tr ) ) - return false; - - if( !match_separator( tr, p.p_optional_value ) ) - return false; - - return true; -} - -//____________________________________________________________________________// - -} // namespace cla - -} // namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE - -} // namespace boost - -#endif // BOOST_TEST_UTILS_RUNTIME_CLA_ID_POLICY_IPP diff --git a/boost/test/utils/runtime/cla/iface/argument_factory.hpp b/boost/test/utils/runtime/cla/iface/argument_factory.hpp deleted file mode 100644 index cbca713bd3..0000000000 --- a/boost/test/utils/runtime/cla/iface/argument_factory.hpp +++ /dev/null @@ -1,51 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. -// Use, modification, and distribution are subject to the -// Boost Software License, Version 1.0. (See accompanying file -// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - -// See http://www.boost.org/libs/test for the library home page. -// -// File : $RCSfile$ -// -// Version : $Revision$ -// -// Description : defines interface for argument_factory -// *************************************************************************** - -#ifndef BOOST_TEST_UTILS_RUNTIME_CLA_IFACE_ARGUMENT_FACTORY_HPP -#define BOOST_TEST_UTILS_RUNTIME_CLA_IFACE_ARGUMENT_FACTORY_HPP - -// Boost.Runtime.Parameter -#include <boost/test/utils/runtime/config.hpp> -#include <boost/test/utils/runtime/fwd.hpp> - -#include <boost/test/utils/runtime/cla/fwd.hpp> - -namespace boost { - -namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE { - -namespace cla { - -// ************************************************************************** // -// ************** argument_factory ************** // -// ************************************************************************** // -// another name can be argument production policy - -class argument_factory { -public: - // Argument factory interface - virtual argument_ptr produce_using( parameter& p, argv_traverser& tr ) = 0; /// produce argument based on input - virtual argument_ptr produce_using( parameter& p, parser const& ) = 0; /// produce argument based on internal generator and/or values of other parameters - virtual void argument_usage_info( format_stream& fs ) = 0; /// argument value format information -protected: - BOOST_TEST_PROTECTED_VIRTUAL ~argument_factory() {} -}; - -} // namespace boost - -} // namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE - -} // namespace cla - -#endif // BOOST_TEST_UTILS_RUNTIME_CLA_IFACE_ARGUMENT_FACTORY_HPP diff --git a/boost/test/utils/runtime/cla/iface/id_policy.hpp b/boost/test/utils/runtime/cla/iface/id_policy.hpp deleted file mode 100644 index 5fa13e6bc7..0000000000 --- a/boost/test/utils/runtime/cla/iface/id_policy.hpp +++ /dev/null @@ -1,73 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. -// Use, modification, and distribution are subject to the -// Boost Software License, Version 1.0. (See accompanying file -// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - -// See http://www.boost.org/libs/test for the library home page. -// -// File : $RCSfile$ -// -// Version : $Revision$ -// -// Description : defines interface for identification_policy -// *************************************************************************** - -#ifndef BOOST_TEST_UTILS_RUNTIME_CLA_IFACE_ID_POLICY_HPP -#define BOOST_TEST_UTILS_RUNTIME_CLA_IFACE_ID_POLICY_HPP - -// Boost.Runtime.Parameter -#include <boost/test/utils/runtime/config.hpp> - -#include <boost/test/utils/runtime/cla/fwd.hpp> - -// Boost.Test -#include <boost/test/utils/class_properties.hpp> -#include <boost/test/utils/rtti.hpp> - -namespace boost { - -namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE { - -namespace cla { - -// ************************************************************************** // -// ************** identification_policy ************** // -// ************************************************************************** // - -#ifdef BOOST_MSVC -# pragma warning(push) -# pragma warning(disable:4244) -#endif - -class identification_policy { -public: - // Public properties - unit_test::readwrite_property<rtti::id_t> p_type_id; - - // Policy interface - virtual bool responds_to( cstring name ) const = 0; - virtual cstring id_2_report() const = 0; - virtual void usage_info( format_stream& fs ) const = 0; - virtual bool matching( parameter const& p, argv_traverser& tr, bool primary ) const = 0; - - virtual bool conflict_with( identification_policy const& ) const = 0; - -protected: - // Constructor - explicit identification_policy( rtti::id_t dyn_type ) - : p_type_id( dyn_type ) - {} - BOOST_TEST_PROTECTED_VIRTUAL ~identification_policy() {} -}; - -#ifdef BOOST_MSVC -# pragma warning(pop) -#endif - -} // namespace cla - -} // namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE - -} // namespace boost - -#endif // BOOST_TEST_UTILS_RUNTIME_CLA_IFACE_ID_POLICY_HPP diff --git a/boost/test/utils/runtime/cla/modifier.hpp b/boost/test/utils/runtime/cla/modifier.hpp deleted file mode 100644 index 4b55536b73..0000000000 --- a/boost/test/utils/runtime/cla/modifier.hpp +++ /dev/null @@ -1,69 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. -// Use, modification, and distribution are subject to the -// Boost Software License, Version 1.0. (See accompanying file -// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - -// See http://www.boost.org/libs/test for the library home page. -// -// File : $RCSfile$ -// -// Version : $Revision$ -// -// Description : parameter modifiers -// *************************************************************************** - -#ifndef BOOST_TEST_UTILS_RUNTIME_CLA_MODIFIER_HPP -#define BOOST_TEST_UTILS_RUNTIME_CLA_MODIFIER_HPP - -// Boost.Runtime.Parameter -#include <boost/test/utils/runtime/config.hpp> - -// Boost.Test -#include <boost/test/utils/named_params.hpp> - -namespace boost { - -namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE { - -namespace cla { - -// ************************************************************************** // -// ************** environment variable modifiers ************** // -// ************************************************************************** // - -namespace { - -nfp::typed_keyword<bool,struct optional_t> optional_m; -nfp::named_parameter<bool,optional_t,bool> optional( true ); -nfp::typed_keyword<bool,struct required_t> required_m; -nfp::named_parameter<bool,required_t,bool> required( true ); -nfp::typed_keyword<bool,struct multiplicable_t> multiplicable_m; -nfp::named_parameter<bool,multiplicable_t,bool> multiplicable( true ); -nfp::typed_keyword<bool,struct guess_name_t> guess_name_m; -nfp::named_parameter<bool,guess_name_t,bool> guess_name( true ); -nfp::typed_keyword<bool,struct ignore_mismatch_t> ignore_mismatch_m; -nfp::named_parameter<bool,ignore_mismatch_t,bool> ignore_mismatch( true ); -nfp::typed_keyword<bool,struct optional_value_t> optional_value_m; -nfp::named_parameter<bool,optional_value_t,bool> optional_value( true ); - -nfp::typed_keyword<char_type,struct input_separator_t> input_separator; -nfp::typed_keyword<cstring,struct prefix_t> prefix; -nfp::typed_keyword<cstring,struct name_t> name; -nfp::typed_keyword<cstring,struct separator_t> separator; -nfp::typed_keyword<cstring,struct description_t> description; -nfp::typed_keyword<cstring,struct refer_to_t> default_refer_to; - -nfp::keyword<struct default_value_t> default_value; -nfp::keyword<struct handler_t> handler; -nfp::keyword<struct interpreter_t> interpreter; -nfp::keyword<struct assign_to_t> assign_to; - -} // local namespace - -} // namespace cla - -} // namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE - -} // namespace boost - -#endif // BOOST_TEST_UTILS_RUNTIME_CLA_MODIFIER_HPP diff --git a/boost/test/utils/runtime/cla/named_parameter.cpp b/boost/test/utils/runtime/cla/named_parameter.cpp deleted file mode 100644 index 7e94722dc9..0000000000 --- a/boost/test/utils/runtime/cla/named_parameter.cpp +++ /dev/null @@ -1,16 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. -// Use, modification, and distribution are subject to the -// Boost Software License, Version 1.0. (See accompanying file -// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - -// See http://www.boost.org/libs/test for the library home page. -// -// File : $RCSfile$ -// -// Version : $Revision$ -// -// Description : offline implementation of named parameter -// *************************************************************************** - -#define BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE -#include <boost/test/utils/runtime/cla/named_parameter.ipp> diff --git a/boost/test/utils/runtime/cla/named_parameter.hpp b/boost/test/utils/runtime/cla/named_parameter.hpp deleted file mode 100644 index be3f9c570b..0000000000 --- a/boost/test/utils/runtime/cla/named_parameter.hpp +++ /dev/null @@ -1,95 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. -// Use, modification, and distribution are subject to the -// Boost Software License, Version 1.0. (See accompanying file -// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - -// See http://www.boost.org/libs/test for the library home page. -// -// File : $RCSfile$ -// -// Version : $Revision$ -// -// Description : defines model of named parameter -// *************************************************************************** - -#ifndef BOOST_TEST_UTILS_RUNTIME_CLA_NAMED_PARAMETER_HPP -#define BOOST_TEST_UTILS_RUNTIME_CLA_NAMED_PARAMETER_HPP - -// Boost.Runtime.Parameter -#include <boost/test/utils/runtime/config.hpp> - -#include <boost/test/utils/runtime/cla/basic_parameter.hpp> -#include <boost/test/utils/runtime/cla/id_policy.hpp> - -namespace boost { - -namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE { - -namespace cla { - -// ************************************************************************** // -// ************** string_name_policy ************** // -// ************************************************************************** // - -class string_name_policy : public basic_naming_policy { -public: - // Constructor - string_name_policy(); - BOOST_TEST_UTILS_RUNTIME_PARAM_UNNEEDED_VIRTUAL ~string_name_policy() {} - - // policy interface - virtual bool responds_to( cstring name ) const; - virtual bool conflict_with( identification_policy const& ) const; - - // Accept modifier - template<typename Modifier> - void accept_modifier( Modifier const& m ) - { - basic_naming_policy::accept_modifier( m ); - - if( m.has( guess_name_m ) ) - m_guess_name = true; - } - -private: - // Naming policy interface - virtual bool match_name( argv_traverser& tr ) const; - - // Data members - bool m_guess_name; -}; - -// ************************************************************************** // -// ************** runtime::cla::named_parameter ************** // -// ************************************************************************** // - -template<typename T> -class named_parameter_t : public basic_parameter<T,string_name_policy> { - typedef basic_parameter<T,string_name_policy> base; -public: - // Constructors - explicit named_parameter_t( cstring name ) : base( name ) {} -}; - -//____________________________________________________________________________// - -BOOST_TEST_UTILS_RUNTIME_CLA_NAMED_PARAM_GENERATORS( named_parameter ) - -//____________________________________________________________________________// - -} // namespace cla - -} // namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE - -} // namespace boost - -#ifndef BOOST_TEST_UTILS_RUNTIME_PARAM_OFFLINE - -#ifndef BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE -# define BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE inline -#endif -# include <boost/test/utils/runtime/cla/named_parameter.ipp> - -#endif - -#endif // BOOST_TEST_UTILS_RUNTIME_CLA_NAMED_PARAMETER_HPP diff --git a/boost/test/utils/runtime/cla/named_parameter.ipp b/boost/test/utils/runtime/cla/named_parameter.ipp deleted file mode 100644 index e59ebdf89c..0000000000 --- a/boost/test/utils/runtime/cla/named_parameter.ipp +++ /dev/null @@ -1,129 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. -// Use, modification, and distribution are subject to the -// Boost Software License, Version 1.0. (See accompanying file -// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - -// See http://www.boost.org/libs/test for the library home page. -// -// File : $RCSfile$ -// -// Version : $Revision$ -// -// Description : implements model of named parameter -// *************************************************************************** - -#ifndef BOOST_TEST_UTILS_RUNTIME_CLA_NAMED_PARAMETER_IPP -#define BOOST_TEST_UTILS_RUNTIME_CLA_NAMED_PARAMETER_IPP - -// Boost.Runtime.Parameter -#include <boost/test/utils/runtime/config.hpp> - -#include <boost/test/utils/runtime/cla/named_parameter.hpp> -#include <boost/test/utils/runtime/cla/char_parameter.hpp> - -// Boost.Test -#include <boost/test/utils/algorithm.hpp> - -namespace boost { - -namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE { - -namespace cla { - -// ************************************************************************** // -// ************** string_name_policy ************** // -// ************************************************************************** // - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE -string_name_policy::string_name_policy() -: basic_naming_policy( rtti::type_id<string_name_policy>() ) -, m_guess_name( false ) -{ - assign_op( p_prefix.value, BOOST_TEST_UTILS_RUNTIME_PARAM_CSTRING_LITERAL( "-" ), 0 ); -} - -//____________________________________________________________________________// - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE bool -string_name_policy::responds_to( cstring name ) const -{ - std::pair<cstring::iterator,dstring::const_iterator> mm_pos; - - mm_pos = unit_test::mismatch( name.begin(), name.end(), p_name->begin(), p_name->end() ); - - return mm_pos.first == name.end() && (m_guess_name || (mm_pos.second == p_name->end()) ); -} - -//____________________________________________________________________________// - -#ifdef BOOST_MSVC -# pragma warning(push) -# pragma warning(disable:4244) -#endif - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE bool -string_name_policy::conflict_with( identification_policy const& id ) const -{ - if( id.p_type_id == p_type_id ) { - string_name_policy const& snp = static_cast<string_name_policy const&>( id ); - - if( p_name->empty() || snp.p_name->empty() ) - return false; - - if( p_prefix != snp.p_prefix ) - return false; - - std::pair<dstring::const_iterator,dstring::const_iterator> mm_pos = - unit_test::mismatch( p_name->begin(), p_name->end(), snp.p_name->begin(), snp.p_name->end() ); - - return mm_pos.first != p_name->begin() && // there is common substring - ((m_guess_name && (mm_pos.second == snp.p_name->end()) ) || // that match other guy and I am guessing - (snp.m_guess_name && (mm_pos.first == p_name->end()) )); // or me and the other guy is - } - - if( id.p_type_id == rtti::type_id<char_name_policy>() ) { - char_name_policy const& cnp = static_cast<char_name_policy const&>( id ); - - return m_guess_name && - (p_prefix == cnp.p_prefix) && - unit_test::first_char( cstring( p_name ) ) == unit_test::first_char( cstring( cnp.p_name ) ); - } - - return false; -} - -#ifdef BOOST_MSVC -# pragma warning(pop) -#endif - -//____________________________________________________________________________// - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE bool -string_name_policy::match_name( argv_traverser& tr ) const -{ - if( !m_guess_name ) - return basic_naming_policy::match_name( tr ); - - cstring in = tr.input(); - - std::pair<cstring::iterator,dstring::const_iterator> mm_pos; - - mm_pos = unit_test::mismatch( in.begin(), in.end(), p_name->begin(), p_name->end() ); - - if( mm_pos.first == in.begin() ) - return false; - - tr.trim( static_cast<std::size_t>(mm_pos.first - in.begin()) ); - - return true; -} - -//____________________________________________________________________________// - -} // namespace cla - -} // namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE - -} // namespace boost - -#endif // BOOST_TEST_UTILS_RUNTIME_CLA_NAMED_PARAMETER_IPP diff --git a/boost/test/utils/runtime/cla/parameter.hpp b/boost/test/utils/runtime/cla/parameter.hpp deleted file mode 100644 index 9e26d25007..0000000000 --- a/boost/test/utils/runtime/cla/parameter.hpp +++ /dev/null @@ -1,151 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. -// Use, modification, and distribution are subject to the -// Boost Software License, Version 1.0. (See accompanying file -// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - -// See http://www.boost.org/libs/test for the library home page. -// -// File : $RCSfile$ -// -// Version : $Revision$ -// -// Description : defines model of formal parameter -// *************************************************************************** - -#ifndef BOOST_TEST_UTILS_RUNTIME_CLA_PARAMETER_HPP -#define BOOST_TEST_UTILS_RUNTIME_CLA_PARAMETER_HPP - -// Boost.Runtime.Parameter -#include <boost/test/utils/runtime/config.hpp> - -#include <boost/test/utils/runtime/fwd.hpp> -#include <boost/test/utils/runtime/parameter.hpp> -#include <boost/test/utils/runtime/validation.hpp> - -#include <boost/test/utils/runtime/cla/fwd.hpp> -#include <boost/test/utils/runtime/cla/modifier.hpp> -#include <boost/test/utils/runtime/cla/iface/argument_factory.hpp> -#include <boost/test/utils/runtime/cla/iface/id_policy.hpp> - -// Boost.Test -#include <boost/test/utils/rtti.hpp> - -namespace boost { - -namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE { - -namespace cla { - -// ************************************************************************** // -// ************** runtime::cla::parameter ************** // -// ************************************************************************** // - -class parameter : public BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE::parameter { -public: - parameter( identification_policy& ID, argument_factory& F, bool optional_value = false ) - : p_optional( false ) - , p_multiplicable( false ) - , p_optional_value( optional_value ) - , m_id_policy( ID ) - , m_arg_factory( F ) - {} - - // Destructor - virtual ~parameter() {} - - unit_test::readwrite_property<bool> p_optional; - unit_test::readwrite_property<bool> p_multiplicable; - unit_test::readwrite_property<bool> p_optional_value; - unit_test::readwrite_property<dstring> p_description; - - // parameter properties modification - template<typename Modifier> - void accept_modifier( Modifier const& m ) - { - if( m.has( optional_m ) ) - p_optional.value = true; - - if( m.has( required_m ) ) - p_optional.value = false; - - if( m.has( multiplicable_m ) ) - p_multiplicable.value = true; - - if( m.has( optional_value_m ) ) - p_optional_value.value = true; - - nfp::optionally_assign( p_description.value, m, description ); - } - - // access methods - bool has_argument() const { return !!m_actual_argument; } - argument const& actual_argument() const { return *m_actual_argument; } - argument_ptr actual_argument() { return m_actual_argument; } - void reset() { m_actual_argument.reset(); } - - - // identification interface - bool responds_to( cstring name ) const { return m_id_policy.responds_to( name ); } - bool conflict_with( parameter const& p ) const - { - return (id_2_report() == p.id_2_report() && !id_2_report().is_empty()) || - m_id_policy.conflict_with( p.m_id_policy ) || - ((m_id_policy.p_type_id != p.m_id_policy.p_type_id) && p.m_id_policy.conflict_with( m_id_policy )); - } - cstring id_2_report() const { return m_id_policy.id_2_report(); } - void usage_info( format_stream& fs ) const - { - m_id_policy.usage_info( fs ); - if( p_optional_value ) - fs << BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( '[' ); - - m_arg_factory.argument_usage_info( fs ); - - if( p_optional_value ) - fs << BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( ']' ); - } - - // argument match/produce based on input - bool matching( argv_traverser& tr, bool primary ) const - { - return m_id_policy.matching( *this, tr, primary ); - } - - // argument production based on different source - void produce_argument( argv_traverser& tr ) - { - m_id_policy.matching( *this, tr, true ); // !! can we save this position somehow - m_actual_argument = m_arg_factory.produce_using( *this, tr ); - } - void produce_argument( parser const& p ) - { - m_actual_argument = m_arg_factory.produce_using( *this, p ); - } - -private: - //Data members - identification_policy& m_id_policy; - argument_factory& m_arg_factory; - argument_ptr m_actual_argument; -}; - -//____________________________________________________________________________// - -template<typename Parameter,typename Modifier> -inline shared_ptr<Parameter> -operator-( shared_ptr<Parameter> p, Modifier const& m ) -{ - p->accept_modifier( m ); - - return p; -} - -//____________________________________________________________________________// - -} // namespace cla - -} // namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE - -} // namespace boost - -#endif // BOOST_TEST_UTILS_RUNTIME_CLA_PARAMETER_HPP diff --git a/boost/test/utils/runtime/cla/parser.cpp b/boost/test/utils/runtime/cla/parser.cpp deleted file mode 100644 index 8efc17d3b2..0000000000 --- a/boost/test/utils/runtime/cla/parser.cpp +++ /dev/null @@ -1,18 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. -// Use, modification, and distribution are subject to the -// Boost Software License, Version 1.0. (See accompanying file -// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - -// See http://www.boost.org/libs/test for the library home page. -// -// File : $RCSfile$ -// -// Version : $Revision$ -// -// Description : offline implementation for parser -// *************************************************************************** - -#include <boost/test/utils/runtime/config.hpp> - -#define BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE -#include <boost/test/utils/runtime/cla/parser.ipp> diff --git a/boost/test/utils/runtime/cla/parser.hpp b/boost/test/utils/runtime/cla/parser.hpp index ffe09e4adc..effde33a52 100644 --- a/boost/test/utils/runtime/cla/parser.hpp +++ b/boost/test/utils/runtime/cla/parser.hpp @@ -1,158 +1,491 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. +// (C) Copyright Gennadiy Rozental 2001. // Use, modification, and distribution are subject to the // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // See http://www.boost.org/libs/test for the library home page. // -// File : $RCSfile$ -// -// Version : $Revision$ -// -// Description : defines parser - public interface for CLA parsing and accessing +//!@file +//!@brief CLA parser // *************************************************************************** #ifndef BOOST_TEST_UTILS_RUNTIME_CLA_PARSER_HPP #define BOOST_TEST_UTILS_RUNTIME_CLA_PARSER_HPP -// Boost.Runtime.Parameter -#include <boost/test/utils/runtime/config.hpp> -#include <boost/test/utils/runtime/fwd.hpp> +// Boost.Test Runtime parameters #include <boost/test/utils/runtime/argument.hpp> +#include <boost/test/utils/runtime/modifier.hpp> +#include <boost/test/utils/runtime/parameter.hpp> -#include <boost/test/utils/runtime/cla/fwd.hpp> -#include <boost/test/utils/runtime/cla/modifier.hpp> #include <boost/test/utils/runtime/cla/argv_traverser.hpp> -// Boost -#include <boost/optional.hpp> +// Boost.Test +#include <boost/test/utils/foreach.hpp> +#include <boost/test/utils/algorithm.hpp> +#include <boost/test/detail/throw_exception.hpp> -// STL -#include <list> +#include <boost/algorithm/cxx11/all_of.hpp> // !! ?? unnecessary after cxx11 -namespace boost { +// STL +// !! ?? #include <unordered_set> +#include <set> +#include <iostream> -namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE { +#include <boost/test/detail/suppress_warnings.hpp> +namespace boost { +namespace runtime { namespace cla { // ************************************************************************** // -// ************** runtime::cla::parser ************** // +// ************** runtime::cla::parameter_trie ************** // // ************************************************************************** // -namespace cla_detail { +namespace rt_cla_detail { -template<typename Modifier> -class global_mod_parser { -public: - global_mod_parser( parser& p, Modifier const& m ) - : m_parser( p ) - , m_modifiers( m ) - {} - - template<typename Param> - global_mod_parser const& - operator<<( shared_ptr<Param> param ) const +struct parameter_trie; +typedef shared_ptr<parameter_trie> parameter_trie_ptr; +typedef std::map<char,parameter_trie_ptr> trie_per_char; +typedef std::vector<boost::reference_wrapper<parameter_cla_id const> > param_cla_id_list; + +struct parameter_trie { + parameter_trie() : m_has_final_candidate( false ) {} + + /// If subtrie corresponding to the char c exists returns it otherwise creates new + parameter_trie_ptr make_subtrie( char c ) { - param->accept_modifier( m_modifiers ); + trie_per_char::const_iterator it = m_subtrie.find( c ); - m_parser << param; + if( it == m_subtrie.end() ) + it = m_subtrie.insert( std::make_pair( c, parameter_trie_ptr( new parameter_trie ) ) ).first; - return *this; + return it->second; } -private: - // Data members; - parser& m_parser; - Modifier const& m_modifiers; + /// Creates series of sub-tries per characters in a string + parameter_trie_ptr make_subtrie( cstring s ) + { + parameter_trie_ptr res; + + BOOST_TEST_FOREACH( char, c, s ) + res = (res ? res->make_subtrie( c ) : make_subtrie( c )); + + return res; + } + + /// Registers candidate parameter for this subtrie. If final, it needs to be unique + void add_candidate_id( parameter_cla_id const& param_id, basic_param_ptr param_candidate, bool final ) + { + BOOST_TEST_I_ASSRT( !m_has_final_candidate && (!final || m_id_candidates.empty()), + conflicting_param() << "Parameter cla id " << param_id.m_tag << " conflicts with the " + << "parameter cla id " << m_id_candidates.back().get().m_tag ); + + m_has_final_candidate = final; + m_id_candidates.push_back( ref(param_id) ); + + if( m_id_candidates.size() == 1 ) + m_param_candidate = param_candidate; + else + m_param_candidate.reset(); + } + + /// Gets subtrie for specified char if present or nullptr otherwise + parameter_trie_ptr get_subtrie( char c ) const + { + trie_per_char::const_iterator it = m_subtrie.find( c ); + + return it != m_subtrie.end() ? it->second : parameter_trie_ptr(); + } + + // Data members + trie_per_char m_subtrie; + param_cla_id_list m_id_candidates; + basic_param_ptr m_param_candidate; + bool m_has_final_candidate; }; +// ************************************************************************** // +// ************** runtime::cla::report_foreing_token ************** // +// ************************************************************************** // + +static void +report_foreing_token( cstring program_name, cstring token ) +{ + std::cerr << "Boost.Test WARNING: token \"" << token << "\" does not correspond to the Boost.Test argument \n" + << " and should be placed after all Boost.Test arguments and the -- separator.\n" + << " For example: " << program_name << " --random -- " << token << "\n"; } +} // namespace rt_cla_detail + // ************************************************************************** // // ************** runtime::cla::parser ************** // // ************************************************************************** // class parser { public: - typedef std::list<parameter_ptr>::const_iterator param_iterator; - typedef std::list<parameter_ptr>::size_type param_size_type; - - // Constructor - explicit parser( cstring program_name = cstring() ); + /// Initializes a parser and builds internal trie representation used for + /// parsing based on the supplied parameters +#ifndef BOOST_NO_CXX11_FUNCTION_TEMPLATE_DEFAULT_ARGS + template<typename Modifiers=nfp::no_params_type> + parser( parameters_store const& parameters, Modifiers const& m = nfp::no_params ) +#else + template<typename Modifiers> + parser( parameters_store const& parameters, Modifiers const& m ) +#endif + { + nfp::opt_assign( m_end_of_param_indicator, m, end_of_params ); + nfp::opt_assign( m_negation_prefix, m, negation_prefix ); - // parameter list construction interface - parser& operator<<( parameter_ptr param ); + BOOST_TEST_I_ASSRT( algorithm::all_of( m_end_of_param_indicator.begin(), + m_end_of_param_indicator.end(), + parameter_cla_id::valid_prefix_char ), + invalid_cla_id() << "End of parameters indicator can only consist of prefix characters." ); - // parser and global parameters modifiers - template<typename Modifier> - cla_detail::global_mod_parser<Modifier> - operator-( Modifier const& m ) - { - nfp::optionally_assign( m_traverser.p_separator.value, m, input_separator ); - nfp::optionally_assign( m_traverser.p_ignore_mismatch.value, m, ignore_mismatch_m ); + BOOST_TEST_I_ASSRT( algorithm::all_of( m_negation_prefix.begin(), + m_negation_prefix.end(), + parameter_cla_id::valid_name_char ), + invalid_cla_id() << "Negation prefix can only consist of prefix characters." ); - return cla_detail::global_mod_parser<Modifier>( *this, m ); + build_trie( parameters ); } // input processing method - void parse( int& argc, char_type** argv ); + int + parse( int argc, char** argv, runtime::arguments_store& res ) + { + // save program name for help message + m_program_name = argv[0]; + cstring path_sep( "\\/" ); + + cstring::iterator it = unit_test::utils::find_last_of( m_program_name.begin(), m_program_name.end(), + path_sep.begin(), path_sep.end() ); + if( it != m_program_name.end() ) + m_program_name.trim_left( it + 1 ); + + // Set up the traverser + argv_traverser tr( argc, (char const**)argv ); + + // Loop till we reach end of input + while( !tr.eoi() ) { + cstring curr_token = tr.current_token(); + + cstring prefix; + cstring name; + cstring value_separator; + bool negative_form = false; + + // Perform format validations and split the argument into prefix, name and separator + // False return value indicates end of params indicator is met + if( !validate_token_format( curr_token, prefix, name, value_separator, negative_form ) ) { + // get rid of "end of params" token + tr.next_token(); + break; + } + + // Locate trie corresponding to found prefix and skip it in the input + trie_ptr curr_trie = m_param_trie[prefix]; + + if( !curr_trie ) { + // format_error() << "Unrecognized parameter prefix in the argument " << tr.current_token() + rt_cla_detail::report_foreing_token( m_program_name, curr_token ); + tr.save_token(); + continue; + } + + curr_token.trim_left( prefix.size() ); + + // Locate parameter based on a name and skip it in the input + locate_result locate_res = locate_parameter( curr_trie, name, curr_token ); + parameter_cla_id const& found_id = locate_res.first; + basic_param_ptr found_param = locate_res.second; + + if( negative_form ) { + BOOST_TEST_I_ASSRT( found_id.m_negatable, + format_error( found_param->p_name ) + << "Parameter tag " << found_id.m_tag << " is not negatable." ); + + curr_token.trim_left( m_negation_prefix.size() ); + } + + curr_token.trim_left( name.size() ); + + cstring value; + + // Skip validations if parameter has optional value and we are at the end of token + if( !value_separator.is_empty() || !found_param->p_has_optional_value ) { + // Validate and skip value separator in the input + BOOST_TEST_I_ASSRT( found_id.m_value_separator == value_separator, + format_error( found_param->p_name ) + << "Invalid separator for the parameter " + << found_param->p_name + << " in the argument " << tr.current_token() ); + + curr_token.trim_left( value_separator.size() ); + + // Deduce value source + value = curr_token; + if( value.is_empty() ) { + tr.next_token(); + value = tr.current_token(); + } + + BOOST_TEST_I_ASSRT( !value.is_empty(), + format_error( found_param->p_name ) + << "Missing an argument value for the parameter " + << found_param->p_name + << " in the argument " << tr.current_token() ); + } + + // Validate against argument duplication + BOOST_TEST_I_ASSRT( !res.has( found_param->p_name ) || found_param->p_repeatable, + duplicate_arg( found_param->p_name ) + << "Duplicate argument value for the parameter " + << found_param->p_name + << " in the argument " << tr.current_token() ); + + // Produce argument value + found_param->produce_argument( value, negative_form, res ); + + tr.next_token(); + } + + // generate the remainder and return it's size + return tr.remainder(); + } - // parameters access - param_iterator first_param() const; - param_iterator last_param() const; - param_size_type num_params() const { return m_parameters.size(); } - void reset(); + // help/usage + void + usage( std::ostream& ostr, cstring param_name = cstring() ) + { + if( !param_name.is_empty() ) { + basic_param_ptr param = locate_parameter( m_param_trie[help_prefix], param_name, "" ).second; + param->usage( ostr, m_negation_prefix ); + } + else { + ostr << "Usage: " << m_program_name << " [Boost.Test argument]... "; + if( !m_end_of_param_indicator.empty() ) + ostr << m_end_of_param_indicator << " [custom test module argument]..."; + ostr << "\n"; + } + + ostr << "\nFor detailed help on Boost.Test parameters use:\n" + << " " << m_program_name << " --help\n" + << "or\n" + << " " << m_program_name << " --help=<parameter name>\n"; + } - // arguments access - const_argument_ptr operator[]( cstring string_id ) const; - cstring get( cstring string_id ) const; + void + help( std::ostream& ostr, parameters_store const& parameters, cstring param_name ) + { + if( !param_name.is_empty() ) { + basic_param_ptr param = locate_parameter( m_param_trie[help_prefix], param_name, "" ).second; + param->help( ostr, m_negation_prefix ); + return; + } + + ostr << "Usage: " << m_program_name << " [Boost.Test argument]... "; + if( !m_end_of_param_indicator.empty() ) + ostr << m_end_of_param_indicator << " [custom test module argument]..."; + + ostr << "\n\nBoost.Test arguments correspond to parameters listed below. " + "All parameters are optional. You can use specify parameter value either " + "as a command line argument or as a value of corresponding environment " + "variable. In case if argument for the same parameter is specified in both " + "places, command line is taking precedence. Command line argument format " + "supports parameter name guessing, so you can use any unambiguous " + "prefix to identify a parameter."; + if( !m_end_of_param_indicator.empty() ) + ostr << " All the arguments after the " << m_end_of_param_indicator << " are ignored by the Boost.Test."; + + ostr << "\n\nBoost.Test supports following parameters:\n"; + + BOOST_TEST_FOREACH( parameters_store::storage_type::value_type const&, v, parameters.all() ) { + basic_param_ptr param = v.second; + + param->usage( ostr, m_negation_prefix ); + } + + ostr << "\nUse --help=<parameter name> to display detailed help for specific parameter.\n"; + } - template<typename T> - T const& get( cstring string_id ) const +private: + typedef rt_cla_detail::parameter_trie_ptr trie_ptr; + typedef rt_cla_detail::trie_per_char trie_per_char; + typedef std::map<cstring,trie_ptr> str_to_trie; + + void + build_trie( parameters_store const& parameters ) { - return arg_value<T>( valid_argument( string_id ) ); + // Iterate over all parameters + BOOST_TEST_FOREACH( parameters_store::storage_type::value_type const&, v, parameters.all() ) { + basic_param_ptr param = v.second; + + // Register all parameter's ids in trie. + BOOST_TEST_FOREACH( parameter_cla_id const&, id, param->cla_ids() ) { + // This is the trie corresponding to the prefix. + trie_ptr next_trie = m_param_trie[id.m_prefix]; + if( !next_trie ) + next_trie = m_param_trie[id.m_prefix] = trie_ptr( new rt_cla_detail::parameter_trie ); + + // Build the trie, by following name's characters + // and register this parameter as candidate on each level + for( size_t index = 0; index < id.m_tag.size(); ++index ) { + next_trie = next_trie->make_subtrie( id.m_tag[index] ); + + next_trie->add_candidate_id( id, param, index == (id.m_tag.size() - 1) ); + } + } + } } - template<typename T> - void get( cstring string_id, boost::optional<T>& res ) const + bool + validate_token_format( cstring token, cstring& prefix, cstring& name, cstring& separator, bool& negative_form ) { - const_argument_ptr actual_arg = (*this)[string_id]; + // Match prefix + cstring::iterator it = token.begin(); + while( it != token.end() && parameter_cla_id::valid_prefix_char( *it ) ) + ++it; - if( actual_arg ) - res = arg_value<T>( *actual_arg ); - else - res.reset(); - } + prefix.assign( token.begin(), it ); - // help/usage - void usage( out_stream& ostr ); - void help( out_stream& ostr ); + if( prefix.empty() ) + return true; -private: - argument const& valid_argument( cstring string_id ) const; + // Match name + while( it != token.end() && parameter_cla_id::valid_name_char( *it ) ) + ++it; - // Data members - argv_traverser m_traverser; - std::list<parameter_ptr> m_parameters; - dstring m_program_name; -}; + name.assign( prefix.end(), it ); -//____________________________________________________________________________// + if( name.empty() ) { + if( prefix == m_end_of_param_indicator ) + return false; -} // namespace cla + BOOST_TEST_I_THROW( format_error() << "Invalid format for an actual argument " << token ); + } -} // namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE + // Match value separator + while( it != token.end() && parameter_cla_id::valid_separator_char( *it ) ) + ++it; -} // namespace boost + separator.assign( name.end(), it ); -#ifndef BOOST_TEST_UTILS_RUNTIME_PARAM_OFFLINE + // Match negation prefix + negative_form = !m_negation_prefix.empty() && ( name.substr( 0, m_negation_prefix.size() ) == m_negation_prefix ); + if( negative_form ) + name.trim_left( m_negation_prefix.size() ); -#ifndef BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE -# define BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE inline -#endif -# include <boost/test/utils/runtime/cla/parser.ipp> + return true; + } + // C++03: cannot have references as types + typedef std::pair<parameter_cla_id, basic_param_ptr> locate_result; + + locate_result + locate_parameter( trie_ptr curr_trie, cstring name, cstring token ) + { + std::vector<trie_ptr> typo_candidates; + std::vector<trie_ptr> next_typo_candidates; + trie_ptr next_trie; + + BOOST_TEST_FOREACH( char, c, name ) { + if( curr_trie ) { + // locate next subtrie corresponding to the char + next_trie = curr_trie->get_subtrie( c ); + + if( next_trie ) + curr_trie = next_trie; + else { + // Initiate search for typo candicates. We will account for 'wrong char' typo + // 'missing char' typo and 'extra char' typo + BOOST_TEST_FOREACH( trie_per_char::value_type const&, typo_cand, curr_trie->m_subtrie ) { + // 'wrong char' typo + typo_candidates.push_back( typo_cand.second ); + + // 'missing char' typo + if( (next_trie = typo_cand.second->get_subtrie( c )) ) + typo_candidates.push_back( next_trie ); + } + + // 'extra char' typo + typo_candidates.push_back( curr_trie ); + + curr_trie.reset(); + } + } + else { + // go over existing typo candidates and see if they are still viable + BOOST_TEST_FOREACH( trie_ptr, typo_cand, typo_candidates ) { + trie_ptr next_typo_cand = typo_cand->get_subtrie( c ); + + if( next_typo_cand ) + next_typo_candidates.push_back( next_typo_cand ); + } + + next_typo_candidates.swap( typo_candidates ); + next_typo_candidates.clear(); + } + } + + if( !curr_trie ) { + std::vector<cstring> typo_candidate_names; + std::set<parameter_cla_id const*> unique_typo_candidate; // !! ?? unordered_set + typo_candidate_names.reserve( typo_candidates.size() ); +// !! ?? unique_typo_candidate.reserve( typo_candidates.size() ); + + BOOST_TEST_FOREACH( trie_ptr, trie_cand, typo_candidates ) { + // avoid ambiguos candidate trie + if( trie_cand->m_id_candidates.size() > 1 ) + continue; + + BOOST_TEST_FOREACH( parameter_cla_id const&, param_cand, trie_cand->m_id_candidates ) { + if( !unique_typo_candidate.insert( ¶m_cand ).second ) + continue; + + typo_candidate_names.push_back( param_cand.m_tag ); + } + } + +#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES + BOOST_TEST_I_THROW( unrecognized_param( std::move(typo_candidate_names) ) + << "An unrecognized parameter in the argument " + << token ); +#else + BOOST_TEST_I_THROW( unrecognized_param( typo_candidate_names ) + << "An unrecognized parameter in the argument " + << token ); #endif + } + + if( curr_trie->m_id_candidates.size() > 1 ) { + std::vector<cstring> amb_names; + BOOST_TEST_FOREACH( parameter_cla_id const&, param_id, curr_trie->m_id_candidates ) + amb_names.push_back( param_id.m_tag ); + +#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES + BOOST_TEST_I_THROW( ambiguous_param( std::move( amb_names ) ) + << "An ambiguous parameter name in the argument " << token ); +#else + BOOST_TEST_I_THROW( ambiguous_param( amb_names ) + << "An ambiguous parameter name in the argument " << token ); +#endif + } + + return locate_result( curr_trie->m_id_candidates.back().get(), curr_trie->m_param_candidate ); + } + + // Data members + cstring m_program_name; + std::string m_end_of_param_indicator; + std::string m_negation_prefix; + str_to_trie m_param_trie; +}; + +} // namespace cla +} // namespace runtime +} // namespace boost + +#include <boost/test/detail/enable_warnings.hpp> #endif // BOOST_TEST_UTILS_RUNTIME_CLA_PARSER_HPP diff --git a/boost/test/utils/runtime/cla/parser.ipp b/boost/test/utils/runtime/cla/parser.ipp deleted file mode 100644 index b8a4ca4636..0000000000 --- a/boost/test/utils/runtime/cla/parser.ipp +++ /dev/null @@ -1,267 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. -// Use, modification, and distribution are subject to the -// Boost Software License, Version 1.0. (See accompanying file -// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - -// See http://www.boost.org/libs/test for the library home page. -// -// File : $RCSfile$ -// -// Version : $Revision$ -// -// Description : implements parser - public interface for CLA parsing and accessing -// *************************************************************************** - -#ifndef BOOST_TEST_UTILS_RUNTIME_CLA_PARSER_IPP -#define BOOST_TEST_UTILS_RUNTIME_CLA_PARSER_IPP - -// Boost.Runtime.Parameter -#include <boost/test/utils/runtime/config.hpp> -#include <boost/test/utils/runtime/trace.hpp> -#include <boost/test/utils/runtime/argument.hpp> - -#include <boost/test/utils/runtime/cla/argv_traverser.hpp> -#include <boost/test/utils/runtime/cla/parameter.hpp> -#include <boost/test/utils/runtime/cla/modifier.hpp> -#include <boost/test/utils/runtime/cla/validation.hpp> -#include <boost/test/utils/runtime/cla/parser.hpp> - -// Boost.Test -#include <boost/test/utils/basic_cstring/io.hpp> -#include <boost/test/utils/foreach.hpp> - -// Boost -#include <boost/lexical_cast.hpp> - -namespace boost { - -namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE { - -namespace cla { - -// ************************************************************************** // -// ************** runtime::cla::parser ************** // -// ************************************************************************** // - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE -parser::parser( cstring program_name ) -{ - assign_op( m_program_name, program_name, 0 ); -} - -//____________________________________________________________________________// - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE parser::param_iterator -parser::first_param() const -{ - return m_parameters.begin(); -} - -//____________________________________________________________________________// - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE parser::param_iterator -parser::last_param() const -{ - return m_parameters.end(); -} - -//____________________________________________________________________________// - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE argument const& -parser::valid_argument( cstring string_id ) const -{ - const_argument_ptr arg = (*this)[string_id]; - - BOOST_TEST_UTILS_RUNTIME_PARAM_VALIDATE_LOGIC( !!arg, "Actual argument for parameter " << string_id << " is not present" ); - - return *arg; -} - -//____________________________________________________________________________// - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE parser& -parser::operator<<( parameter_ptr new_param ) -{ - BOOST_TEST_FOREACH( parameter_ptr, old_param, m_parameters ) { - BOOST_TEST_UTILS_RUNTIME_PARAM_VALIDATE_LOGIC( !old_param->conflict_with( *new_param ), - BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( "Definition of parameter " ) << new_param->id_2_report() << - BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( " conflicts with defintion of parameter " ) << old_param->id_2_report() ); - } - - m_parameters.push_back( new_param ); - - return *this; -} - -//____________________________________________________________________________// - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE void -parser::parse( int& argc, char_type** argv ) -{ - if( m_program_name.empty() ) { - m_program_name.assign( argv[0] ); - dstring::size_type pos = m_program_name.find_last_of( BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( "/\\" ) ); - - if( pos != static_cast<dstring::size_type>(cstring::npos) ) - m_program_name.erase( 0, pos+1 ); - } - - m_traverser.init( argc, argv ); - - BOOST_TEST_IMPL_TRY { - while( !m_traverser.eoi() ) { - parameter_ptr found_param; - - BOOST_TEST_UTILS_RUNTIME_PARAM_TRACE( "Total " << m_parameters.size() << " parameters registered" ); - - BOOST_TEST_FOREACH( parameter_ptr const&, curr_param, m_parameters ) { - BOOST_TEST_UTILS_RUNTIME_PARAM_TRACE( "Try parameter " << curr_param->id_2_report() ); - - if( curr_param->matching( m_traverser, !found_param ) ) { - BOOST_TEST_UTILS_RUNTIME_PARAM_TRACE( "Match found" ); - BOOST_TEST_UTILS_RUNTIME_CLA_VALIDATE_INPUT( !found_param, (m_traverser.rollback(),m_traverser), "Ambiguous input" ); - - found_param = curr_param; - } - - m_traverser.rollback(); - } - - if( !found_param ) { - BOOST_TEST_UTILS_RUNTIME_PARAM_TRACE( "No match found" ); - BOOST_TEST_UTILS_RUNTIME_CLA_VALIDATE_INPUT( m_traverser.handle_mismatch(), m_traverser, - BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( "Unexpected input" ) ); - - continue; - } - - BOOST_TEST_UTILS_RUNTIME_PARAM_TRACE( "Parse argument value" ); - found_param->produce_argument( m_traverser ); - - m_traverser.commit(); - } - - BOOST_TEST_FOREACH( parameter_ptr const&, curr_param, m_parameters ) { - if( !curr_param->p_optional && !curr_param->actual_argument() ) { - curr_param->produce_argument( *this ); - - BOOST_TEST_UTILS_RUNTIME_PARAM_VALIDATE_LOGIC( curr_param->actual_argument(), - BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( "Required argument for parameter " ) << curr_param->id_2_report() - << BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( " is missing" ) ); - } - } - } - BOOST_TEST_IMPL_CATCH0( bad_lexical_cast ) { - BOOST_TEST_UTILS_RUNTIME_PARAM_REPORT_LOGIC_ERROR( - BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( "String to value convertion error during input parsing" ) ); - }; - - m_traverser.remainder( argc, argv ); -} - -//____________________________________________________________________________// - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE const_argument_ptr -parser::operator[]( cstring string_id ) const -{ - parameter_ptr found_param; - - BOOST_TEST_FOREACH( parameter_ptr const&, curr_param, m_parameters ) { - if( curr_param->responds_to( string_id ) ) { - BOOST_TEST_UTILS_RUNTIME_PARAM_VALIDATE_LOGIC( !found_param, - BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( "Ambiguous parameter string id: " ) << string_id ); - - found_param = curr_param; - } - } - - return found_param ? found_param->actual_argument() : argument_ptr(); -} - -//____________________________________________________________________________// - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE cstring -parser::get( cstring string_id ) const -{ - return get<cstring>( string_id ); -} - -//____________________________________________________________________________// - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE void -parser::usage( out_stream& ostr ) -{ - if( m_program_name.empty() ) - assign_op( m_program_name, BOOST_TEST_UTILS_RUNTIME_PARAM_CSTRING_LITERAL( "<program>" ), 0 ); - - format_stream fs; - - fs << m_program_name; - - BOOST_TEST_FOREACH( parameter_ptr const&, curr_param, m_parameters ) { - fs << BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( ' ' ); - - if( curr_param->p_optional ) - fs << BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( '[' ); - - curr_param->usage_info( fs ); - - if( curr_param->p_optional ) - fs << BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( ']' ); - - if( curr_param->p_multiplicable ) { - fs << BOOST_TEST_UTILS_RUNTIME_PARAM_CSTRING_LITERAL( " ... " ); - - if( curr_param->p_optional ) - fs << BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( '[' ); - - curr_param->usage_info( fs ); - - if( curr_param->p_optional ) - fs << BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( ']' ); - } - } - - ostr << BOOST_TEST_UTILS_RUNTIME_PARAM_CSTRING_LITERAL( "Usage:\n" ) << fs.str() << std::endl; -} - -//____________________________________________________________________________// - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE void -parser::help( out_stream& ostr ) -{ - usage( ostr ); - - bool need_where = true; - - BOOST_TEST_FOREACH( parameter_ptr const&, curr_param, m_parameters ) { - if( curr_param->p_description->empty() ) - continue; - - if( need_where ) { - ostr << BOOST_TEST_UTILS_RUNTIME_PARAM_CSTRING_LITERAL( "where:\n" ); - need_where = false; - } - - ostr << curr_param->id_2_report() << BOOST_TEST_UTILS_RUNTIME_PARAM_CSTRING_LITERAL( " - " ) << curr_param->p_description << std::endl; - } -} - -//____________________________________________________________________________// - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE void -parser::reset() -{ - BOOST_TEST_FOREACH( parameter_ptr const&, param, m_parameters ) - param->reset(); -} - -//____________________________________________________________________________// - -} // namespace cla - -} // namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE - -} // namespace boost - -#endif // BOOST_TEST_UTILS_RUNTIME_CLA_PARSER_IPP diff --git a/boost/test/utils/runtime/cla/positional_parameter.hpp b/boost/test/utils/runtime/cla/positional_parameter.hpp deleted file mode 100644 index f378743dd5..0000000000 --- a/boost/test/utils/runtime/cla/positional_parameter.hpp +++ /dev/null @@ -1,91 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. -// Use, modification, and distribution are subject to the -// Boost Software License, Version 1.0. (See accompanying file -// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - -// See http://www.boost.org/libs/test for the library home page. -// -// File : $RCSfile$ -// -// Version : $Revision$ -// -// Description : positional parameter model -// *************************************************************************** - -#ifndef BOOST_TEST_UTILS_RUNTIME_CLA_POSITIONAL_PARAMETER_HPP -#define BOOST_TEST_UTILS_RUNTIME_CLA_POSITIONAL_PARAMETER_HPP - -// Boost.Runtime.Parameter -#include <boost/test/utils/runtime/config.hpp> - -#include <boost/test/utils/runtime/cla/basic_parameter.hpp> - -namespace boost { - -namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE { - -namespace cla { - -// ************************************************************************** // -// ************** trivial_id_policy ************** // -// ************************************************************************** // - -class trivial_id_policy : public identification_policy { -public: - trivial_id_policy() - : identification_policy( rtti::type_id<trivial_id_policy>() ) - {} - BOOST_TEST_UTILS_RUNTIME_PARAM_UNNEEDED_VIRTUAL ~trivial_id_policy() {} - - virtual bool responds_to( cstring name ) const { return m_name == name; } - virtual bool conflict_with( identification_policy const& ) const { return false; } - virtual cstring id_2_report() const { return m_name; } - virtual void usage_info( format_stream& fs ) const - { - if( !m_name.empty() ) - fs << BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( '<' ) << m_name << BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( '>' ); - else - fs << BOOST_TEST_UTILS_RUNTIME_PARAM_CSTRING_LITERAL( "<value>" ); - } - - virtual bool matching( parameter const& p, argv_traverser&, bool primary ) const - { - return primary && ( !p.has_argument() || p.p_multiplicable ); - } - - template<typename Modifier> - void accept_modifier( Modifier const& m ) - { - nfp::optionally_assign( m_name, m, name ); - } - -private: - // Data members - dstring m_name; -}; - -// ************************************************************************** // -// ************** runtime::cla::positional_parameter ************** // -// ************************************************************************** // - -template<typename T> -class positional_parameter_t : public basic_parameter<T,trivial_id_policy> { - typedef basic_parameter<T,trivial_id_policy> base; -public: - // Constructors - explicit positional_parameter_t( cstring name ) - : base( name ) - {} -}; - -//____________________________________________________________________________// - -BOOST_TEST_UTILS_RUNTIME_CLA_NAMED_PARAM_GENERATORS( positional_parameter ) - -} // namespace cla - -} // namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE - -} // namespace boost - -#endif // BOOST_TEST_UTILS_RUNTIME_CLA_POSITIONAL_PARAMETER_HPP diff --git a/boost/test/utils/runtime/cla/typed_parameter.hpp b/boost/test/utils/runtime/cla/typed_parameter.hpp deleted file mode 100644 index 70c5bbc009..0000000000 --- a/boost/test/utils/runtime/cla/typed_parameter.hpp +++ /dev/null @@ -1,70 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. -// Use, modification, and distribution are subject to the -// Boost Software License, Version 1.0. (See accompanying file -// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - -// See http://www.boost.org/libs/test for the library home page. -// -// File : $RCSfile$ -// -// Version : $Revision$ -// -// Description : generic typed parameter model -// *************************************************************************** - -#ifndef BOOST_TEST_UTILS_RUNTIME_CLA_TYPED_PARAMETER_HPP -#define BOOST_TEST_UTILS_RUNTIME_CLA_TYPED_PARAMETER_HPP - -// Boost.Runtime.Parameter -#include <boost/test/utils/runtime/config.hpp> - -#include <boost/test/utils/runtime/fwd.hpp> -#include <boost/test/utils/runtime/validation.hpp> - -#include <boost/test/utils/runtime/cla/parameter.hpp> -#include <boost/test/utils/runtime/cla/argument_factory.hpp> - -// Boost.Test -#include <boost/test/utils/rtti.hpp> - -namespace boost { - -namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE { - -namespace cla { - -// ************************************************************************** // -// ************** runtime::cla::typed_parameter ************** // -// ************************************************************************** // - -template<typename T> -class typed_parameter : public cla::parameter { -public: - explicit typed_parameter( identification_policy& ID ) - : cla::parameter( ID, m_arg_factory, rtti::type_id<T>() == rtti::type_id<bool>() ) - {} - - // parameter properties modification - template<typename Modifier> - void accept_modifier( Modifier const& m ) - { - cla::parameter::accept_modifier( m ); - - m_arg_factory.accept_modifier( m ); - - BOOST_TEST_UTILS_RUNTIME_PARAM_VALIDATE_LOGIC( !p_optional || !m_arg_factory.m_value_generator, - BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( "can't define a value generator for optional parameter " ) << id_2_report() ); - } - -private: - // Data members - typed_argument_factory<T> m_arg_factory; -}; - -} // namespace cla - -} // namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE - -} // namespace boost - -#endif // BOOST_TEST_UTILS_RUNTIME_CLA_TYPED_PARAMETER_HPP diff --git a/boost/test/utils/runtime/cla/validation.cpp b/boost/test/utils/runtime/cla/validation.cpp deleted file mode 100644 index 7f19a5ca45..0000000000 --- a/boost/test/utils/runtime/cla/validation.cpp +++ /dev/null @@ -1,16 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. -// Use, modification, and distribution are subject to the -// Boost Software License, Version 1.0. (See accompanying file -// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - -// See http://www.boost.org/libs/test for the library home page. -// -// File : $RCSfile$ -// -// Version : $Revision$ -// -// Description : input validation helpers offline implementation -// *************************************************************************** - -#define BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE -#include <boost/test/utils/runtime/cla/validation.ipp> diff --git a/boost/test/utils/runtime/cla/validation.hpp b/boost/test/utils/runtime/cla/validation.hpp deleted file mode 100644 index 8a3da14c5b..0000000000 --- a/boost/test/utils/runtime/cla/validation.hpp +++ /dev/null @@ -1,57 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. -// Use, modification, and distribution are subject to the -// Boost Software License, Version 1.0. (See accompanying file -// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - -// See http://www.boost.org/libs/test for the library home page. -// -// File : $RCSfile$ -// -// Version : $Revision$ -// -// Description : input validation helpers definition -// *************************************************************************** - -#ifndef BOOST_TEST_UTILS_RUNTIME_CLA_VALIDATION_HPP -#define BOOST_TEST_UTILS_RUNTIME_CLA_VALIDATION_HPP - -// Boost.Runtime.Parameter -#include <boost/test/utils/runtime/config.hpp> - -#include <boost/test/utils/runtime/cla/fwd.hpp> - -namespace boost { - -namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE { - -namespace cla { - -// ************************************************************************** // -// ************** runtime::cla::report_input_error ************** // -// ************************************************************************** // - -void report_input_error( argv_traverser const& tr, format_stream& msg ); - -//____________________________________________________________________________// - -#define BOOST_TEST_UTILS_RUNTIME_CLA_VALIDATE_INPUT( b, tr, msg ) \ - if( b ) ; else ::boost::BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE::cla::report_input_error( tr, format_stream().ref() << msg ) - -//____________________________________________________________________________// - -} // namespace cla - -} // namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE - -} // namespace boost - -#ifndef BOOST_TEST_UTILS_RUNTIME_PARAM_OFFLINE - -#ifndef BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE -# define BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE inline -#endif -# include <boost/test/utils/runtime/cla/validation.ipp> - -#endif - -#endif // BOOST_TEST_UTILS_RUNTIME_CLA_VALIDATION_HPP diff --git a/boost/test/utils/runtime/cla/validation.ipp b/boost/test/utils/runtime/cla/validation.ipp deleted file mode 100644 index 9d8cd27b4a..0000000000 --- a/boost/test/utils/runtime/cla/validation.ipp +++ /dev/null @@ -1,61 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. -// Use, modification, and distribution are subject to the -// Boost Software License, Version 1.0. (See accompanying file -// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - -// See http://www.boost.org/libs/test for the library home page. -// -//! @file -//! @brief Input validation helpers implementation -// *************************************************************************** - -#ifndef BOOST_TEST_UTILS_RUNTIME_CLA_VALIDATION_IPP -#define BOOST_TEST_UTILS_RUNTIME_CLA_VALIDATION_IPP - -// Boost.Runtime.Parameter -#include <boost/test/utils/runtime/config.hpp> - -#include <boost/test/utils/runtime/cla/argv_traverser.hpp> -#include <boost/test/utils/runtime/cla/validation.hpp> -#include <boost/test/utils/runtime/validation.hpp> // BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE::logic_error - -// Boost.Test -#include <boost/test/utils/basic_cstring/io.hpp> -#include <boost/test/detail/throw_exception.hpp> - -namespace boost { - -namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE { - -namespace cla { - -// ************************************************************************** // -// ************** runtime::cla::validation ************** // -// ************************************************************************** // - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE void -report_input_error( argv_traverser const& tr, format_stream& msg ) -{ - if( tr.eoi() ) - msg << BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( " at the end of input" ); - else { - msg << BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( " in the following position: " ); - - if( tr.input().size() > 5 ) - msg << tr.input().substr( 0, 5 ) << BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( "..." ); - else - msg << tr.input(); - } - - BOOST_TEST_IMPL_THROW( BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE::logic_error( msg.str() ) ); -} - -//____________________________________________________________________________// - -} // namespace cla - -} // namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE - -} // namespace boost - -#endif // BOOST_TEST_UTILS_RUNTIME_CLA_VALIDATION_IPP diff --git a/boost/test/utils/runtime/cla/value_generator.hpp b/boost/test/utils/runtime/cla/value_generator.hpp deleted file mode 100644 index 0efc25def1..0000000000 --- a/boost/test/utils/runtime/cla/value_generator.hpp +++ /dev/null @@ -1,81 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. -// Use, modification, and distribution are subject to the -// Boost Software License, Version 1.0. (See accompanying file -// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - -// See http://www.boost.org/libs/test for the library home page. -// -// File : $RCSfile$ -// -// Version : $Revision$ -// -// Description : specific value generators -// *************************************************************************** - -#ifndef BOOST_TEST_UTILS_RUNTIME_CLA_VALUE_GENERATOR_HPP -#define BOOST_TEST_UTILS_RUNTIME_CLA_VALUE_GENERATOR_HPP - -// Boost.Runtime.Parameter -#include <boost/test/utils/runtime/config.hpp> - -#include <boost/test/utils/runtime/cla/fwd.hpp> -#include <boost/test/utils/runtime/cla/parser.hpp> - -namespace boost { - -namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE { - -namespace cla { - -namespace rt_cla_detail { - -// ************************************************************************** // -// ************** runtime::cla::const_generator ************** // -// ************************************************************************** // - -template<typename T> -class const_generator { -public: - // Constructor - explicit const_generator( T const& t ) : m_const_value( t ) {} - - // generator interface - void operator()( parser const&, boost::optional<T>& t ) const { t = m_const_value; } - -private: - // Data members - T m_const_value; -}; - -// ************************************************************************** // -// ************** runtime::cla::ref_generator ************** // -// ************************************************************************** // - -template<typename T> -class ref_generator { -public: - // Constructor - explicit ref_generator( cstring ref_id ) : m_ref_id( ref_id ) {} - - // generator interface - void operator()( parser const& p, boost::optional<T>& t ) const - { - p.get( m_ref_id, t ); - } - -private: - // Data members - cstring m_ref_id; -}; - -//____________________________________________________________________________// - -} // namespace rt_cla_detail - -} // namespace cla - -} // namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE - -} // namespace boost - -#endif // BOOST_TEST_UTILS_RUNTIME_CLA_VALUE_GENERATOR_HPP diff --git a/boost/test/utils/runtime/cla/value_handler.hpp b/boost/test/utils/runtime/cla/value_handler.hpp deleted file mode 100644 index 38792602ac..0000000000 --- a/boost/test/utils/runtime/cla/value_handler.hpp +++ /dev/null @@ -1,57 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. -// Use, modification, and distribution are subject to the -// Boost Software License, Version 1.0. (See accompanying file -// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - -// See http://www.boost.org/libs/test for the library home page. -// -// File : $RCSfile$ -// -// Version : $Revision$ -// -// Description : specific value handlers -// *************************************************************************** - -#ifndef BOOST_TEST_UTILS_RUNTIME_CLA_VALUE_HANDLER_HPP -#define BOOST_TEST_UTILS_RUNTIME_CLA_VALUE_HANDLER_HPP - -// Boost.Runtime.Parameter -#include <boost/test/utils/runtime/config.hpp> - -#include <boost/test/utils/runtime/cla/fwd.hpp> - -namespace boost { - -namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE { - -namespace cla { - -namespace rt_cla_detail { - -// ************************************************************************** // -// ************** runtime::cla::assigner ************** // -// ************************************************************************** // - -template<typename T> -class assigner { -public: - // Constructor - explicit assigner( T& loc ) : m_target( loc ) {} - - // value handler implementation - void operator()( parameter const&, T& t ) { m_target = t; } - -private: - // Data members - T& m_target; -}; - -} // namespace rt_cla_detail - -} // namespace cla - -} // namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE - -} // namespace boost - -#endif // BOOST_TEST_UTILS_RUNTIME_CLA_VALUE_HANDLER_HPP |