Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
us::Any Class Reference

An Any class represents a general type and is capable of storing any type, supporting type-safe extraction of the internally stored data. More...

#include <usAny.h>

Public Member Functions

 Any ()
 Creates an empty any type. More...
 
template<typename ValueType >
 Any (const ValueType &value)
 Creates an Any which stores the init parameter inside. More...
 
 Any (const Any &other)
 Copy constructor, works with empty Anys and initialized Any values. More...
 
 ~Any ()
 
Any & Swap (Any &rhs)
 Swaps the content of the two Anys. More...
 
template<typename ValueType >
Any & operator= (const ValueType &rhs)
 Assignment operator for all types != Any. More...
 
Any & operator= (const Any &rhs)
 Assignment operator for Any. More...
 
bool Empty () const
 Returns true if the Any is empty. More...
 
std::string ToString () const
 Returns a string representation for the content. If this Any is empty, returns an empty string. More...
 
std::string ToJSON () const
 Returns a JSON representation for the content. More...
 
const std::type_info & Type () const
 Returns the type information of the stored content. If the Any is empty typeid(void) is returned. It is suggested to always query an Any for its type info before trying to extract data via an any_cast/ref_any_cast. More...
 

Detailed Description

An Any class represents a general type and is capable of storing any type, supporting type-safe extraction of the internally stored data.

Code taken from the Boost 1.46.1 library. Original copyright by Kevlin Henney. Modified for CppMicroServices.

Definition at line 144 of file usAny.h.

Constructor & Destructor Documentation

◆ Any() [1/3]

us::Any::Any ( )
inline

Creates an empty any type.

Definition at line 151 of file usAny.h.

Referenced by operator=().

◆ Any() [2/3]

template<typename ValueType >
us::Any::Any ( const ValueType &  value)
inline

Creates an Any which stores the init parameter inside.

Parameters
valueThe content of the Any

Example:

Any a(13);
Any a(string("12345"));
Any()
Creates an empty any type.
Definition: usAny.h:151

Definition at line 166 of file usAny.h.

◆ Any() [3/3]

us::Any::Any ( const Any &  other)
inline

Copy constructor, works with empty Anys and initialized Any values.

Parameters
otherThe Any to copy

Definition at line 175 of file usAny.h.

◆ ~Any()

us::Any::~Any ( )
inline

Definition at line 179 of file usAny.h.

Member Function Documentation

◆ Empty()

bool us::Any::Empty ( ) const
inline

Returns true if the Any is empty.

Definition at line 227 of file usAny.h.

Referenced by ToJSON(), and ToString().

◆ operator=() [1/2]

Any& us::Any::operator= ( const Any &  rhs)
inline

Assignment operator for Any.

Parameters
rhsThe Any which should be assigned to this Any.

Definition at line 218 of file usAny.h.

References Any().

◆ operator=() [2/2]

template<typename ValueType >
Any& us::Any::operator= ( const ValueType &  rhs)
inline

Assignment operator for all types != Any.

Parameters
rhsThe value which should be assigned to this Any.

Example:

Any a = 13;
Any a = string("12345");

Definition at line 207 of file usAny.h.

References Any().

◆ Swap()

Any& us::Any::Swap ( Any &  rhs)
inline

Swaps the content of the two Anys.

Parameters
rhsThe Any to swap this Any with.

Definition at line 189 of file usAny.h.

References mitk::swap().

◆ ToJSON()

std::string us::Any::ToJSON ( ) const
inline

Returns a JSON representation for the content.

Custom types should specialize the any_value_to_json template function for meaningful output.

Definition at line 249 of file usAny.h.

References Empty().

◆ ToString()

std::string us::Any::ToString ( ) const
inline

Returns a string representation for the content. If this Any is empty, returns an empty string.

Custom types should either provide a std::ostream& operator<<(std::ostream& os, const CustomType& ct) function or specialize the any_value_to_string template function for meaningful output.

Definition at line 239 of file usAny.h.

References Empty().

◆ Type()

const std::type_info& us::Any::Type ( ) const
inline

Returns the type information of the stored content. If the Any is empty typeid(void) is returned. It is suggested to always query an Any for its type info before trying to extract data via an any_cast/ref_any_cast.

Definition at line 260 of file usAny.h.


The documentation for this class was generated from the following file: