Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 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 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 15 | #ifndef NDNBOOST_RT_ARGUMENT_HPP_062604GER |
| 16 | #define NDNBOOST_RT_ARGUMENT_HPP_062604GER |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 17 | |
| 18 | // Boost.Runtime.Parameter |
| 19 | #include <ndnboost/test/utils/runtime/config.hpp> |
| 20 | #include <ndnboost/test/utils/runtime/fwd.hpp> |
| 21 | #include <ndnboost/test/utils/runtime/validation.hpp> |
| 22 | |
| 23 | // Boost.Test |
| 24 | #include <ndnboost/test/utils/class_properties.hpp> |
| 25 | #include <ndnboost/test/utils/rtti.hpp> |
| 26 | |
| 27 | // STL |
| 28 | #include <cassert> |
| 29 | |
| 30 | namespace ndnboost { |
| 31 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 32 | namespace NDNBOOST_RT_PARAM_NAMESPACE { |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 33 | |
| 34 | // ************************************************************************** // |
| 35 | // ************** runtime::argument ************** // |
| 36 | // ************************************************************************** // |
| 37 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 38 | #ifdef NDNBOOST_MSVC |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 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 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 102 | #ifdef NDNBOOST_MSVC |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 103 | # pragma warning(pop) |
| 104 | #endif |
| 105 | |
| 106 | //____________________________________________________________________________// |
| 107 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 108 | } // namespace NDNBOOST_RT_PARAM_NAMESPACE |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 109 | |
| 110 | } // namespace ndnboost |
| 111 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 112 | #endif // NDNBOOST_RT_ARGUMENT_HPP_062604GER |