73 template<
typename Iterator>
78 const Iterator begin = i1;
79 for ( ; i1 != i2; ++i1)
91 template<
typename Iterator>
96 const Iterator begin = i1;
97 for ( ; i1 != i2; ++i1)
145 template<
class K,
class V>
151 template<
class K,
class V>
184 template <
typename ValueType>
185 Any(
const ValueType& value)
186 : _content(new Holder<ValueType>(value))
195 : _content(other._content ? other._content->Clone() : nullptr)
225 template <
typename ValueType>
226 Any& operator = (
const ValueType& rhs)
259 return _content->ToString();
269 return Empty() ?
"null" : _content->ToJSON();
278 const std::type_info&
Type()
const
280 return _content ? _content->Type() :
typeid(void);
288 virtual ~Placeholder()
291 virtual std::string ToString()
const = 0;
292 virtual std::string
ToJSON()
const = 0;
294 virtual const std::type_info& Type()
const = 0;
295 virtual Placeholder* Clone()
const = 0;
298 template <
typename ValueType>
299 class Holder:
public Placeholder
302 Holder(
const ValueType& value)
306 std::string ToString()
const override
311 std::string
ToJSON()
const override
316 const std::type_info& Type()
const override
318 return typeid(ValueType);
321 Placeholder* Clone()
const override
323 return new Holder(_held);
329 Holder& operator=(
const Holder &);
333 template <
typename ValueType>
336 template <
typename ValueType>
339 Placeholder* _content;
347 : std::bad_cast(), _msg(msg)
352 const char *
what()
const throw()
override
355 return "US_PREPEND_NAMESPACE(BadAnyCastException): "
356 "failed conversion using US_PREPEND_NAMESPACE(any_cast)";
376 template <
typename ValueType>
379 return operand && operand->
Type() ==
typeid(ValueType)
380 ? &
static_cast<Any::Holder<ValueType>*
>(operand->_content)->_held
394 template <
typename ValueType>
397 return any_cast<ValueType>(
const_cast<Any*
>(operand));
412 template <
typename ValueType>
415 ValueType* result = any_cast<ValueType>(
const_cast<Any*
>(&operand));
432 template <
typename ValueType>
435 ValueType* result = any_cast<ValueType>(&operand);
448 template <
typename ValueType>
451 ValueType* result = any_cast<ValueType>(
const_cast<Any*
>(&operand));
452 if (!result)
throw BadAnyCastException(
"RefAnyCast: Failed to convert between const Any types");
464 template <
typename ValueType>
467 ValueType* result = any_cast<ValueType>(&operand);
481 template <
typename ValueType>
484 return &
static_cast<Any::Holder<ValueType>*
>(operand->_content)->_held;
496 template <
typename ValueType>
499 return any_cast<ValueType>(
const_cast<Any*
>(operand));
506 std::stringstream ss;
508 typedef typename std::map<K, Any>::const_iterator Iterator;
509 Iterator i1 = m.begin();
510 const Iterator begin = i1;
511 const Iterator end = m.end();
512 for ( ; i1 != end; ++i1)
514 if (i1 == begin) ss << i1->first <<
" : " << i1->second.ToString();
515 else ss <<
", " << i1->first <<
" : " << i1->second.ToString();
521 template<
class K,
class V>
524 std::stringstream ss;
526 typedef typename std::map<K, V>::const_iterator Iterator;
527 Iterator i1 = m.begin();
528 const Iterator begin = i1;
529 const Iterator end = m.end();
530 for ( ; i1 != end; ++i1)
532 if (i1 == begin) ss << i1->first <<
" : " << i1->second;
533 else ss <<
", " << i1->first <<
" : " << i1->second;
542 std::stringstream ss;
544 typedef typename std::map<K, Any>::const_iterator Iterator;
545 Iterator i1 = m.begin();
546 const Iterator begin = i1;
547 const Iterator end = m.end();
548 for ( ; i1 != end; ++i1)
550 if (i1 == begin) ss <<
"\"" << i1->first <<
"\" : " << i1->second.ToJSON();
551 else ss <<
", " <<
"\"" << i1->first <<
"\" : " << i1->second.ToJSON();
557 template<
class K,
class V>
560 std::stringstream ss;
562 typedef typename std::map<K, V>::const_iterator Iterator;
563 Iterator i1 = m.begin();
564 const Iterator begin = i1;
565 const Iterator end = m.end();
566 for ( ; i1 != end; ++i1)
568 if (i1 == begin) ss <<
"\"" << i1->first <<
"\" : " << i1->second;
569 else ss <<
", " <<
"\"" << i1->first <<
"\" : " << i1->second;