// (C) Copyright Gennadiy Rozental 2001. // 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 : model of actual argument (both typed and abstract interface) // *************************************************************************** #ifndef BOOST_TEST_UTILS_RUNTIME_ARGUMENT_HPP #define BOOST_TEST_UTILS_RUNTIME_ARGUMENT_HPP // Boost.Test Runtime parameters #include #include // Boost.Test #include #include #include #include // STL #include #include namespace boost { namespace runtime { // ************************************************************************** // // ************** runtime::argument ************** // // ************************************************************************** // class argument { public: // Constructor argument( rtti::id_t value_type ) : p_value_type( value_type ) {} // Destructor virtual ~argument() {} // Public properties rtti::id_t const p_value_type; }; // ************************************************************************** // // ************** runtime::typed_argument ************** // // ************************************************************************** // template class typed_argument : public argument { public: // Constructor explicit typed_argument( T const& v ) : argument( rtti::type_id() ) , p_value( v ) {} unit_test::readwrite_property p_value; }; // ************************************************************************** // // ************** runtime::arguments_store ************** // // ************************************************************************** // class arguments_store { public: typedef std::map storage_type; /// Returns number of arguments in the store; mostly used for testing std::size_t size() const { return m_arguments.size(); } /// Clears the store for reuse void clear() { m_arguments.clear(); } /// Returns true if there is an argument corresponding to the specified parameter name bool has( cstring parameter_name ) const { return m_arguments.find( parameter_name ) != m_arguments.end(); } /// Provides types access to argument value by parameter name template T const& get( cstring parameter_name ) const { return const_cast(this)->get( parameter_name ); } template T& get( cstring parameter_name ) { storage_type::const_iterator found = m_arguments.find( parameter_name ); BOOST_TEST_I_ASSRT( found != m_arguments.end(), access_to_missing_argument() << "There is no argument provided for parameter " << parameter_name ); argument_ptr arg = found->second; BOOST_TEST_I_ASSRT( arg->p_value_type == rtti::type_id(), arg_type_mismatch() << "Access with invalid type for argument corresponding to parameter " << parameter_name ); return static_cast&>( *arg ).p_value.value; } /// Set's the argument value for specified parameter name template void set( cstring parameter_name, T const& value ) { m_arguments[parameter_name] = argument_ptr( new typed_argument( value ) ); } private: // Data members storage_type m_arguments; }; } // namespace runtime } // namespace boost #include #endif // BOOST_TEST_UTILS_RUNTIME_ARGUMENT_HPP