blob: fa2b29db83ea67d8d7cd1db9c3a7be3c1748cfa3 [file] [log] [blame]
Jeff Thompsonef2d5a42013-08-22 19:09:24 -07001// (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 Thompson3d613fd2013-10-15 15:39:04 -070015#ifndef NDNBOOST_RT_ARGUMENT_HPP_062604GER
16#define NDNBOOST_RT_ARGUMENT_HPP_062604GER
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070017
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
30namespace ndnboost {
31
Jeff Thompson3d613fd2013-10-15 15:39:04 -070032namespace NDNBOOST_RT_PARAM_NAMESPACE {
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070033
34// ************************************************************************** //
35// ************** runtime::argument ************** //
36// ************************************************************************** //
37
Jeff Thompson3d613fd2013-10-15 15:39:04 -070038#ifdef NDNBOOST_MSVC
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070039# pragma warning(push)
40# pragma warning(disable:4244)
41#endif
42
43class argument {
44public:
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
63template<typename T>
64class typed_argument : public argument {
65public:
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
82template<typename T>
83inline T const&
84arg_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
93template<typename T>
94inline T&
95arg_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 Thompson3d613fd2013-10-15 15:39:04 -0700102#ifdef NDNBOOST_MSVC
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700103# pragma warning(pop)
104#endif
105
106//____________________________________________________________________________//
107
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700108} // namespace NDNBOOST_RT_PARAM_NAMESPACE
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700109
110} // namespace ndnboost
111
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700112#endif // NDNBOOST_RT_ARGUMENT_HPP_062604GER