1 // (C) Copyright Gennadiy Rozental 2001.
2 // Distributed under the Boost Software License, Version 1.0.
3 // (See accompanying file LICENSE_1_0.txt or copy at
4 // http://www.boost.org/LICENSE_1_0.txt)
6 // See http://www.boost.org/libs/test for the library home page.
10 // Version : $Revision$
12 // Description : model of actual argument (both typed and abstract interface)
13 // ***************************************************************************
15 #ifndef BOOST_TEST_UTILS_RUNTIME_ARGUMENT_HPP
16 #define BOOST_TEST_UTILS_RUNTIME_ARGUMENT_HPP
18 // Boost.Test Runtime parameters
19 #include <boost/test/utils/runtime/fwd.hpp>
20 #include <boost/test/utils/runtime/errors.hpp>
23 #include <boost/test/utils/class_properties.hpp>
24 #include <boost/test/utils/rtti.hpp>
25 #include <boost/test/utils/basic_cstring/compare.hpp>
26 #include <boost/test/detail/throw_exception.hpp>
31 #include <boost/test/detail/suppress_warnings.hpp>
36 // ************************************************************************** //
37 // ************** runtime::argument ************** //
38 // ************************************************************************** //
43 argument( rtti::id_t value_type )
44 : p_value_type( value_type )
48 virtual ~argument() {}
51 rtti::id_t const p_value_type;
54 // ************************************************************************** //
55 // ************** runtime::typed_argument ************** //
56 // ************************************************************************** //
59 class typed_argument : public argument {
62 explicit typed_argument( T const& v )
63 : argument( rtti::type_id<T>() )
67 unit_test::readwrite_property<T> p_value;
70 // ************************************************************************** //
71 // ************** runtime::arguments_store ************** //
72 // ************************************************************************** //
74 class arguments_store {
76 typedef std::map<cstring, argument_ptr> storage_type;
78 /// Returns number of arguments in the store; mostly used for testing
79 std::size_t size() const { return m_arguments.size(); }
81 /// Clears the store for reuse
82 void clear() { m_arguments.clear(); }
84 /// Returns true if there is an argument corresponding to the specified parameter name
85 bool has( cstring parameter_name ) const
87 return m_arguments.find( parameter_name ) != m_arguments.end();
90 /// Provides types access to argument value by parameter name
92 T const& get( cstring parameter_name ) const {
93 return const_cast<arguments_store*>(this)->get<T>( parameter_name );
97 T& get( cstring parameter_name ) {
98 storage_type::const_iterator found = m_arguments.find( parameter_name );
99 BOOST_TEST_I_ASSRT( found != m_arguments.end(),
100 access_to_missing_argument()
101 << "There is no argument provided for parameter "
104 argument_ptr arg = found->second;
106 BOOST_TEST_I_ASSRT( arg->p_value_type == rtti::type_id<T>(),
108 << "Access with invalid type for argument corresponding to parameter "
111 return static_cast<typed_argument<T>&>( *arg ).p_value.value;
114 /// Set's the argument value for specified parameter name
116 void set( cstring parameter_name, T const& value )
118 m_arguments[parameter_name] = argument_ptr( new typed_argument<T>( value ) );
123 storage_type m_arguments;
126 } // namespace runtime
129 #include <boost/test/detail/enable_warnings.hpp>
131 #endif // BOOST_TEST_UTILS_RUNTIME_ARGUMENT_HPP