argument.hpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. // See http://www.boost.org/libs/test for the library home page.
  6. //
  7. // File : $RCSfile$
  8. //
  9. // Version : $Revision: 57992 $
  10. //
  11. // Description : model of actual argument (both typed and abstract interface)
  12. // ***************************************************************************
  13. #ifndef BOOST_RT_ARGUMENT_HPP_062604GER
  14. #define BOOST_RT_ARGUMENT_HPP_062604GER
  15. // Boost.Runtime.Parameter
  16. #include <boost/test/utils/runtime/config.hpp>
  17. #include <boost/test/utils/runtime/fwd.hpp>
  18. #include <boost/test/utils/runtime/validation.hpp>
  19. // Boost.Test
  20. #include <boost/test/utils/class_properties.hpp>
  21. #include <boost/test/utils/rtti.hpp>
  22. // STL
  23. #include <cassert>
  24. namespace boost {
  25. namespace BOOST_RT_PARAM_NAMESPACE {
  26. // ************************************************************************** //
  27. // ************** runtime::argument ************** //
  28. // ************************************************************************** //
  29. #ifdef BOOST_MSVC
  30. # pragma warning(push)
  31. # pragma warning(disable:4244)
  32. #endif
  33. class argument {
  34. public:
  35. // Constructor
  36. argument( parameter const& p, rtti::id_t value_type )
  37. : p_formal_parameter( p )
  38. , p_value_type( value_type )
  39. {}
  40. // Destructor
  41. virtual ~argument() {}
  42. // Public properties
  43. unit_test::readonly_property<parameter const&> p_formal_parameter;
  44. unit_test::readonly_property<rtti::id_t> p_value_type;
  45. };
  46. // ************************************************************************** //
  47. // ************** runtime::typed_argument ************** //
  48. // ************************************************************************** //
  49. template<typename T>
  50. class typed_argument : public argument {
  51. public:
  52. // Constructor
  53. explicit typed_argument( parameter const& p )
  54. : argument( p, rtti::type_id<T>() )
  55. {}
  56. typed_argument( parameter const& p, T const& t )
  57. : argument( p, rtti::type_id<T>() )
  58. , p_value( t )
  59. {}
  60. unit_test::readwrite_property<T> p_value;
  61. };
  62. // ************************************************************************** //
  63. // ************** runtime::arg_value ************** //
  64. // ************************************************************************** //
  65. template<typename T>
  66. inline T const&
  67. arg_value( argument const& arg_ )
  68. {
  69. assert( arg_.p_value_type == rtti::type_id<T>() ); // detect logic error
  70. return static_cast<typed_argument<T> const&>( arg_ ).p_value.value;
  71. }
  72. //____________________________________________________________________________//
  73. template<typename T>
  74. inline T&
  75. arg_value( argument& arg_ )
  76. {
  77. assert( arg_.p_value_type == rtti::type_id<T>() ); // detect logic error
  78. return static_cast<typed_argument<T>&>( arg_ ).p_value.value;
  79. }
  80. #ifdef BOOST_MSVC
  81. # pragma warning(pop)
  82. #endif
  83. //____________________________________________________________________________//
  84. } // namespace BOOST_RT_PARAM_NAMESPACE
  85. } // namespace boost
  86. #endif // BOOST_RT_ARGUMENT_HPP_062604GER