File indexing completed on 2025-01-18 09:52:42
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #ifndef BOOST_TEST_UTILS_RUNTIME_ARGUMENT_HPP
0016 #define BOOST_TEST_UTILS_RUNTIME_ARGUMENT_HPP
0017
0018
0019 #include <boost/test/utils/runtime/fwd.hpp>
0020 #include <boost/test/utils/runtime/errors.hpp>
0021
0022
0023 #include <boost/test/utils/class_properties.hpp>
0024 #include <boost/test/utils/rtti.hpp>
0025 #include <boost/test/utils/basic_cstring/compare.hpp>
0026 #include <boost/test/detail/throw_exception.hpp>
0027
0028
0029 #include <cassert>
0030
0031 #include <boost/test/detail/suppress_warnings.hpp>
0032
0033 namespace boost {
0034 namespace runtime {
0035
0036
0037
0038
0039
0040 class argument {
0041 public:
0042
0043 argument( rtti::id_t value_type )
0044 : p_value_type( value_type )
0045 {}
0046
0047
0048 virtual ~argument() {}
0049
0050
0051 rtti::id_t const p_value_type;
0052 };
0053
0054
0055
0056
0057
0058 template<typename T>
0059 class typed_argument : public argument {
0060 public:
0061
0062 explicit typed_argument( T const& v )
0063 : argument( rtti::type_id<T>() )
0064 , p_value( v )
0065 {}
0066
0067 unit_test::readwrite_property<T> p_value;
0068 };
0069
0070
0071
0072
0073
0074 class arguments_store {
0075 public:
0076 typedef std::map<cstring, argument_ptr> storage_type;
0077
0078
0079 std::size_t size() const { return m_arguments.size(); }
0080
0081
0082 void clear() { m_arguments.clear(); }
0083
0084
0085 bool has( cstring parameter_name ) const
0086 {
0087 return m_arguments.find( parameter_name ) != m_arguments.end();
0088 }
0089
0090
0091 template<typename T>
0092 T const& get( cstring parameter_name ) const {
0093 return const_cast<arguments_store*>(this)->get<T>( parameter_name );
0094 }
0095
0096 template<typename T>
0097 T& get( cstring parameter_name ) {
0098 storage_type::const_iterator found = m_arguments.find( parameter_name );
0099 BOOST_TEST_I_ASSRT( found != m_arguments.end(),
0100 access_to_missing_argument()
0101 << "There is no argument provided for parameter "
0102 << parameter_name );
0103
0104 argument_ptr arg = found->second;
0105
0106 BOOST_TEST_I_ASSRT( arg->p_value_type == rtti::type_id<T>(),
0107 arg_type_mismatch()
0108 << "Access with invalid type for argument corresponding to parameter "
0109 << parameter_name );
0110
0111 return static_cast<typed_argument<T>&>( *arg ).p_value.value;
0112 }
0113
0114
0115 template<typename T>
0116 void set( cstring parameter_name, T const& value )
0117 {
0118 m_arguments[parameter_name] = argument_ptr( new typed_argument<T>( value ) );
0119 }
0120
0121 private:
0122
0123 storage_type m_arguments;
0124 };
0125
0126 }
0127 }
0128
0129 #include <boost/test/detail/enable_warnings.hpp>
0130
0131 #endif