///////////////////////////////////////////////////////////////////////////// // // (C) Copyright Vicente J. Botet Escriba 2010. // Distributed under the Boost // Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or // copy at http://www.boost.org/LICENSE_1_0.txt) // // See http://www.boost.org/libs/stm for documentation. // ////////////////////////////////////////////////////////////////////////////// #ifndef BOOST_PROPERTY__HPP #define BOOST_PROPERTY__HPP #include namespace boost { template class ro_property { protected: Final const & that_; Final & that() {return const_cast(that_);} public: typedef T value_type; //----------------------------------------------------------------------------- ro_property(Final const& that) : that_(that) {} ro_property(ro_property const& r) : that_(r.that_) {} template ro_property(ro_property const& r) : that_(r.that_) {} operator T() const { //T(Final::* get)()=Getter; return (that_.*Getter)(); } }; template class rw_property : public ro_property { typedef ro_property base_type; public: typedef T value_type; //----------------------------------------------------------------------------- rw_property(Final & that) : base_type(that) {} rw_property(rw_property const& r) : base_type(r) {} template rw_property(rw_property const& r) : base_type(r) {} rw_property& operator=(T const& rhs) { (this->that().*Setter)(rhs); return *this; } template rw_property& operator=(U const& rhs) { (this->that().*Setter)(rhs); return *this; } }; template struct rw_property_traits { typedef rw_property reference; typedef rw_property value; }; template struct ro_property_traits { typedef ro_property value; }; } #define BOOST_RW_PROPERTY(FINAL, T, FIELD) \ typedef boost::rw_property_traits BOOST_JOIN(FIELD,_type); \ BOOST_JOIN(FIELD,_type)::reference FIELD() { return BOOST_JOIN(FIELD,_type)::reference(*this); } \ BOOST_JOIN(FIELD,_type)::value::value_type FIELD() const { return T(BOOST_JOIN(FIELD,_type)::value(*const_cast(this))); } \ #define BOOST_RO_PROPERTY(FINAL, T, FIELD) \ typedef boost::ro_property_traits BOOST_JOIN(FIELD,_type); \ BOOST_JOIN(FIELD,_type)::value::value_type FIELD() const { return T(BOOST_JOIN(FIELD,_type)::value(*this)); } \ #define BOOST_RW_PROPERTY_STORAGE(FINAL, T, FIELD) \ private:\ T BOOST_JOIN(FIELD,_); \ public:\ T& FIELD() { return BOOST_JOIN(FIELD,_); } \ T FIELD() const { return BOOST_JOIN(FIELD,_); } \ #define BOOST_RO_PROPERTY_STORAGE(FINAL, T, FIELD) \ private:\ T BOOST_JOIN(FIELD,_); \ public:\ T FIELD() const { return BOOST_JOIN(FIELD,_); } \ #endif //BOOST_PROPERTY__HPP