DynaMix  1.3.7
A new take on polymorphism in C++
dynamix::object Class Reference

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.
 
objectoperator= (object &&o) noexcept
 Move assignment.
 
 object (const object &o)=delete
 
objectoperator= (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_allocatorallocator () 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.
 

Detailed Description

The main object class.

Member Function Documentation

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,

bool dynamix::object::copyable ( ) const
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).

template<typename Mixin >
Mixin* dynamix::object::get ( )
inlinenoexcept

Gets a specific mixin from the object. Returns nullptr if the mixin isn't available.

template<typename Mixin >
const Mixin* dynamix::object::get ( ) const
inlinenoexcept

Gets a specific mixin from the object. Returns nullptr if the mixin isn't available.

bool dynamix::object::has ( const char *  mixin_name) const
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).

void* dynamix::object::get ( mixin_id  id)
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.

const void* dynamix::object::get ( mixin_id  id) const
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.

void* dynamix::object::get ( const char *  mixin_name)
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.

const void* dynamix::object::get ( const char *  mixin_name) const
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.

template<typename Feature >
bool dynamix::object::implements_by_mixin ( const Feature *  ) const
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.

template<typename Feature >
bool dynamix::object::implements_with_default ( const Feature *  ) const
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

std::pair<char*, size_t> dynamix::object::hard_replace_mixin ( mixin_id  id,
char *  buffer,
size_t  mixin_offset 
)
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


The documentation for this class was generated from the following file: