Warning, file /include/boost/test/utils/class_properties.hpp was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #ifndef BOOST_TEST_UTILS_CLASS_PROPERTIES_HPP
0017 #define BOOST_TEST_UTILS_CLASS_PROPERTIES_HPP
0018
0019
0020 #include <boost/test/detail/config.hpp>
0021
0022
0023 #if !BOOST_WORKAROUND(__IBMCPP__, BOOST_TESTED_AT(600))
0024 #include <boost/preprocessor/seq/for_each.hpp>
0025 #endif
0026 #include <boost/call_traits.hpp>
0027 #include <boost/type_traits/add_pointer.hpp>
0028 #include <boost/type_traits/add_const.hpp>
0029 #include <boost/utility/addressof.hpp>
0030
0031
0032 #include <iosfwd>
0033
0034 #include <boost/test/detail/suppress_warnings.hpp>
0035
0036
0037
0038 namespace boost {
0039 namespace unit_test {
0040
0041
0042
0043
0044
0045 template<class PropertyType>
0046 class class_property {
0047 protected:
0048 typedef typename call_traits<PropertyType>::const_reference read_access_t;
0049 typedef typename call_traits<PropertyType>::param_type write_param_t;
0050 typedef typename add_pointer<typename add_const<PropertyType>::type>::type address_res_t;
0051 public:
0052
0053 class_property() : value( PropertyType() ) {}
0054 explicit class_property( write_param_t init_value )
0055 : value( init_value ) {}
0056
0057
0058 operator read_access_t() const { return value; }
0059 read_access_t get() const { return value; }
0060 bool operator!() const { return !value; }
0061 address_res_t operator&() const { return &value; }
0062
0063
0064 #ifndef BOOST_TEST_NO_PROTECTED_USING
0065 protected:
0066 #endif
0067 PropertyType value;
0068 };
0069
0070
0071
0072 #ifdef BOOST_CLASSIC_IOSTREAMS
0073
0074 template<class PropertyType>
0075 inline std::ostream&
0076 operator<<( std::ostream& os, class_property<PropertyType> const& p )
0077
0078 #else
0079
0080 template<typename CharT1, typename Tr,class PropertyType>
0081 inline std::basic_ostream<CharT1,Tr>&
0082 operator<<( std::basic_ostream<CharT1,Tr>& os, class_property<PropertyType> const& p )
0083
0084 #endif
0085 {
0086 return os << p.get();
0087 }
0088
0089
0090
0091 #define DEFINE_PROPERTY_FREE_BINARY_OPERATOR( op ) \
0092 template<class PropertyType> \
0093 inline bool \
0094 operator op( PropertyType const& lhs, class_property<PropertyType> const& rhs ) \
0095 { \
0096 return lhs op rhs.get(); \
0097 } \
0098 template<class PropertyType> \
0099 inline bool \
0100 operator op( class_property<PropertyType> const& lhs, PropertyType const& rhs ) \
0101 { \
0102 return lhs.get() op rhs; \
0103 } \
0104 template<class PropertyType> \
0105 inline bool \
0106 operator op( class_property<PropertyType> const& lhs, \
0107 class_property<PropertyType> const& rhs ) \
0108 { \
0109 return lhs.get() op rhs.get(); \
0110 } \
0111
0112
0113 DEFINE_PROPERTY_FREE_BINARY_OPERATOR( == )
0114 DEFINE_PROPERTY_FREE_BINARY_OPERATOR( != )
0115
0116 #undef DEFINE_PROPERTY_FREE_BINARY_OPERATOR
0117
0118
0119
0120
0121
0122 template<class PropertyType>
0123 class readonly_property : public class_property<PropertyType> {
0124 typedef class_property<PropertyType> base_prop;
0125 typedef typename base_prop::address_res_t arrow_res_t;
0126 protected:
0127 typedef typename base_prop::write_param_t write_param_t;
0128 public:
0129
0130 readonly_property() {}
0131 explicit readonly_property( write_param_t init_value ) : base_prop( init_value ) {}
0132
0133
0134 arrow_res_t operator->() const { return boost::addressof( base_prop::value ); }
0135 };
0136
0137
0138
0139 #if BOOST_WORKAROUND(__IBMCPP__, BOOST_TESTED_AT(600))
0140
0141 #define BOOST_READONLY_PROPERTY( property_type, friends ) boost::unit_test::readwrite_property<property_type >
0142
0143 #else
0144
0145 #define BOOST_READONLY_PROPERTY_DECLARE_FRIEND(r, data, elem) friend class elem;
0146
0147 #define BOOST_READONLY_PROPERTY( property_type, friends ) \
0148 class BOOST_JOIN( readonly_property, __LINE__ ) \
0149 : public boost::unit_test::readonly_property<property_type > { \
0150 typedef boost::unit_test::readonly_property<property_type > base_prop; \
0151 BOOST_PP_SEQ_FOR_EACH( BOOST_READONLY_PROPERTY_DECLARE_FRIEND, ' ', friends ) \
0152 typedef base_prop::write_param_t write_param_t; \
0153 public: \
0154 BOOST_JOIN( readonly_property, __LINE__ )() {} \
0155 explicit BOOST_JOIN( readonly_property, __LINE__ )( write_param_t init_v ) \
0156 : base_prop( init_v ) {} \
0157 } \
0158
0159
0160 #endif
0161
0162
0163
0164
0165
0166 template<class PropertyType>
0167 class readwrite_property : public class_property<PropertyType> {
0168 typedef class_property<PropertyType> base_prop;
0169 typedef typename add_pointer<PropertyType>::type arrow_res_t;
0170 typedef typename base_prop::address_res_t const_arrow_res_t;
0171 typedef typename base_prop::write_param_t write_param_t;
0172 public:
0173 readwrite_property() : base_prop() {}
0174 explicit readwrite_property( write_param_t init_value ) : base_prop( init_value ) {}
0175
0176
0177 void set( write_param_t v ) { base_prop::value = v; }
0178 arrow_res_t operator->() { return boost::addressof( base_prop::value ); }
0179 const_arrow_res_t operator->() const { return boost::addressof( base_prop::value ); }
0180
0181 #ifndef BOOST_TEST_NO_PROTECTED_USING
0182 using base_prop::value;
0183 #endif
0184 };
0185
0186
0187
0188 }
0189 }
0190
0191 #include <boost/test/detail/enable_warnings.hpp>
0192
0193 #undef BOOST_TEST_NO_PROTECTED_USING
0194
0195 #endif