--- trunk/OOPSE-4/src/utils/any.hpp 2005/04/15 22:03:16 2203 +++ trunk/OOPSE-4/src/utils/any.hpp 2005/04/15 22:04:00 2204 @@ -1,28 +1,28 @@ /* -* Boost Software License - Version 1.0 - August 17th, 2003 -* -* Permission is hereby granted, free of charge, to any person or organization -* obtaining a copy of the software and accompanying documentation covered by -* this license (the "Software") to use, reproduce, display, distribute, -* execute, and transmit the Software, and to prepare derivative works of the -* Software, and to permit third-parties to whom the Software is furnished to -* do so, all subject to the following: + * Boost Software License - Version 1.0 - August 17th, 2003 + * + * Permission is hereby granted, free of charge, to any person or organization + * obtaining a copy of the software and accompanying documentation covered by + * this license (the "Software") to use, reproduce, display, distribute, + * execute, and transmit the Software, and to prepare derivative works of the + * Software, and to permit third-parties to whom the Software is furnished to + * do so, all subject to the following: -* The copyright notices in the Software and this entire statement, including -* the above license grant, this restriction and the following disclaimer, -* must be included in all copies of the Software, in whole or in part, and -* all derivative works of the Software, unless such copies or derivative -* works are solely in the form of machine-executable object code generated by -* a source language processor. + * The copyright notices in the Software and this entire statement, including + * the above license grant, this restriction and the following disclaimer, + * must be included in all copies of the Software, in whole or in part, and + * all derivative works of the Software, unless such copies or derivative + * works are solely in the form of machine-executable object code generated by + * a source language processor. -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -* DEALINGS IN THE SOFTWARE. -*/ + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT + * SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE + * FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ // See http://www.boost.org/libs/any for Documentation. @@ -42,174 +42,174 @@ namespace boost namespace boost { - template inline void throw_exception(E const & e) { - throw e; + template inline void throw_exception(E const & e) { + throw e; + } + + class any + { + public: // structors + + any() + : content(0) + { } - class any + template + any(const ValueType & value) + : content(new holder(value)) { - public: // structors + } - any() - : content(0) - { - } + any(const any & other) + : content(other.content ? other.content->clone() : 0) + { + } - template - any(const ValueType & value) - : content(new holder(value)) - { - } + ~any() + { + delete content; + } - any(const any & other) - : content(other.content ? other.content->clone() : 0) - { - } + public: // modifiers - ~any() - { - delete content; - } + any & swap(any & rhs) + { + std::swap(content, rhs.content); + return *this; + } - public: // modifiers + template + any & operator=(const ValueType & rhs) + { + any(rhs).swap(*this); + return *this; + } - any & swap(any & rhs) - { - std::swap(content, rhs.content); - return *this; - } + any & operator=(const any & rhs) + { + any(rhs).swap(*this); + return *this; + } - template - any & operator=(const ValueType & rhs) - { - any(rhs).swap(*this); - return *this; - } + public: // queries - any & operator=(const any & rhs) - { - any(rhs).swap(*this); - return *this; - } + bool empty() const + { + return !content; + } - public: // queries + const std::type_info & type() const + { + return content ? content->type() : typeid(void); + } - bool empty() const - { - return !content; - } + //#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS + // private: // types + //#else + public: // types (public so any_cast can be non-friend) + //#endif - const std::type_info & type() const - { - return content ? content->type() : typeid(void); - } - -//#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS -// private: // types -//#else - public: // types (public so any_cast can be non-friend) -//#endif - - class placeholder - { - public: // structors + class placeholder + { + public: // structors - virtual ~placeholder() - { - } + virtual ~placeholder() + { + } - public: // queries + public: // queries - virtual const std::type_info & type() const = 0; + virtual const std::type_info & type() const = 0; - virtual placeholder * clone() const = 0; + virtual placeholder * clone() const = 0; - }; + }; - template - class holder : public placeholder - { - public: // structors + template + class holder : public placeholder + { + public: // structors - holder(const ValueType & value) - : held(value) - { - } + holder(const ValueType & value) + : held(value) + { + } - public: // queries + public: // queries - virtual const std::type_info & type() const - { - return typeid(ValueType); - } + virtual const std::type_info & type() const + { + return typeid(ValueType); + } - virtual placeholder * clone() const - { - return new holder(held); - } + virtual placeholder * clone() const + { + return new holder(held); + } - public: // representation + public: // representation - ValueType held; + ValueType held; - }; + }; -//#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS -// -// private: // representation -// -// template -// friend ValueType * any_cast(any *); -// -//#else -// - public: // representation (public so any_cast can be non-friend) -// -//#endif + //#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS + // + // private: // representation + // + // template + // friend ValueType * any_cast(any *); + // + //#else + // + public: // representation (public so any_cast can be non-friend) + // + //#endif - placeholder * content; + placeholder * content; - }; + }; - class bad_any_cast : public std::bad_cast + class bad_any_cast : public std::bad_cast + { + public: + virtual const char * what() const throw() { - public: - virtual const char * what() const throw() - { - return "boost::bad_any_cast: " - "failed conversion using boost::any_cast"; - } - }; - - template - ValueType * any_cast(any * operand) - { - return operand && operand->type() == typeid(ValueType) - ? &static_cast *>(operand->content)->held - : 0; + return "boost::bad_any_cast: " + "failed conversion using boost::any_cast"; } + }; - template - const ValueType * any_cast(const any * operand) - { - return any_cast(const_cast(operand)); - } + template + ValueType * any_cast(any * operand) + { + return operand && operand->type() == typeid(ValueType) + ? &static_cast *>(operand->content)->held + : 0; + } - template - ValueType any_cast(const any & operand) - { - const ValueType * result = any_cast(&operand); - if(!result) - boost::throw_exception(bad_any_cast()); - return *result; - } + template + const ValueType * any_cast(const any * operand) + { + return any_cast(const_cast(operand)); + } + template + ValueType any_cast(const any & operand) + { + const ValueType * result = any_cast(&operand); + if(!result) + boost::throw_exception(bad_any_cast()); + return *result; + } - template - bool equal_any_type(const any& operand) { - } + template + bool equal_any_type(const any& operand) { + } + } // Copyright Kevlin Henney, 2000, 2001, 2002. All rights reserved.