DynaMix
1.3.7
A new take on polymorphism in C++
|
The main object class. More...
#include <object.hpp>
Public Member Functions | |
object () noexcept | |
Constructs an empty object - no mixins. | |
object (object_allocator *allocator) | |
Constructs an object with an object allocator. | |
object (const object_type_template &type_template, object_allocator *allocator=nullptr) | |
Constructs an object from a specific type template. | |
object (object &&o) noexcept | |
Move constructor from an existing object. | |
object & | operator= (object &&o) noexcept |
Move assignment. | |
object (const object &o)=delete | |
object & | operator= (const object &o)=delete |
object | copy () const |
void | copy_from (const object &o) |
void | copy_matching_from (const object &o) |
bool | copyable () const noexcept |
template<typename Mixin > | |
bool | has () const noexcept |
Checks if the object has a specific mixin. | |
template<typename Mixin > | |
Mixin * | get () noexcept |
template<typename Mixin > | |
const Mixin * | get () const noexcept |
bool | has (mixin_id id) const noexcept |
Checks if the object has a specific mixin by id. | |
bool | has (const char *mixin_name) const noexcept |
void * | get (mixin_id id) noexcept |
const void * | get (mixin_id id) const noexcept |
void * | get (const char *mixin_name) noexcept |
const void * | get (const char *mixin_name) const noexcept |
template<typename Feature > | |
bool | implements (const Feature *) const noexcept |
Checks if the object implements a feature. | |
template<typename Feature > | |
bool | implements_by_mixin (const Feature *) const noexcept |
template<typename Feature > | |
bool | implements_with_default (const Feature *) const noexcept |
template<typename Feature > | |
size_t | num_implementers (const Feature *) const noexcept |
Returns the number of mixins in the object which implement a feature. | |
void | clear () noexcept |
Destroys all mixins within an object and resets its type info. | |
bool | empty () const noexcept |
Returns true if the object is empty - has no mixins. | |
object_allocator * | allocator () const |
Returns the allcator associated with this object (may be nullptr ) | |
std::pair< char *, size_t > | move_mixin (mixin_id id, char *buffer, size_t mixin_offset) |
std::pair< char *, size_t > | hard_replace_mixin (mixin_id id, char *buffer, size_t mixin_offset) noexcept |
void | reallocate_mixins () |
void | get_message_names (std::vector< const char * > &out_message_names) const |
Adds the names of the messages implemented by the object to the vector. | |
void | get_mixin_names (std::vector< const char * > &out_mixin_names) const |
Adds the names of the object's mixins to the vector. | |
The main object class.
object dynamix::object::copy | ( | ) | const |
Explicit copy via move assignment This function is not recommended as it will slice the type if you have a class inherited from object
void dynamix::object::copy_from | ( | const object & | o | ) |
Explicit assignment from existing object. Will also change the type of the target to the source type. Will call assignment operators for mixins that exist in both. Will copy-construct new mixins for this. Will destroy mixins that don't exist in source. It will not, however, match asssignment operators for different mixin types which have such defined between them,
void dynamix::object::copy_matching_from | ( | const object & | o | ) |
Assignment of mixins that exist in both objects. Will not change the type of the target. Will call assignment operators for mixins that exist in both objects. It will not, however, match asssignment operators for different mixin types which have such defined between them,
|
noexcept |
Checks whether all of the object's mixins have copy-constructors and assignment operators. Returns false if either is missing from at least one of its mixins (note that there might be cases where copy_from or copy_matching_from won't throw even though this function returns false).
|
inlinenoexcept |
Gets a specific mixin from the object. Returns nullptr if the mixin isn't available.
|
inlinenoexcept |
Gets a specific mixin from the object. Returns nullptr if the mixin isn't available.
|
noexcept |
Checks if the object has a specific mixin by mixin name (name of the class or manual name provided by the mixin_name
feature).
|
noexcept |
Gets a specific mixin by id from the object. Returns nullptr if the mixin isn't available. It is the user's responsibility to cast the returned value to the appropriate type.
|
noexcept |
Gets a specific mixin by id from the object. Returns nullptr if the mixin isn't available. It is the user's responsibility to cast the returned value to the appropriate type.
|
noexcept |
Gets a specific mixin by mixin name from the object. Returns nullptr if the mixin isn't available. It is the user's responsibility to cast the returned value to the appropriate type.
The mixin name is the name of the actual mixin class or a manual name provided by the mixin_name
feature.
|
noexcept |
Gets a specific mixin by mixin name from the object. Returns nullptr if the mixin isn't available. It is the user's responsibility to cast the returned value to the appropriate type.
The mixin name is the name of the actual mixin class or a manual name provided by the mixin_name
feature.
|
inlinenoexcept |
Checks if the object implements a feature by a mixin. Note that on false
the object might still implement the feature but with a default implementation.
|
inlinenoexcept |
Checks if the object implements a feature with a default implementation (false
means that it either does not implement it at all, or it's implemented by a mixin)
std::pair<char*, size_t> dynamix::object::move_mixin | ( | mixin_id | id, |
char * | buffer, | ||
size_t | mixin_offset | ||
) |
Moves a mixin to the designated buffer, by invocating its move constructor. Throws an exception if the mixin is not movable. Returns the old mixin buffer and offset or {nullptr, 0} if the object doesn't have such mixin The library never calls this function internally. Unless the user calls it, an object's mixins will always have the same addresses
|
noexcept |
Replaces a mixin's buffer with another. Returns the old buffer and offset. WARNING: if the Mixin is not part of the object, this function will crash! Will not touch the new buffer. It's the user's responsibility to set the appropriate object inside. The library never calls this function internally. Unless the user calls it, an object's mixins will always have the same addresses
void dynamix::object::reallocate_mixins | ( | ) |
Allocates buffers for all mixins and deallocates the old ones. Suitable to call from object allocators which keep a single mixin buffer per object. The order is for each mixin: { allocate new; deallocate old; } The library never calls this function internally. Unless the user calls it, an object's mixins will always have the same addresses