ArkScript
A small, fast, functional and scripting language for video games
Ark::UserType Class Reference

A class to be use C++ objects in ArkScript. More...

#include <UserType.hpp>

+ Collaboration diagram for Ark::UserType:

Classes

struct  ControlFuncs
 A structure holding a bunch of pointers to different useful functions related to this usertype. More...
 

Public Member Functions

template<typename T >
 UserType (T *data=nullptr, ControlFuncs *block=nullptr) noexcept
 Construct a new User Type object.
 
void del ()
 Free memory through the control functions block.
 
void * data () const noexcept
 Get the pointer to the object.
 
template<typename T >
bool is () const noexcept
 Check if the object held is of a given type.
 
template<typename T >
T & as () noexcept
 Return the underlying object as a given type.
 
template<typename T >
const T & as () const noexcept
 

Private Attributes

uint16_t m_type_id
 
void * m_data
 
ControlFuncsm_funcs
 

Friends

ARK_API bool operator== (const UserType &A, const UserType &B) noexcept
 
ARK_API bool operator< (const UserType &A, const UserType &B) noexcept
 
ARK_API std::ostream & operator<< (std::ostream &os, const UserType &A) noexcept
 

Detailed Description

A class to be use C++ objects in ArkScript.

A pointer to the value you want to store must be sent, thus the value must not be destroyed while the UserType lives, otherwise it would result in an UB when trying to use the object

Definition at line 49 of file UserType.hpp.

Constructor & Destructor Documentation

◆ UserType()

template<typename T >
Ark::UserType::UserType ( T *  data = nullptr,
ControlFuncs block = nullptr 
)
inlineexplicitnoexcept

Construct a new User Type object.

Template Parameters
Tthe type of the pointer
Parameters
dataa pointer to the data to store in the object

Definition at line 69 of file UserType.hpp.

Member Function Documentation

◆ as() [1/2]

template<typename T >
const T & Ark::UserType::as ( ) const
inlinenoexcept

Definition at line 126 of file UserType.hpp.

References m_data.

◆ as() [2/2]

template<typename T >
T & Ark::UserType::as ( )
inlinenoexcept

Return the underlying object as a given type.

Template Parameters
Tthe type in which the underlying data pointer should be converted to
Returns
T&

Definition at line 120 of file UserType.hpp.

References m_data.

◆ data()

void * Ark::UserType::data ( ) const
inlinenoexcept

Get the pointer to the object.

Returns
void*

Definition at line 86 of file UserType.hpp.

References m_data.

◆ del()

void Ark::UserType::del ( )

Free memory through the control functions block.

Definition at line 5 of file UserType.cpp.

References Ark::UserType::ControlFuncs::deleter, m_data, and m_funcs.

◆ is()

template<typename T >
bool Ark::UserType::is ( ) const
inlinenoexcept

Check if the object held is of a given type.

Usage example:

MyType object;
UserType a(&object);
if (a.is<MyType>())
// then ...
else
// otherwise...
A class to be use C++ objects in ArkScript.
Definition: UserType.hpp:50
Template Parameters
Tthe type to use for the test
Returns
true
false

Definition at line 108 of file UserType.hpp.

References m_type_id.

Friends And Related Function Documentation

◆ operator<

ARK_API bool operator< ( const UserType A,
const UserType B 
)
friend

Definition at line 16 of file UserType.cpp.

◆ operator<<

ARK_API std::ostream & operator<< ( std::ostream &  os,
const UserType A 
)
friend

Definition at line 21 of file UserType.cpp.

◆ operator==

ARK_API bool operator== ( const UserType A,
const UserType B 
)
friend

Definition at line 11 of file UserType.cpp.

Member Data Documentation

◆ m_data

void* Ark::UserType::m_data
private

Definition at line 137 of file UserType.hpp.

Referenced by as(), data(), and del().

◆ m_funcs

ControlFuncs* Ark::UserType::m_funcs
private

Definition at line 138 of file UserType.hpp.

Referenced by del().

◆ m_type_id

uint16_t Ark::UserType::m_type_id
private

Definition at line 136 of file UserType.hpp.

Referenced by is().


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