siplasplas
A library for C++ reflection and introspection
|
Implements a type-erased object container with support for dynamic method and attribute invokation. More...
#include <siplasplas/typeerasure/any.hpp>
Public Types | |
using | Base = SimpleAny< Storage > |
using | Method = cpp::typeerasure::Function< FunctionsStorage, FunctionArgsStorage > |
using | Attribute = cpp::typeerasure::Field< AttributesStorage > |
Public Member Functions | |
MethodProxy | operator() (const std::string &name) |
Gives access to an object method. More... | |
ConstMethodProxy | operator() (const std::string &name) const |
Gives access to an object method. More... | |
AttributeProxy | operator[] (const std::string &name) |
ConstAttributeProxy | operator[] (const std::string &name) const |
bool | hasMethod (const std::string &name) const |
Checks if the object has a method with a given name. More... | |
bool | hasAttribute (const std::string &name) const |
Checks if the object has an attribute with a given name. More... | |
::cpp::SimpleAny< Storage > & | simpleAny () |
Returns the any object as a SimpleAny. | |
const ::cpp::SimpleAny< Storage > & | simpleAny () const |
Returns the any object as a SimpleAny. | |
Public Member Functions inherited from cpp::SimpleAny< Storage > | |
SimpleAny () | |
Constructs an empty SimpleAny. | |
SimpleAny (const cpp::typeerasure::TypeInfo &typeInfo) | |
Default constructs a value of the given type. More... | |
bool | empty () const |
Checks whether the any has an object hosted in or if is empty. More... | |
template<typename T , typename = std::enable_if_t< !std::is_base_of< SimpleAny, std::decay_t<T> >::value >> | |
SimpleAny (const T &value) | |
Constructs an any of type T from an lvalue of type T. More... | |
template<typename OtherStorage > | |
SimpleAny (const SimpleAny< OtherStorage > &other) | |
template<typename OtherStorage > | |
SimpleAny (SimpleAny< OtherStorage > &&other) | |
SimpleAny (const SimpleAny &other) | |
SimpleAny (SimpleAny &&other) | |
template<typename T > | |
bool | hasType () const |
Checks if the any has a value of type T. More... | |
template<typename T > | |
const std::decay_t< T > & | get () const |
Returns a readonly reference to the hosted object. More... | |
template<typename T > | |
std::decay_t< T > & | get () |
Returns a reference to the hosted object. More... | |
cpp::typeerasure::TypeInfo | typeInfo () const |
Returns the type information of the hosted type. | |
cpp::SimpleAny< cpp::NonOwningStorage > | getReference () |
Returns a reference any to the hosted object. | |
cpp::SimpleAny< cpp::ConstNonOwningStorage > | getReference () const |
Returns a const reference any to the hosted object. | |
template<typename T > | |
SimpleAny & | operator= (const T &value) |
Assigns a value of type T. More... | |
SimpleAny & | operator= (const SimpleAny &other) |
SimpleAny & | operator= (SimpleAny &&other) |
const Storage & | getStorage () const |
Returns the storage backend of the SimpleAny object. | |
Static Public Member Functions | |
template<typename Class , typename... Args> | |
static Any | create (Args &&...args) |
Static Public Member Functions inherited from cpp::SimpleAny< Storage > | |
template<typename T , typename... Args> | |
static SimpleAny | create (Args &&...args) |
Constructs a SimpleAny with an in-place constructed value of type T. More... | |
Implements a type-erased object container with support for dynamic method and attribute invokation.
cpp::Any extends the interface of cpp::SimpleAny to add dynamic manipulation of the object's interface. cpp::Any keeps track of a set of methods and attributes the instace has assigned, so it can behave as an instance of a class with its interface and associated data members:
The behavior is undefined if the user access a method or attribute the any object doesn't have
Storage | Storage for the type erased object |
FunctionsStorage | Storage for the type erased methods. Storage by default |
FunctionArgsStorage | Storage for the type erased method call arguments. FunctionsStorage by default |
AttributesStorage | Storage for the type erased attributes. Storage by default |
|
inline |
Checks if the object has an attribute with a given name.
name | name of the attribute |
|
inline |
Checks if the object has a method with a given name.
name | name of the method |
|
inline |
Gives access to an object method.
name | Name of the object. If the object has no method with that name, the behavior is undefined |
|
inline |
Gives access to an object method.
name | Name of the object. If the object has no method with that name, the behavior is undefined |