1 | // (C) Copyright Gennadiy Rozental 2005. |
---|
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: argument.hpp,v $ |
---|
9 | // |
---|
10 | // Version : $Revision: 1.2 $ |
---|
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 | class argument { |
---|
39 | public: |
---|
40 | // Constructor |
---|
41 | argument( parameter const& p, rtti::id_t value_type ) |
---|
42 | : p_formal_parameter( p ) |
---|
43 | , p_value_type( value_type ) |
---|
44 | {} |
---|
45 | |
---|
46 | // Destructor |
---|
47 | virtual ~argument() {} |
---|
48 | |
---|
49 | // Public properties |
---|
50 | unit_test::readonly_property<parameter const&> p_formal_parameter; |
---|
51 | unit_test::readonly_property<rtti::id_t> p_value_type; |
---|
52 | }; |
---|
53 | |
---|
54 | // ************************************************************************** // |
---|
55 | // ************** runtime::typed_argument ************** // |
---|
56 | // ************************************************************************** // |
---|
57 | |
---|
58 | template<typename T> |
---|
59 | class typed_argument : public argument { |
---|
60 | public: |
---|
61 | // Constructor |
---|
62 | explicit typed_argument( parameter const& p ) |
---|
63 | : argument( p, rtti::type_id<T>() ) |
---|
64 | {} |
---|
65 | typed_argument( parameter const& p, T const& t ) |
---|
66 | : argument( p, rtti::type_id<T>() ) |
---|
67 | , p_value( t ) |
---|
68 | {} |
---|
69 | |
---|
70 | unit_test::readwrite_property<T> p_value; |
---|
71 | }; |
---|
72 | |
---|
73 | // ************************************************************************** // |
---|
74 | // ************** runtime::arg_value ************** // |
---|
75 | // ************************************************************************** // |
---|
76 | |
---|
77 | template<typename T> |
---|
78 | inline T const& |
---|
79 | arg_value( argument const& arg ) |
---|
80 | { |
---|
81 | assert( arg.p_value_type == rtti::type_id<T>() ); // detect logic error |
---|
82 | |
---|
83 | return static_cast<typed_argument<T> const&>( arg ).p_value.value; |
---|
84 | } |
---|
85 | |
---|
86 | //____________________________________________________________________________// |
---|
87 | |
---|
88 | template<typename T> |
---|
89 | inline T& |
---|
90 | arg_value( argument& arg ) |
---|
91 | { |
---|
92 | assert( arg.p_value_type == rtti::type_id<T>() ); // detect logic error |
---|
93 | |
---|
94 | return static_cast<typed_argument<T>&>( arg ).p_value.value; |
---|
95 | } |
---|
96 | |
---|
97 | //____________________________________________________________________________// |
---|
98 | |
---|
99 | } // namespace BOOST_RT_PARAM_NAMESPACE |
---|
100 | |
---|
101 | } // namespace boost |
---|
102 | |
---|
103 | // ************************************************************************** // |
---|
104 | // Revision History: |
---|
105 | // |
---|
106 | // $Log: argument.hpp,v $ |
---|
107 | // Revision 1.2 2005/04/12 07:01:35 rogeeff |
---|
108 | // exclude polymorphic_downcast |
---|
109 | // |
---|
110 | // Revision 1.1 2005/04/12 06:42:42 rogeeff |
---|
111 | // Runtime.Param library initial commit |
---|
112 | // |
---|
113 | // ************************************************************************** // |
---|
114 | |
---|
115 | #endif // BOOST_RT_ARGUMENT_HPP_062604GER |
---|