54 template<
typename Iterator>
59 const Iterator begin = i1;
60 for ( ; i1 != i2; ++i1)
72 template<
typename Iterator>
77 const Iterator begin = i1;
78 for ( ; i1 != i2; ++i1)
126 template<
class K,
class V>
132 template<
class K,
class V>
165 template <
typename ValueType>
166 Any(
const ValueType& value)
167 : _content(new Holder<ValueType>(value))
176 : _content(other._content ? other._content->Clone() : nullptr)
206 template <
typename ValueType>
209 Any(rhs).Swap(*
this);
220 Any(rhs).Swap(*
this);
241 return Empty() ? std::string() : _content->ToString();
251 return Empty() ?
"null" : _content->ToJSON();
260 const std::type_info&
Type()
const
262 return _content ? _content->Type() :
typeid(void);
270 virtual ~Placeholder()
273 virtual std::string
ToString()
const = 0;
274 virtual std::string
ToJSON()
const = 0;
276 virtual const std::type_info&
Type()
const = 0;
277 virtual Placeholder* Clone()
const = 0;
280 template <
typename ValueType>
281 class Holder:
public Placeholder
284 Holder(
const ValueType& value)
288 std::string
ToString()
const override
293 std::string
ToJSON()
const override
298 const std::type_info&
Type()
const override
300 return typeid(ValueType);
303 Placeholder* Clone()
const override
305 return new Holder(_held);
315 template <
typename ValueType>
318 template <
typename ValueType>
321 Placeholder* _content;
337 : std::bad_cast(), _msg(msg)
342 const char *
what()
const throw()
override
345 return "us::BadAnyCastException: "
346 "failed conversion using us::any_cast";
366 template <
typename ValueType>
369 return operand && operand->
Type() ==
typeid(ValueType)
370 ? &
static_cast<Any::Holder<ValueType>*
>(operand->_content)->_held
384 template <
typename ValueType>
387 return any_cast<ValueType>(
const_cast<Any*
>(operand));
402 template <
typename ValueType>
405 ValueType* result = any_cast<ValueType>(
const_cast<Any*
>(&operand));
422 template <
typename ValueType>
425 ValueType* result = any_cast<ValueType>(&operand);
438 template <
typename ValueType>
441 ValueType* result = any_cast<ValueType>(
const_cast<Any*
>(&operand));
442 if (!result)
throw BadAnyCastException(
"RefAnyCast: Failed to convert between const Any types");
454 template <
typename ValueType>
457 ValueType* result = any_cast<ValueType>(&operand);
471 template <
typename ValueType>
474 return &
static_cast<Any::Holder<ValueType>*
>(operand->_content)->_held;
486 template <
typename ValueType>
489 return any_cast<ValueType>(
const_cast<Any*
>(operand));
496 std::stringstream ss;
498 typedef typename std::map<K, Any>::const_iterator Iterator;
499 Iterator i1 = m.begin();
500 const Iterator begin = i1;
501 const Iterator end = m.end();
502 for ( ; i1 != end; ++i1)
504 if (i1 == begin) ss << i1->first <<
" : " << i1->second.ToString();
505 else ss <<
", " << i1->first <<
" : " << i1->second.ToString();
511 template<
class K,
class V>
514 std::stringstream ss;
516 typedef typename std::map<K, V>::const_iterator Iterator;
517 Iterator i1 = m.begin();
518 const Iterator begin = i1;
519 const Iterator end = m.end();
520 for ( ; i1 != end; ++i1)
522 if (i1 == begin) ss << i1->first <<
" : " << i1->second;
523 else ss <<
", " << i1->first <<
" : " << i1->second;
532 std::stringstream ss;
534 typedef typename std::map<K, Any>::const_iterator Iterator;
535 Iterator i1 = m.begin();
536 const Iterator begin = i1;
537 const Iterator end = m.end();
538 for ( ; i1 != end; ++i1)
540 if (i1 == begin) ss <<
"\"" << i1->first <<
"\" : " << i1->second.ToJSON();
541 else ss <<
", " <<
"\"" << i1->first <<
"\" : " << i1->second.ToJSON();
547 template<
class K,
class V>
550 std::stringstream ss;
552 typedef typename std::map<K, V>::const_iterator Iterator;
553 Iterator i1 = m.begin();
554 const Iterator begin = i1;
555 const Iterator end = m.end();
556 for ( ; i1 != end; ++i1)
558 if (i1 == begin) ss <<
"\"" << i1->first <<
"\" : " << i1->second;
559 else ss <<
", " <<
"\"" << i1->first <<
"\" : " << i1->second;
#define MITKCPPMICROSERVICES_EXPORT
An Any class represents a general type and is capable of storing any type, supporting type-safe extra...
Any & Swap(Any &rhs)
Swaps the content of the two Anys.
Any & operator=(const ValueType &rhs)
Assignment operator for all types != Any.
friend ValueType * unsafe_any_cast(Any *)
bool Empty() const
Returns true if the Any is empty.
Any(const Any &other)
Copy constructor, works with empty Anys and initialized Any values.
Any(const ValueType &value)
Creates an Any which stores the init parameter inside.
std::string ToJSON() const
Returns a JSON representation for the content.
const std::type_info & Type() const
Returns the type information of the stored content. If the Any is empty typeid(void) is returned....
std::string ToString() const
Returns a string representation for the content. If this Any is empty, returns an empty string.
Any()
Creates an empty any type.
friend ValueType * any_cast(Any *)
any_cast operator used to extract the ValueType from an Any*. Will return a pointer to the stored val...
Exception thrown when an any_cast fails due to a type mismatch.
const char * what() const override
BadAnyCastException(const std::string &msg="")
~BadAnyCastException() override
void swap(CustomMimeType &l, CustomMimeType &r)
Swap two CustomMimeType objects.
std::string container_to_json(Iterator i1, Iterator i2)
std::string container_to_string(Iterator i1, Iterator i2)
ValueType * any_cast(Any *operand)
any_cast operator used to extract the ValueType from an Any*. Will return a pointer to the stored val...
MITKCPPMICROSERVICES_EXPORT std::string any_value_to_json(const Any &val)
ValueType * unsafe_any_cast(Any *operand)
MITKCPPMICROSERVICES_EXPORT std::string any_value_to_string(const Any &any)
const ValueType & ref_any_cast(const Any &operand)
ref_any_cast operator used to return a const reference to the internal data.