Implements a type-erased object container with support for dynamic method and attribute invokation.
More...
|
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...
|
|
| SimpleAny () |
| Constructs an empty SimpleAny.
|
|
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) |
|
template<typename Storage, typename FunctionsStorage = Storage, typename FunctionArgsStorage = FunctionsStorage>
class cpp::Any< Storage, FunctionsStorage, FunctionArgsStorage >
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:
auto any = cpp::Any::create<MyClass>("hello");
any("method") = &MyCass::method;
any("method")("hello, "s, "world"s);
any["field"] = &MyClass::field;
any["field"] = 42;
The behavior is undefined if the user access a method or attribute the any object doesn't have
- Template Parameters
-
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 |