44 #include <usCoreConfig.h>
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>
195 : _content(other._content ? other._content->
Clone() : 0)
225 template <
typename ValueType>
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
306 virtual std::string ToString()
const override
311 virtual std::string ToJSON()
const override
316 virtual const std::type_info& Type()
const override
321 virtual 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 virtual 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>
380 ? &
static_cast<Any::Holder<ValueType>*
>(operand->_content)->_held
394 template <
typename ValueType>
412 template <
typename ValueType>
432 template <
typename ValueType>
448 template <
typename ValueType>
452 if (!result)
throw BadAnyCastException(
"RefAnyCast: Failed to convert between const Any types");
464 template <
typename ValueType>
481 template <
typename ValueType>
484 return &
static_cast<Any::Holder<ValueType>*
>(operand->_content)->_held;
496 template <
typename ValueType>
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;
const std::type_info & Type() const
virtual const char * what() const override
std::string ToJSON() const
std::string container_to_json(Iterator i1, Iterator i2)
Any(const ValueType &value)
ValueType
Type of the value held by a Value object.
std::string any_value_to_json(const std::map< K, Any > &m)
std::string container_to_string(Iterator i1, Iterator i2)
std::string ToString() const
ValueType & ref_any_cast(Any &operand)
const ValueType * unsafe_any_cast(const Any *operand)
static void swap(T &x, T &y)
std::string any_value_to_string(const std::map< K, Any > &m)
ValueType any_cast(Any &operand)
BadAnyCastException(const std::string &msg="")