Home | History | Annotate | Download | only in runtime
      1 //  (C) Copyright Gennadiy Rozental 2005-2008.
      2 //  Distributed under the Boost Software License, Version 1.0.
      3 //  (See accompanying file LICENSE_1_0.txt or copy at
      4 //  http://www.boost.org/LICENSE_1_0.txt)
      5 
      6 //  See http://www.boost.org/libs/test for the library home page.
      7 //
      8 //  File        : $RCSfile$
      9 //
     10 //  Version     : $Revision: 57992 $
     11 //
     12 //  Description : model of actual argument (both typed and abstract interface)
     13 // ***************************************************************************
     14 
     15 #ifndef BOOST_RT_ARGUMENT_HPP_062604GER
     16 #define BOOST_RT_ARGUMENT_HPP_062604GER
     17 
     18 // Boost.Runtime.Parameter
     19 #include <boost/test/utils/runtime/config.hpp>
     20 #include <boost/test/utils/runtime/fwd.hpp>
     21 #include <boost/test/utils/runtime/validation.hpp>
     22 
     23 // Boost.Test
     24 #include <boost/test/utils/class_properties.hpp>
     25 #include <boost/test/utils/rtti.hpp>
     26 
     27 // STL
     28 #include <cassert>
     29 
     30 namespace boost {
     31 
     32 namespace BOOST_RT_PARAM_NAMESPACE {
     33 
     34 // ************************************************************************** //
     35 // **************              runtime::argument               ************** //
     36 // ************************************************************************** //
     37 
     38 #ifdef BOOST_MSVC
     39 #  pragma warning(push)
     40 #  pragma warning(disable:4244)
     41 #endif
     42 
     43 class argument {
     44 public:
     45     // Constructor
     46     argument( parameter const& p, rtti::id_t value_type )
     47     : p_formal_parameter( p )
     48     , p_value_type( value_type )
     49     {}
     50 
     51     // Destructor
     52     virtual     ~argument()  {}
     53 
     54     // Public properties
     55     unit_test::readonly_property<parameter const&> p_formal_parameter;
     56     unit_test::readonly_property<rtti::id_t>       p_value_type;
     57 };
     58 
     59 // ************************************************************************** //
     60 // **************             runtime::typed_argument          ************** //
     61 // ************************************************************************** //
     62 
     63 template<typename T>
     64 class typed_argument : public argument {
     65 public:
     66     // Constructor
     67     explicit typed_argument( parameter const& p )
     68     : argument( p, rtti::type_id<T>() )
     69     {}
     70     typed_argument( parameter const& p, T const& t )
     71     : argument( p, rtti::type_id<T>() )
     72     , p_value( t )
     73     {}
     74 
     75     unit_test::readwrite_property<T>    p_value;
     76 };
     77 
     78 // ************************************************************************** //
     79 // **************               runtime::arg_value             ************** //
     80 // ************************************************************************** //
     81 
     82 template<typename T>
     83 inline T const&
     84 arg_value( argument const& arg_ )
     85 {
     86     assert( arg_.p_value_type == rtti::type_id<T>() ); // detect logic error
     87 
     88     return static_cast<typed_argument<T> const&>( arg_ ).p_value.value;
     89 }
     90 
     91 //____________________________________________________________________________//
     92 
     93 template<typename T>
     94 inline T&
     95 arg_value( argument& arg_ )
     96 {
     97     assert( arg_.p_value_type == rtti::type_id<T>() ); // detect logic error
     98 
     99     return static_cast<typed_argument<T>&>( arg_ ).p_value.value;
    100 }
    101 
    102 #ifdef BOOST_MSVC
    103 #  pragma warning(pop)
    104 #endif
    105 
    106 //____________________________________________________________________________//
    107 
    108 } // namespace BOOST_RT_PARAM_NAMESPACE
    109 
    110 } // namespace boost
    111 
    112 #endif // BOOST_RT_ARGUMENT_HPP_062604GER
    113