class ov::Any

Overview

This class represents an object to work with different types. More…

#include <any.hpp>

class Any
{
public:
    // structs

    template <typename T>
    struct EqualityComparable;
    template <typename... T>
    struct EqualityComparable<std::map<T...>>;
    template <typename... T>
    struct EqualityComparable<std::vector<T...>>;
    template <typename T>
    struct HasBaseMemberType;
    template <class T>
    struct Impl<T, typename std::enable_if<!std::is_convertible<T, std::shared_ptr<RuntimeAttribute>>::value>::type>;
    template <class T>
    struct Impl<T, typename std::enable_if<std::is_convertible<T, std::shared_ptr<RuntimeAttribute>>::value>::type>;
    template <class T, typename = void>
    struct Impl;
    template <typename>
    struct TupleToTypeIndex;
    template <typename... Args>
    struct TupleToTypeIndex<std::tuple<Args...>>;

    // classes

    class Base;

    // construction

    Any();
    Any(const Any& other);
    Any(Any&& other);

    template <
        typename T,
        typename std::enable_if<!std::is_same<decay_t<T>, Any>::value&&!std::is_abstract<decay_t<T>>::value&&!std::is_convertible<decay_t<T>, Base::Ptr>::value, bool>::type = true
        >
    Any(T&& value);

    Any(const char \* str);
    Any(const std::nullptr_t);

    // methods

    Any& operator = (const Any& other);
    Any& operator = (Any&& other);
    const std::type_info& type_info() const;
    bool empty() const;

    template <class T>
    bool is() const;

    template <class T>
    std::enable_if<std::is_convertible<T, std::shared_ptr<RuntimeAttribute>>::value, T>::type& as();

    template <class T>
    std::enable_if<!std::is_convertible<T, std::shared_ptr<RuntimeAttribute>>::value&&!std::is_same<T, std::string>::value&&std::is_default_constructible<T>::value&&(util::Istreamable<T>::value||util::Readable<T>::value), T>::type& as();

    template <class T>
    std::enable_if<!std::is_convertible<T, std::shared_ptr<RuntimeAttribute>>::value&&!std::is_same<T, std::string>::value&&(!std::is_default_constructible<T>::value||(!util::Istreamable<T>::value&&!util::Readable<T>::value)), T>::type& as();

    template <class T>
    std::enable_if<std::is_same<T, std::string>::value, T>::type& as();

    template <class T>
    const T& as() const;

    template <typename T>
    operator T& ();

    template <typename T>
    operator const T & () const;

    template <typename T>
    operator T& () const;

    bool operator == (const Any& other) const;
    bool operator == (const std::nullptr_t&) const;
    bool operator != (const Any& other) const;
    Base \* operator -> ();
    const Base \* operator -> () const;
    void print(std::ostream& stream) const;
    void read(std::istream& stream);
    Base \* get();
    const Base \* get() const;
    void \* addressof();
    const void \* addressof() const;

    template <typename T, typename... Args>
    static Any make(Args&&... args);
};

Detailed Documentation

This class represents an object to work with different types.

Construction

Any()

Default constructor.

Any(const Any& other)

Сopy constructor.

Parameters:

other

other Any object

Any(Any&& other)

Default move constructor.

Parameters:

other

other Any object

template <
    typename T,
    typename std::enable_if<!std::is_same<decay_t<T>, Any>::value&&!std::is_abstract<decay_t<T>>::value&&!std::is_convertible<decay_t<T>, Base::Ptr>::value, bool>::type = true
    >
Any(T&& value)

Constructor creates any with object.

Parameters:

T

Any type

value

object

Any(const char \* str)

Constructor creates string any from char *.

Parameters:

str

char array

Any(const std::nullptr_t)

Empty constructor.

Methods

Any& operator = (const Any& other)

Сopy assignment operator.

Parameters:

other

other Any object

Returns:

reference to the current object

Any& operator = (Any&& other)

Default move assignment operator.

Parameters:

other

other Any object

Returns:

reference to the current object

const std::type_info& type_info() const

Returns type info

Returns:

type info

bool empty() const

Checks that any contains a value

Returns:

false if any contains a value else false

template <class T>
bool is() const

Check that stored type can be casted to specified type. If internal type supports Base.

Parameters:

T

Type of value

Returns:

true if type of value is correct. Return false if any is empty

template <class T>
std::enable_if<std::is_convertible<T, std::shared_ptr<RuntimeAttribute>>::value, T>::type& as()

Dynamic cast to specified type

Parameters:

T

type

Returns:

casted object

template <class T>
std::enable_if<!std::is_convertible<T, std::shared_ptr<RuntimeAttribute>>::value&&!std::is_same<T, std::string>::value&&std::is_default_constructible<T>::value&&(util::Istreamable<T>::value||util::Readable<T>::value), T>::type& as()

Dynamic cast to specified type

Parameters:

T

type

Returns:

casted object

template <class T>
std::enable_if<!std::is_convertible<T, std::shared_ptr<RuntimeAttribute>>::value&&!std::is_same<T, std::string>::value&&(!std::is_default_constructible<T>::value||(!util::Istreamable<T>::value&&!util::Readable<T>::value)), T>::type& as()

Dynamic cast to specified type

Parameters:

T

type

Returns:

casted object

template <class T>
std::enable_if<std::is_same<T, std::string>::value, T>::type& as()

Dynamic cast to specified type

Parameters:

T

type

Returns:

casted object

template <class T>
const T& as() const

Dynamic cast to specified type

Parameters:

T

type

Returns:

const reference to caster object

template <typename T>
operator T& ()

Converts to specified type.

Parameters:

T

type

Returns:

casted object

template <typename T>
operator const T & () const

Converts to specified type.

Parameters:

T

type

Returns:

casted object

template <typename T>
operator T& () const

Converts to specified type.

Parameters:

T

type

Returns:

casted object

bool operator == (const Any& other) const

The comparison operator for the Any.

Parameters:

other

object to compare

Returns:

true if objects are equal

bool operator == (const std::nullptr_t&) const

The comparison operator for the Any.

Parameters:

other

object to compare

Returns:

true if objects are equal

bool operator != (const Any& other) const

The comparison operator for the Any.

Parameters:

other

object to compare

Returns:

true if objects aren’t equal

Base \* operator -> ()

Standard pointer operator.

Returns:

underlined interface

const Base \* operator -> () const

Standard pointer operator.

Returns:

underlined interface

void print(std::ostream& stream) const

Prints underlying object to the given output stream. Uses operator<< if it is defined, leaves stream unchanged otherwise. In case of empty any or nullptr stream immediately returns.

Parameters:

stream

Output stream object will be printed to.

void read(std::istream& stream)

Read into underlying object from the given input stream. Uses operator>> if it is defined, leaves stream unchanged otherwise. In case of empty any or nullptr stream immediately returns.

Parameters:

stream

Output stream object will be printed to.

Base \* get()

Return pointer to underlined interface.

Returns:

underlined interface

const Base \* get() const

Return pointer to underlined interface.

Returns:

underlined interface

void \* addressof()

Returns address to internal value if any is not empty and nullptr instead.

Returns:

address to internal stored value

const void \* addressof() const

Returns address to internal value if any is not empty and nullptr instead.

Returns:

address to internal stored value

template <typename T, typename... Args>
static Any make(Args&&... args)

Inplace value construction function.

Parameters:

T

Any type

Args

pack of paramter types passed to T constructor

args

pack of paramters passed to T constructor