1 #ifndef SIPLASPLAS_TYPEERASURE_ANY_HPP 2 #define SIPLASPLAS_TYPEERASURE_ANY_HPP 4 #include "simpleany.hpp" 5 #include "function.hpp" 7 #include <siplasplas/utility/hash.hpp> 43 typename FunctionsStorage = Storage,
44 typename FunctionArgsStorage = FunctionsStorage,
45 typename AttributesStorage = FunctionsStorage
56 template<
typename Class,
typename... Args>
57 static Any create(Args&&... args)
70 template<
typename... Args>
73 return (*_method)(_this->getReference(), std::forward<Args>(args)...);
76 template<
typename... Args>
79 return (*_method)(_this->getReference(), std::forward<Args>(args)...);
82 template<
typename Callable>
83 MethodProxy&
operator=(Callable&& callable)
85 *_method = std::forward<Callable>(callable);
89 const Method& method()
const 104 class ConstMethodProxy
107 ConstMethodProxy(
const Method& method,
const Any* this_) :
112 template<
typename... Args>
115 return (*_method)(_this->getReference(), std::forward<Args>(args)...);
118 const Method& method()
const 132 _attribute{&attribute},
136 template<
typename Invokable>
138 cpp::function_kind<std::decay_t<Invokable>>() == cpp::FunctionKind::MEMBER_OBJECT,
141 operator=(Invokable&& invokable)
143 (*_attribute) = std::forward<Invokable>(invokable);
149 cpp::function_kind<std::decay_t<T>>() != cpp::FunctionKind::MEMBER_OBJECT,
154 get<std::decay_t<T>>() = std::forward<T>(value);
161 return _attribute->template getAs<T>(_this->simpleAny());
173 return _attribute->template getAs<T>(_this->simpleAny());
177 operator const T&()
const 197 class ConstAttributeProxy
200 ConstAttributeProxy(
const Attribute& attribute,
const Any* this_) :
201 _attribute{&attribute},
208 return _attribute->template getAs<T>(_this->simpleAny());
212 operator const T&()
const 239 return {_methods[name],
this};
254 return {_methods[name],
this};
257 AttributeProxy operator[](
const std::string& name)
259 return {_attributes[name],
this};
262 ConstAttributeProxy operator[](
const std::string& name)
const 265 return {_attributes[name],
this};
277 auto it = _methods.find(name);
279 if(it != _methods.end())
281 return !it->second.empty();
298 auto it = _attributes.find(name);
300 if(it != _attributes.end())
302 return !it->second.empty();
369 #endif // SIPLASPLAS_TYPEERASURE_ANY_HPP ::cpp::SimpleAny< Storage > & simpleAny()
Returns the any object as a SimpleAny.
Definition: any.hpp:313
SimpleAny & operator=(const T &value)
Assigns a value of type T.
Definition: simpleany.hpp:535
const ::cpp::SimpleAny< Storage > & simpleAny() const
Returns the any object as a SimpleAny.
Definition: any.hpp:321
Definition: canary_allocator.hpp:7
Stores a type erased member object pointer.
Definition: field.hpp:25
cpp::typeerasure::TypeInfo typeInfo() const
Returns the type information of the hosted type.
Definition: simpleany.hpp:503
bool hasMethod(const std::string &name) const
Checks if the object has a method with a given name.
Definition: any.hpp:275
std::unordered_map< Key, Value, Hash< Key >> HashTable
std::unordered_map alias using cpp::Hash as hash.
Definition: hash.hpp:240
ConstMethodProxy operator()(const std::string &name) const
Gives access to an object method.
Definition: any.hpp:251
Implements a type-erased value container with minimal value semantics requirements.
Definition: simpleany.hpp:15
MethodProxy operator()(const std::string &name)
Gives access to an object method.
Definition: any.hpp:237
bool hasAttribute(const std::string &name) const
Checks if the object has an attribute with a given name.
Definition: any.hpp:296
const char * typeName() const
Returns the name of the type.
Definition: typeinfo.hpp:134
Implements a type-erased object container with support for dynamic method and attribute invokation...
Definition: any.hpp:47
Stores a type-erased callable of any signature and kind.
Definition: function.hpp:58
#define SIPLASPLAS_ASSERT(...)
Defines an assertion expression.
Definition: assert.hpp:212