1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/epoc32/include/stdapis/boost/any.hpp Tue Mar 16 16:12:26 2010 +0000
1.3 @@ -0,0 +1,238 @@
1.4 +// See http://www.boost.org/libs/any for Documentation.
1.5 +
1.6 +#ifndef BOOST_ANY_INCLUDED
1.7 +#define BOOST_ANY_INCLUDED
1.8 +
1.9 +// what: variant type boost::any
1.10 +// who: contributed by Kevlin Henney,
1.11 +// with features contributed and bugs found by
1.12 +// Ed Brey, Mark Rodgers, Peter Dimov, and James Curran
1.13 +// when: July 2001
1.14 +// where: tested with BCC 5.5, MSVC 6.0, and g++ 2.95
1.15 +
1.16 +#include <algorithm>
1.17 +#include <typeinfo>
1.18 +
1.19 +#include "boost/config.hpp"
1.20 +#include <boost/type_traits/remove_reference.hpp>
1.21 +#include <boost/type_traits/is_reference.hpp>
1.22 +#include <boost/throw_exception.hpp>
1.23 +#include <boost/static_assert.hpp>
1.24 +
1.25 +namespace boost
1.26 +{
1.27 + class any
1.28 + {
1.29 + public: // structors
1.30 +
1.31 + any()
1.32 + : content(0)
1.33 + {
1.34 + }
1.35 +
1.36 + template<typename ValueType>
1.37 + any(const ValueType & value)
1.38 + : content(new holder<ValueType>(value))
1.39 + {
1.40 + }
1.41 +
1.42 + any(const any & other)
1.43 + : content(other.content ? other.content->clone() : 0)
1.44 + {
1.45 + }
1.46 +
1.47 + ~any()
1.48 + {
1.49 + delete content;
1.50 + }
1.51 +
1.52 + public: // modifiers
1.53 +
1.54 + any & swap(any & rhs)
1.55 + {
1.56 + std::swap(content, rhs.content);
1.57 + return *this;
1.58 + }
1.59 +
1.60 + template<typename ValueType>
1.61 + any & operator=(const ValueType & rhs)
1.62 + {
1.63 + any(rhs).swap(*this);
1.64 + return *this;
1.65 + }
1.66 +
1.67 + any & operator=(const any & rhs)
1.68 + {
1.69 + any(rhs).swap(*this);
1.70 + return *this;
1.71 + }
1.72 +
1.73 + public: // queries
1.74 +
1.75 + bool empty() const
1.76 + {
1.77 + return !content;
1.78 + }
1.79 +
1.80 + const std::type_info & type() const
1.81 + {
1.82 + return content ? content->type() : typeid(void);
1.83 + }
1.84 +
1.85 +#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
1.86 + private: // types
1.87 +#else
1.88 + public: // types (public so any_cast can be non-friend)
1.89 +#endif
1.90 +
1.91 + class placeholder
1.92 + {
1.93 + public: // structors
1.94 +
1.95 + virtual ~placeholder()
1.96 + {
1.97 + }
1.98 +
1.99 + public: // queries
1.100 +
1.101 + virtual const std::type_info & type() const = 0;
1.102 +
1.103 + virtual placeholder * clone() const = 0;
1.104 +
1.105 + };
1.106 +
1.107 + template<typename ValueType>
1.108 + class holder : public placeholder
1.109 + {
1.110 + public: // structors
1.111 +
1.112 + holder(const ValueType & value)
1.113 + : held(value)
1.114 + {
1.115 + }
1.116 +
1.117 + public: // queries
1.118 +
1.119 + virtual const std::type_info & type() const
1.120 + {
1.121 + return typeid(ValueType);
1.122 + }
1.123 +
1.124 + virtual placeholder * clone() const
1.125 + {
1.126 + return new holder(held);
1.127 + }
1.128 +
1.129 + public: // representation
1.130 +
1.131 + ValueType held;
1.132 +
1.133 + };
1.134 +
1.135 +#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
1.136 +
1.137 + private: // representation
1.138 +
1.139 + template<typename ValueType>
1.140 + friend ValueType * any_cast(any *);
1.141 +
1.142 + template<typename ValueType>
1.143 + friend ValueType * unsafe_any_cast(any *);
1.144 +
1.145 +#else
1.146 +
1.147 + public: // representation (public so any_cast can be non-friend)
1.148 +
1.149 +#endif
1.150 +
1.151 + placeholder * content;
1.152 +
1.153 + };
1.154 +
1.155 + class bad_any_cast : public std::bad_cast
1.156 + {
1.157 + public:
1.158 + virtual const char * what() const throw()
1.159 + {
1.160 + return "boost::bad_any_cast: "
1.161 + "failed conversion using boost::any_cast";
1.162 + }
1.163 + };
1.164 +
1.165 + template<typename ValueType>
1.166 + ValueType * any_cast(any * operand)
1.167 + {
1.168 + return operand && operand->type() == typeid(ValueType)
1.169 + ? &static_cast<any::holder<ValueType> *>(operand->content)->held
1.170 + : 0;
1.171 + }
1.172 +
1.173 + template<typename ValueType>
1.174 + const ValueType * any_cast(const any * operand)
1.175 + {
1.176 + return any_cast<ValueType>(const_cast<any *>(operand));
1.177 + }
1.178 +
1.179 + template<typename ValueType>
1.180 + ValueType any_cast(const any & operand)
1.181 + {
1.182 + typedef BOOST_DEDUCED_TYPENAME remove_reference<ValueType>::type nonref;
1.183 +
1.184 +#ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
1.185 + // If 'nonref' is still reference type, it means the user has not
1.186 + // specialized 'remove_reference'.
1.187 +
1.188 + // Please use BOOST_BROKEN_COMPILER_TYPE_TRAITS_SPECIALIZATION macro
1.189 + // to generate specialization of remove_reference for your class
1.190 + // See type traits library documentation for details
1.191 + BOOST_STATIC_ASSERT(!is_reference<nonref>::value);
1.192 +#endif
1.193 +
1.194 + const nonref * result = any_cast<nonref>(&operand);
1.195 + if(!result)
1.196 + boost::throw_exception(bad_any_cast());
1.197 + return *result;
1.198 + }
1.199 +
1.200 + template<typename ValueType>
1.201 + ValueType any_cast(any & operand)
1.202 + {
1.203 + typedef BOOST_DEDUCED_TYPENAME remove_reference<ValueType>::type nonref;
1.204 +
1.205 +#ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
1.206 + // The comment in the above version of 'any_cast' explains when this
1.207 + // assert is fired and what to do.
1.208 + BOOST_STATIC_ASSERT(!is_reference<nonref>::value);
1.209 +#endif
1.210 +
1.211 + nonref * result = any_cast<nonref>(&operand);
1.212 + if(!result)
1.213 + boost::throw_exception(bad_any_cast());
1.214 + return *result;
1.215 + }
1.216 +
1.217 + // Note: The "unsafe" versions of any_cast are not part of the
1.218 + // public interface and may be removed at any time. They are
1.219 + // required where we know what type is stored in the any and can't
1.220 + // use typeid() comparison, e.g., when our types may travel across
1.221 + // different shared libraries.
1.222 + template<typename ValueType>
1.223 + inline ValueType * unsafe_any_cast(any * operand)
1.224 + {
1.225 + return &static_cast<any::holder<ValueType> *>(operand->content)->held;
1.226 + }
1.227 +
1.228 + template<typename ValueType>
1.229 + inline const ValueType * unsafe_any_cast(const any * operand)
1.230 + {
1.231 + return unsafe_any_cast<ValueType>(const_cast<any *>(operand));
1.232 + }
1.233 +}
1.234 +
1.235 +// Copyright Kevlin Henney, 2000, 2001, 2002. All rights reserved.
1.236 +//
1.237 +// Distributed under the Boost Software License, Version 1.0. (See
1.238 +// accompanying file LICENSE_1_0.txt or copy at
1.239 +// http://www.boost.org/LICENSE_1_0.txt)
1.240 +
1.241 +#endif