![]() |
Gorgon Game Engine
|
This class can hold any other information providing type erasure. More...
Public Member Functions | |
Any () | |
Default constructor. More... | |
Any (Any &&any) | |
Move constructor. More... | |
Any (const Any &any) | |
Copy constructor. More... | |
template<class T_ > | |
Any (const T_ &data) | |
Creates a new Any from the given data. More... | |
Any (const TMP::RTTS &typeinterface, void *data) | |
Unsafe! Constructs any from give raw data. More... | |
Any (void *data, const TMP::RTTS &typeinterface) | |
Unsafe! Constructs any from give raw data. More... | |
~Any () | |
Destructor. More... | |
void | AssumeRaw (TMP::RTTS &type, void *data) |
Unsafe! This function sets the raw data contained within any, while modifying its type data. More... | |
void | Clear () |
Clears the content of the any. More... | |
void * | Disown () |
Unsafe! Disowns the data contained in this any. More... | |
template<class T_ > | |
T_ & | Get () |
Returns the value contained with this any. More... | |
template<class T_ > | |
const T_ & | Get () const |
Returns the value contained with this any. More... | |
void * | GetRaw () const |
Unsafe! This function returns raw data contained within any. More... | |
std::string | GetTypeName () const |
bool | IsPointer () const |
Checks if any contains a pointer. More... | |
bool | IsSameType (const Any &other) const |
Checks whether the Any is the same type with the given type. More... | |
bool | IsSet () const |
Checks whether the Any is set. More... | |
bool | operator!= (const Any &content) const |
Compares two Any variables. More... | |
template<class T_ > | |
bool | operator!= (const T_ &content) const |
Compares the contents of this Any to the given value. More... | |
Any & | operator= (Any &&any) |
Moves the information in the given Any to this Any. More... | |
Any & | operator= (const Any &any) |
Copies the information in the given Any. More... | |
template<class T_ > | |
Any & | operator= (const T_ &value) |
Set the content of the Any to the given value. More... | |
bool | operator== (const Any &content) const |
Compares two Any variables. More... | |
template<class T_ > | |
bool | operator== (const T_ &content) const |
Compares the contents of this Any to the given value. More... | |
void * | Pointer () const |
Returns the pointer without type information. More... | |
template<class T_ > | |
void | Set (const T_ &data) |
Set the content of the Any to the given value. More... | |
template<class T_ > | |
void | Set (const T_ &data, TMP::RTTS *type) |
Unsafe! This function sets the data contained within any with regular means. More... | |
template<class T_ > | |
void | Set (T_ &&data) |
Set the content of the Any to the given value. More... | |
void | SetRaw (TMP::RTTS *type, void *data) |
Unsafe! This function sets the raw data contained within any, while modifying its type data. More... | |
void | SetRaw (void *data) |
Unsafe! This function sets the raw data contained within any, without modifying its type data. More... | |
void | SetType (const TMP::RTTS &type) |
Unsafe! This function modifies type information of the data content. More... | |
void | Swap (Any &other) |
Swaps the contents of the current any with another. More... | |
template<class T_ > | |
bool | TypeCheck () const |
Checks whether the Any is the same type with the given type. More... | |
TMP::RTTI & | TypeInfo () const |
Returns TypeInfo used by current data. More... | |
TMP::RTTS * | TypeServices () const |
Returns TypeInterface used by this any. More... | |
template<class T_ > | |
T_ | UnsafeGet () const |
Unsafe version of Get. More... | |
Protected Attributes | |
void * | content |
Data stored in this any. More... | |
TMP::RTTS * | type |
Type of the data stored. More... | |
This class can hold any other information providing type erasure.
It requires the type to be either copy constructible or move constructible. Type safety is ensured during debug using RTTI information.
This class only checks type safety in debug mode. In release it only checks for Any being empty. This check can also be removed if it causes bottleneck. Define GORGON_FAST_ANY to remove these checks.
Currently cannot work with object without copy constructor.
Unsafe! Constructs any from give raw data.
Both typeinterface and data are duplicated.
References RTTS::Clone(), Any::content, RTTS::Duplicate(), and Any::type.
Unsafe! Constructs any from give raw data.
typeinterface is duplicated. Ownership of data is taken.
References RTTS::Clone(), Any::content, RTTS::Duplicate(), and Any::type.
Any | ( | const T_ & | data | ) |
Copy constructor.
Requires type in the copied Any to be copy constructible.
References RTTS::Clone(), Any::content, RTTS::Duplicate(), and Any::type.
~Any | ( | ) |
Destructor.
References Any::Clear().
void AssumeRaw | ( | TMP::RTTS & | type, |
void * | data | ||
) |
Unsafe! This function sets the raw data contained within any, while modifying its type data.
type is duplicated, whereas data ownership is assumed.
References Any::Clear(), Any::content, RTTS::Duplicate(), and Any::type.
void Clear | ( | ) |
Clears the content of the any.
References Any::content, RTTS::Delete(), and Any::type.
void* Disown | ( | ) |
Unsafe! Disowns the data contained in this any.
The data is not freed. This function returns the raw pointer that is disowned
References Any::content, and Any::type.
T_& Get | ( | ) |
Returns the value contained with this any.
If this Any is not const, this method could be used to move the object out of Any. It can also be used to modify the value contained within this Any.
std::runtime_error | if Any is empty |
std::bad_cast | (debug only) if types do not match |
References ASSERT, Any::content, RTTI::IsSameType(), RTTI::Name(), and Any::type.
const T_& Get | ( | ) | const |
Returns the value contained with this any.
If this Any is not const, this method could be used to move the object out of Any. It can also be used to modify the value contained within this Any.
std::runtime_error | if Any is empty |
std::bad_cast | (debug only) if types do not match |
References ASSERT, Any::content, RTTI::IsSameType(), RTTI::Name(), and Any::type.
void* GetRaw | ( | ) | const |
Unsafe! This function returns raw data contained within any.
References Any::content.
std::string GetTypeName | ( | ) | const |
References Gorgon::Utils::demangle(), Any::type, and RTTI::TypeInfo().
bool IsPointer | ( | ) | const |
Checks if any contains a pointer.
References RTTI::IsPointer(), and Any::type.
bool IsSameType | ( | const Any & | other | ) | const |
Checks whether the Any is the same type with the given type.
References RTTI::IsSameType(), Any::type, and RTTI::TypeInfo().
bool IsSet | ( | ) | const |
Checks whether the Any is set.
References Any::content.
bool operator!= | ( | const Any & | content | ) | const |
Compares two Any variables.
std::bad_cast | if types do not match |
References Any::content, and Any::operator==().
bool operator!= | ( | const T_ & | content | ) | const |
Compares the contents of this Any to the given value.
The value should be the same type as this Any. Even if it is possible, no cross type comparison will be performed. You may use any.Get<originaltype>() == othertype_variable
std::runtime_error | if Any is empty |
std::bad_cast | (debug only) if types do not match |
References Any::content, and Any::operator==().
Moves the information in the given Any to this Any.
This function directly moves the pointer therefore, no copying or moving performed on the original type.
References Any::Clear(), and Any::Swap().
Copies the information in the given Any.
It requires type in the copied Any to be copy constructible.
References Any::Clear(), RTTS::Clone(), Any::content, RTTS::Duplicate(), and Any::type.
Any& operator= | ( | const T_ & | value | ) |
Set the content of the Any to the given value.
The value is duplicated. Requires T_ to be copy constructible.
bool operator== | ( | const Any & | content | ) | const |
Compares two Any variables.
std::bad_cast | (debug only) if types do not match |
References ASSERT, Any::content, RTTI::GetSize(), RTTI::Name(), Any::type, and RTTI::TypeInfo().
bool operator== | ( | const T_ & | content | ) | const |
Compares the contents of this Any to the given value.
The value should be the same type as this Any. Even if it is possible, no cross type comparison will be performed. You may use any.Get<originaltype>() == othertype_variable
std::runtime_error | if Any is empty |
std::bad_cast | (debug only) if types do not match |
References ASSERT, Any::content, RTTI::IsSameType(), RTTI::Name(), and Any::type.
void* Pointer | ( | ) | const |
Returns the pointer without type information.
References Any::content.
void Set | ( | const T_ & | data | ) |
Set the content of the Any to the given value.
The value is duplicated. Requires T_ to be copy constructible.
References Any::Clear().
void Set | ( | const T_ & | data, |
TMP::RTTS * | type | ||
) |
Unsafe! This function sets the data contained within any with regular means.
However, the type info is user supplied. Its primary aim is to be able to set pointer types from from void pointers. This can also be used as type casting.
References Any::Clear(), RTTS::Clone(), Any::content, RTTS::Duplicate(), and Any::type.
void Set | ( | T_ && | data | ) |
Set the content of the Any to the given value.
The value is moved. Requires T_ to be move constructible.
References Any::Clear().
void SetRaw | ( | TMP::RTTS * | type, |
void * | data | ||
) |
Unsafe! This function sets the raw data contained within any, while modifying its type data.
type and data are duplicated.
References Any::Clear(), RTTS::Clone(), Any::content, RTTS::Duplicate(), and Any::type.
void SetRaw | ( | void * | data | ) |
Unsafe! This function sets the raw data contained within any, without modifying its type data.
data is duplicated.
References RTTS::Clone(), Any::content, RTTS::Delete(), and Any::type.
void SetType | ( | const TMP::RTTS & | type | ) |
Unsafe! This function modifies type information of the data content.
type is duplicated
References RTTS::Duplicate(), and Any::type.
void Swap | ( | Any & | other | ) |
Swaps the contents of the current any with another.
Does not perform copying or moving.
References Any::content, Gorgon::swap(), and Any::type.
bool TypeCheck | ( | ) | const |
Checks whether the Any is the same type with the given type.
References RTTI::IsSameType(), and Any::type.
TMP::RTTI& TypeInfo | ( | ) | const |
T_ UnsafeGet | ( | ) | const |
Unsafe version of Get.
Should be used as last resort. Only const version is available.
std::runtime_error | if Any is empty |
References Any::content, and Any::type.
|
protected |
Data stored in this any.
|
protected |
Type of the data stored.