| 1 |
|
/* |
| 2 |
< |
* Boost Software License - Version 1.0 - August 17th, 2003 |
| 3 |
< |
* |
| 4 |
< |
* Permission is hereby granted, free of charge, to any person or organization |
| 5 |
< |
* obtaining a copy of the software and accompanying documentation covered by |
| 6 |
< |
* this license (the "Software") to use, reproduce, display, distribute, |
| 7 |
< |
* execute, and transmit the Software, and to prepare derivative works of the |
| 8 |
< |
* Software, and to permit third-parties to whom the Software is furnished to |
| 9 |
< |
* do so, all subject to the following: |
| 2 |
> |
* Boost Software License - Version 1.0 - August 17th, 2003 |
| 3 |
> |
* |
| 4 |
> |
* Permission is hereby granted, free of charge, to any person or organization |
| 5 |
> |
* obtaining a copy of the software and accompanying documentation covered by |
| 6 |
> |
* this license (the "Software") to use, reproduce, display, distribute, |
| 7 |
> |
* execute, and transmit the Software, and to prepare derivative works of the |
| 8 |
> |
* Software, and to permit third-parties to whom the Software is furnished to |
| 9 |
> |
* do so, all subject to the following: |
| 10 |
|
|
| 11 |
< |
* The copyright notices in the Software and this entire statement, including |
| 12 |
< |
* the above license grant, this restriction and the following disclaimer, |
| 13 |
< |
* must be included in all copies of the Software, in whole or in part, and |
| 14 |
< |
* all derivative works of the Software, unless such copies or derivative |
| 15 |
< |
* works are solely in the form of machine-executable object code generated by |
| 16 |
< |
* a source language processor. |
| 11 |
> |
* The copyright notices in the Software and this entire statement, including |
| 12 |
> |
* the above license grant, this restriction and the following disclaimer, |
| 13 |
> |
* must be included in all copies of the Software, in whole or in part, and |
| 14 |
> |
* all derivative works of the Software, unless such copies or derivative |
| 15 |
> |
* works are solely in the form of machine-executable object code generated by |
| 16 |
> |
* a source language processor. |
| 17 |
|
|
| 18 |
< |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 19 |
< |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 20 |
< |
* FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT |
| 21 |
< |
* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE |
| 22 |
< |
* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, |
| 23 |
< |
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 24 |
< |
* DEALINGS IN THE SOFTWARE. |
| 25 |
< |
*/ |
| 18 |
> |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 19 |
> |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 20 |
> |
* FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT |
| 21 |
> |
* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE |
| 22 |
> |
* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, |
| 23 |
> |
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 24 |
> |
* DEALINGS IN THE SOFTWARE. |
| 25 |
> |
*/ |
| 26 |
|
|
| 27 |
|
// See http://www.boost.org/libs/any for Documentation. |
| 28 |
|
|
| 42 |
|
namespace boost |
| 43 |
|
{ |
| 44 |
|
|
| 45 |
< |
template<class E> inline void throw_exception(E const & e) { |
| 46 |
< |
throw e; |
| 45 |
> |
template<class E> inline void throw_exception(E const & e) { |
| 46 |
> |
throw e; |
| 47 |
> |
} |
| 48 |
> |
|
| 49 |
> |
class any |
| 50 |
> |
{ |
| 51 |
> |
public: // structors |
| 52 |
> |
|
| 53 |
> |
any() |
| 54 |
> |
: content(0) |
| 55 |
> |
{ |
| 56 |
|
} |
| 57 |
|
|
| 58 |
< |
class any |
| 58 |
> |
template<typename ValueType> |
| 59 |
> |
any(const ValueType & value) |
| 60 |
> |
: content(new holder<ValueType>(value)) |
| 61 |
|
{ |
| 62 |
< |
public: // structors |
| 62 |
> |
} |
| 63 |
|
|
| 64 |
< |
any() |
| 65 |
< |
: content(0) |
| 66 |
< |
{ |
| 67 |
< |
} |
| 64 |
> |
any(const any & other) |
| 65 |
> |
: content(other.content ? other.content->clone() : 0) |
| 66 |
> |
{ |
| 67 |
> |
} |
| 68 |
|
|
| 69 |
< |
template<typename ValueType> |
| 70 |
< |
any(const ValueType & value) |
| 71 |
< |
: content(new holder<ValueType>(value)) |
| 72 |
< |
{ |
| 62 |
< |
} |
| 69 |
> |
~any() |
| 70 |
> |
{ |
| 71 |
> |
delete content; |
| 72 |
> |
} |
| 73 |
|
|
| 74 |
< |
any(const any & other) |
| 65 |
< |
: content(other.content ? other.content->clone() : 0) |
| 66 |
< |
{ |
| 67 |
< |
} |
| 74 |
> |
public: // modifiers |
| 75 |
|
|
| 76 |
< |
~any() |
| 77 |
< |
{ |
| 78 |
< |
delete content; |
| 79 |
< |
} |
| 76 |
> |
any & swap(any & rhs) |
| 77 |
> |
{ |
| 78 |
> |
std::swap(content, rhs.content); |
| 79 |
> |
return *this; |
| 80 |
> |
} |
| 81 |
|
|
| 82 |
< |
public: // modifiers |
| 82 |
> |
template<typename ValueType> |
| 83 |
> |
any & operator=(const ValueType & rhs) |
| 84 |
> |
{ |
| 85 |
> |
any(rhs).swap(*this); |
| 86 |
> |
return *this; |
| 87 |
> |
} |
| 88 |
|
|
| 89 |
< |
any & swap(any & rhs) |
| 90 |
< |
{ |
| 91 |
< |
std::swap(content, rhs.content); |
| 92 |
< |
return *this; |
| 93 |
< |
} |
| 89 |
> |
any & operator=(const any & rhs) |
| 90 |
> |
{ |
| 91 |
> |
any(rhs).swap(*this); |
| 92 |
> |
return *this; |
| 93 |
> |
} |
| 94 |
|
|
| 95 |
< |
template<typename ValueType> |
| 83 |
< |
any & operator=(const ValueType & rhs) |
| 84 |
< |
{ |
| 85 |
< |
any(rhs).swap(*this); |
| 86 |
< |
return *this; |
| 87 |
< |
} |
| 95 |
> |
public: // queries |
| 96 |
|
|
| 97 |
< |
any & operator=(const any & rhs) |
| 98 |
< |
{ |
| 99 |
< |
any(rhs).swap(*this); |
| 100 |
< |
return *this; |
| 93 |
< |
} |
| 97 |
> |
bool empty() const |
| 98 |
> |
{ |
| 99 |
> |
return !content; |
| 100 |
> |
} |
| 101 |
|
|
| 102 |
< |
public: // queries |
| 102 |
> |
const std::type_info & type() const |
| 103 |
> |
{ |
| 104 |
> |
return content ? content->type() : typeid(void); |
| 105 |
> |
} |
| 106 |
|
|
| 107 |
< |
bool empty() const |
| 108 |
< |
{ |
| 109 |
< |
return !content; |
| 110 |
< |
} |
| 107 |
> |
//#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS |
| 108 |
> |
// private: // types |
| 109 |
> |
//#else |
| 110 |
> |
public: // types (public so any_cast can be non-friend) |
| 111 |
> |
//#endif |
| 112 |
|
|
| 113 |
< |
const std::type_info & type() const |
| 114 |
< |
{ |
| 115 |
< |
return content ? content->type() : typeid(void); |
| 105 |
< |
} |
| 106 |
< |
|
| 107 |
< |
//#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS |
| 108 |
< |
// private: // types |
| 109 |
< |
//#else |
| 110 |
< |
public: // types (public so any_cast can be non-friend) |
| 111 |
< |
//#endif |
| 112 |
< |
|
| 113 |
< |
class placeholder |
| 114 |
< |
{ |
| 115 |
< |
public: // structors |
| 113 |
> |
class placeholder |
| 114 |
> |
{ |
| 115 |
> |
public: // structors |
| 116 |
|
|
| 117 |
< |
virtual ~placeholder() |
| 118 |
< |
{ |
| 119 |
< |
} |
| 117 |
> |
virtual ~placeholder() |
| 118 |
> |
{ |
| 119 |
> |
} |
| 120 |
|
|
| 121 |
< |
public: // queries |
| 121 |
> |
public: // queries |
| 122 |
|
|
| 123 |
< |
virtual const std::type_info & type() const = 0; |
| 123 |
> |
virtual const std::type_info & type() const = 0; |
| 124 |
|
|
| 125 |
< |
virtual placeholder * clone() const = 0; |
| 125 |
> |
virtual placeholder * clone() const = 0; |
| 126 |
|
|
| 127 |
< |
}; |
| 127 |
> |
}; |
| 128 |
|
|
| 129 |
< |
template<typename ValueType> |
| 130 |
< |
class holder : public placeholder |
| 131 |
< |
{ |
| 132 |
< |
public: // structors |
| 129 |
> |
template<typename ValueType> |
| 130 |
> |
class holder : public placeholder |
| 131 |
> |
{ |
| 132 |
> |
public: // structors |
| 133 |
|
|
| 134 |
< |
holder(const ValueType & value) |
| 135 |
< |
: held(value) |
| 136 |
< |
{ |
| 137 |
< |
} |
| 134 |
> |
holder(const ValueType & value) |
| 135 |
> |
: held(value) |
| 136 |
> |
{ |
| 137 |
> |
} |
| 138 |
|
|
| 139 |
< |
public: // queries |
| 139 |
> |
public: // queries |
| 140 |
|
|
| 141 |
< |
virtual const std::type_info & type() const |
| 142 |
< |
{ |
| 143 |
< |
return typeid(ValueType); |
| 144 |
< |
} |
| 141 |
> |
virtual const std::type_info & type() const |
| 142 |
> |
{ |
| 143 |
> |
return typeid(ValueType); |
| 144 |
> |
} |
| 145 |
|
|
| 146 |
< |
virtual placeholder * clone() const |
| 147 |
< |
{ |
| 148 |
< |
return new holder(held); |
| 149 |
< |
} |
| 146 |
> |
virtual placeholder * clone() const |
| 147 |
> |
{ |
| 148 |
> |
return new holder(held); |
| 149 |
> |
} |
| 150 |
|
|
| 151 |
< |
public: // representation |
| 151 |
> |
public: // representation |
| 152 |
|
|
| 153 |
< |
ValueType held; |
| 153 |
> |
ValueType held; |
| 154 |
|
|
| 155 |
< |
}; |
| 155 |
> |
}; |
| 156 |
|
|
| 157 |
< |
//#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS |
| 158 |
< |
// |
| 159 |
< |
// private: // representation |
| 160 |
< |
// |
| 161 |
< |
// template<typename ValueType> |
| 162 |
< |
// friend ValueType * any_cast(any *); |
| 163 |
< |
// |
| 164 |
< |
//#else |
| 165 |
< |
// |
| 166 |
< |
public: // representation (public so any_cast can be non-friend) |
| 167 |
< |
// |
| 168 |
< |
//#endif |
| 157 |
> |
//#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS |
| 158 |
> |
// |
| 159 |
> |
// private: // representation |
| 160 |
> |
// |
| 161 |
> |
// template<typename ValueType> |
| 162 |
> |
// friend ValueType * any_cast(any *); |
| 163 |
> |
// |
| 164 |
> |
//#else |
| 165 |
> |
// |
| 166 |
> |
public: // representation (public so any_cast can be non-friend) |
| 167 |
> |
// |
| 168 |
> |
//#endif |
| 169 |
|
|
| 170 |
< |
placeholder * content; |
| 170 |
> |
placeholder * content; |
| 171 |
|
|
| 172 |
< |
}; |
| 172 |
> |
}; |
| 173 |
|
|
| 174 |
< |
class bad_any_cast : public std::bad_cast |
| 174 |
> |
class bad_any_cast : public std::bad_cast |
| 175 |
> |
{ |
| 176 |
> |
public: |
| 177 |
> |
virtual const char * what() const throw() |
| 178 |
|
{ |
| 179 |
< |
public: |
| 180 |
< |
virtual const char * what() const throw() |
| 178 |
< |
{ |
| 179 |
< |
return "boost::bad_any_cast: " |
| 180 |
< |
"failed conversion using boost::any_cast"; |
| 181 |
< |
} |
| 182 |
< |
}; |
| 183 |
< |
|
| 184 |
< |
template<typename ValueType> |
| 185 |
< |
ValueType * any_cast(any * operand) |
| 186 |
< |
{ |
| 187 |
< |
return operand && operand->type() == typeid(ValueType) |
| 188 |
< |
? &static_cast<any::holder<ValueType> *>(operand->content)->held |
| 189 |
< |
: 0; |
| 179 |
> |
return "boost::bad_any_cast: " |
| 180 |
> |
"failed conversion using boost::any_cast"; |
| 181 |
|
} |
| 182 |
+ |
}; |
| 183 |
|
|
| 184 |
< |
template<typename ValueType> |
| 185 |
< |
const ValueType * any_cast(const any * operand) |
| 186 |
< |
{ |
| 187 |
< |
return any_cast<ValueType>(const_cast<any *>(operand)); |
| 188 |
< |
} |
| 184 |
> |
template<typename ValueType> |
| 185 |
> |
ValueType * any_cast(any * operand) |
| 186 |
> |
{ |
| 187 |
> |
return operand && operand->type() == typeid(ValueType) |
| 188 |
> |
? &static_cast<any::holder<ValueType> *>(operand->content)->held |
| 189 |
> |
: 0; |
| 190 |
> |
} |
| 191 |
|
|
| 192 |
< |
template<typename ValueType> |
| 193 |
< |
ValueType any_cast(const any & operand) |
| 194 |
< |
{ |
| 195 |
< |
const ValueType * result = any_cast<ValueType>(&operand); |
| 196 |
< |
if(!result) |
| 203 |
< |
boost::throw_exception(bad_any_cast()); |
| 204 |
< |
return *result; |
| 205 |
< |
} |
| 192 |
> |
template<typename ValueType> |
| 193 |
> |
const ValueType * any_cast(const any * operand) |
| 194 |
> |
{ |
| 195 |
> |
return any_cast<ValueType>(const_cast<any *>(operand)); |
| 196 |
> |
} |
| 197 |
|
|
| 198 |
+ |
template<typename ValueType> |
| 199 |
+ |
ValueType any_cast(const any & operand) |
| 200 |
+ |
{ |
| 201 |
+ |
const ValueType * result = any_cast<ValueType>(&operand); |
| 202 |
+ |
if(!result) |
| 203 |
+ |
boost::throw_exception(bad_any_cast()); |
| 204 |
+ |
return *result; |
| 205 |
+ |
} |
| 206 |
|
|
| 208 |
– |
template<typename T> |
| 209 |
– |
bool equal_any_type(const any& operand) { |
| 207 |
|
|
| 208 |
< |
} |
| 208 |
> |
template<typename T> |
| 209 |
> |
bool equal_any_type(const any& operand) { |
| 210 |
|
|
| 211 |
+ |
} |
| 212 |
+ |
|
| 213 |
|
} |
| 214 |
|
|
| 215 |
|
// Copyright Kevlin Henney, 2000, 2001, 2002. All rights reserved. |