 |
Gorgon Game Engine
|
Go to the documentation of this file.
58 using Type =
typename std::decay<T_>::type;
59 static_assert(!std::is_same<
typename std::decay<
typename std::remove_reference<T_>::type>::
type,
Any>::value,
60 "Something is wrong in here");
131 static_assert(!std::is_same<
typename std::decay<
typename std::remove_reference<T_>::type>::
type,
Any>::value,
132 "Something is wrong in here");
151 void Set(
const T_ &data) {
154 using Type =
typename std::decay<T_>::type;
167 using Type =
typename std::decay<T_>::type;
247 if(this->type)
delete this->
type;
259 #ifndef GORGON_FAST_ANY
261 throw std::runtime_error(
"Any storage is empty");
265 "Type mismatch, orginal: "+
type->
Name()+
", target: "+Utils::GetTypeName<T_>()
269 return *
static_cast<T_*
>(
content);
286 #ifndef GORGON_FAST_ANY
288 throw std::runtime_error(
"Any storage is empty");
292 "Type mismatch, orginal: "+
type->
Name()+
", target: "+Utils::GetTypeName<T_>()
296 return *
static_cast<T_*
>(
content);
306 #ifndef GORGON_FAST_ANY
308 throw std::runtime_error(
"Any storage is empty");
312 return *
static_cast<T_*
>(
content);
333 return *
reinterpret_cast<void**
>(
content);
345 #ifndef GORGON_FAST_ANY
346 if(!
type || !this->content) {
347 throw std::runtime_error(
"Any storage is empty");
351 "Type mismatch, orginal: "+
type->
Name()+
", target: "+Utils::GetTypeName<T_>()
355 return *
static_cast<T_*
>(this->
content)==content;
362 if(!
content.content && !this->content) {
365 else if(!
content.content || !this->content) {
369 #ifndef GORGON_FAST_ANY
420 virtual ~CopyFreeAny() {}
423 T_ &GetData()
const {
424 return *
reinterpret_cast<T_*
>(data);
431 struct CopyFreeAny_impl :
public CopyFreeAny {
432 CopyFreeAny_impl(T_ data) : mydata(std::move(data)) {
433 this->data = &mydata;
436 CopyFreeAny_impl(
const CopyFreeAny_impl &) =
delete;
438 CopyFreeAny_impl(CopyFreeAny_impl &&other) {
439 mydata = std::move(other.data);
442 CopyFreeAny_impl &operator =(CopyFreeAny_impl &&other) {
443 mydata = std::move(other.data);
448 CopyFreeAny_impl &operator =(
const CopyFreeAny_impl &other) =
delete;
450 virtual ~CopyFreeAny_impl() {}
457 CopyFreeAny &MakeCopyFreeAny(T_ data) {
458 return *
new CopyFreeAny_impl<T_>(std::move(data));
void swap(Event< Source_, Args_... > &l, Event< Source_, Args_... > &r)
Swaps two events.
Definition: Event.h:351
void Swap(Any &other)
Swaps the contents of the current any with another.
Definition: Any.h:141
Any(const TMP::RTTS &typeinterface, void *data)
Unsafe! Constructs any from give raw data.
Definition: Any.h:40
void * content
Data stored in this any.
Definition: Any.h:411
bool operator!=(const T_ &content) const
Compares the contents of this Any to the given value.
Definition: Any.h:385
Runtime Type. This class implements both RTTS and RTTI.
Definition: TMP.h:210
void * GetRaw() const
Unsafe! This function returns raw data contained within any.
Definition: Any.h:187
This class can hold any other information providing type erasure.
Definition: Any.h:32
Any()
Default constructor.
Definition: Any.h:36
Any(Any &&any)
Move constructor.
Definition: Any.h:82
Any(const T_ &data)
Creates a new Any from the given data.
Definition: Any.h:57
T_ UnsafeGet() const
Unsafe version of Get.
Definition: Any.h:305
void SetRaw(void *data)
Unsafe! This function sets the raw data contained within any, without modifying its type data.
Definition: Any.h:194
This file contains template metaprogramming methods and classes used throughout Gorgon Library.
void * Disown()
Unsafe! Disowns the data contained in this any.
Definition: Any.h:234
virtual long GetSize() const =0
Returns the size of the object.
virtual const std::type_info & TypeInfo() const =0
virtual bool IsPointer() const =0
Returns if this type is pointer.
void SetType(const TMP::RTTS &type)
Unsafe! This function modifies type information of the data content.
Definition: Any.h:246
Root namespace for Gorgon Game Engine.
Definition: Any.h:19
~Any()
Destructor.
Definition: Any.h:404
bool operator==(const T_ &content) const
Compares the contents of this Any to the given value.
Definition: Any.h:344
TMP::RTTS * type
Type of the data stored.
Definition: Any.h:414
void Clear()
Clears the content of the any.
Definition: Any.h:176
bool IsSameType(const Any &other) const
Checks whether the Any is the same type with the given type.
Definition: Any.h:322
#define ASSERT(expression, message,...)
Replaces regular assert to allow messages and backtrace.
Definition: Assert.h:161
TMP::RTTI & TypeInfo() const
Returns TypeInfo used by current data.
Definition: Any.h:87
virtual void Delete(void *obj) const =0
Deletes the given object.
bool IsPointer() const
Checks if any contains a pointer.
Definition: Any.h:327
void Set(T_ &&data)
Set the content of the Any to the given value.
Definition: Any.h:163
This class contains runtime type services that allows dealing with unknown type.
Definition: TMP.h:190
const T_ & Get() const
Returns the value contained with this any.
Definition: Any.h:285
void Set(const T_ &data)
Set the content of the Any to the given value.
Definition: Any.h:151
This class contains information about a runtime type.
Definition: TMP.h:143
virtual RTTS * Duplicate() const =0
Duplicates this service.
void Set(const T_ &data, TMP::RTTS *type)
Unsafe! This function sets the data contained within any with regular means.
Definition: Any.h:215
virtual void * Clone(const void *const obj) const =0
Clones the given object.
std::string Name() const
Returns human readable name of the type.
Definition: TMP.h:184
Type
Definition: Shader.h:14
void * Pointer() const
Returns the pointer without type information.
Definition: Any.h:332
virtual bool IsSameType(const std::type_info &) const =0
Compares the type stored with this service to the given type info.
void AssumeRaw(TMP::RTTS &type, void *data)
Unsafe! This function sets the raw data contained within any, while modifying its type data.
Definition: Any.h:225
void SetRaw(TMP::RTTS *type, void *data)
Unsafe! This function sets the raw data contained within any, while modifying its type data.
Definition: Any.h:203
Any(const Any &any)
Copy constructor.
Definition: Any.h:68
bool TypeCheck() const
Checks whether the Any is the same type with the given type.
Definition: Any.h:317
T_ & Get()
Returns the value contained with this any.
Definition: Any.h:258
Any & operator=(const Any &any)
Copies the information in the given Any.
Definition: Any.h:101
bool IsSet() const
Checks whether the Any is set.
Definition: Any.h:398
std::string GetTypeName() const
Definition: Any.h:272
Any(void *data, const TMP::RTTS &typeinterface)
Unsafe! Constructs any from give raw data.
Definition: Any.h:48
std::string demangle(const std::string &name)
Definition: Compiler_GCC.cpp:8
TMP::RTTS * TypeServices() const
Returns TypeInterface used by this any.
Definition: Any.h:94