Storing Script Objects
Sometimes you may want to store script objects and use them later, or to implement your own container for script objects. There are some tools provided by asbind20 for storing script objects.
Storing a Single Script Object
-
class single
A set of helper for storing a single script object.
Get the address of the data
This can be used to implemented a function that return reference of data to script
Public Static Functions
-
static inline void *object_ref(const data_type &data) noexcept
Get the referenced object.
This allows direct interaction with the stored object, whether it’s an object handle or not
Note
Only valid if the type of stored data is NOT a primitive value
-
static inline bool construct(data_type &data, asIScriptEngine *engine, int type_id)
Construct the stored value using its default constructor.
- Parameters:
engine – Script engine
type_id – Type ID. Must NOT be void (
asTYPEID_VOID)
- Returns:
True if successful
-
static inline bool copy_construct(data_type &data, asIScriptEngine *engine, int type_id, const void *ref)
Copy construct the stored value from another value.
Note
Make sure this helper doesn’t contain a constructed object previously!
- Parameters:
engine – Script engine
type_id – Type ID. Must NOT be void (
asTYPEID_VOID)ref – Address of the value. Must NOT be
nullptr
- Returns:
True if successful
-
static inline bool copy_assign_from(data_type &data, asIScriptEngine *engine, int type_id, const void *ref)
Copy assign the stored value from another value.
Note
Make sure the stored value is valid!
- Parameters:
engine – Script engine
type_id – Type ID. Must NOT be void (
asTYPEID_VOID)ref – Address of the value. Must NOT be
nullptr
- Returns:
True if successful
-
static inline bool copy_assign_to(const data_type &data, asIScriptEngine *engine, int type_id, void *out)
Copy assign the stored value to destination.
Note
Make sure the stored value is valid!
- Parameters:
engine – Script engine
type_id – Type ID. Must NOT be void (
asTYPEID_VOID)out – Address of the destination. Must NOT be
nullptr
- Returns:
True if successful
-
union data_type
Helper for storing data.
Note
This helper needs an external type ID for correctly handle the stored data, so it is recommended to use this helper as a member of container class, together with a member for storing type ID.
-
static inline void *object_ref(const data_type &data) noexcept
You can check the script_optional from extension library as an example.
Containers
Policies of Type Information
Policies for how containers deal with the type information.
-
template<typename T>
concept typeinfo_policy - #include <options.hpp>
Concept of type information policies.
-
struct typeinfo_identity
- #include <options.hpp>
The type information itself is for the element.
Sequential Containers
-
template<typeinfo_policy TypeInfoPolicy, std::size_t StaticCapacityBytes = 4 * sizeof(void*), typename Allocator = as_allocator<void>>
class small_vector Sequential container for AngelScript objects with small size optimization (SSO)
Most members have the same meaning as member functions of the same name in
std::vector- Template Parameters:
TypeInfoPolicy – Type information policy for element type
StaticCapcityBytes – Static capacity in bytes. Must be aligned with the size of pointer, e.g.
4 * sizeof(void*).Allocator – Allocator type which is able to rebind to multiple types. Its member
pointer_typemust be compatible with raw pointers.
Type information
-
inline auto get_type_info() const noexcept -> asITypeInfo*
-
inline auto element_type_info() const -> asITypeInfo*
-
inline int element_type_id() const
Iterators of small vector
-
inline const_iterator cbegin() const noexcept
-
inline const_iterator cend() const noexcept
-
inline const_iterator begin() const noexcept
-
inline const_iterator end() const noexcept
Modifiers
-
inline void clear() noexcept
-
inline void push_back(const void *ref)
-
inline void emplace_back()
-
inline void pop_back() noexcept
-
inline void insert(const_iterator where, const void *ref)
-
inline void erase(const_iterator start, const_iterator stop)
-
inline void erase(const_iterator where)
-
inline void assign(const_iterator where, const void *ref)
Visiting members
-
template<typename Visitor>
inline decltype(auto) visit(Visitor &&vis, size_type start, size_type count)
-
template<typename Visitor>
inline decltype(auto) visit(Visitor &&vis, const_iterator start, const_iterator stop)
Public Types
-
using size_type = std::size_t
-
using difference_type = std::ptrdiff_t
-
using pointer = void*
-
using const_pointer = const void*
Public Functions
-
small_vector() = delete
-
inline ~small_vector()
-
inline small_vector(const small_vector &other)
-
inline explicit small_vector(asITypeInfo *ti)
-
inline small_vector(asITypeInfo *ti, script_init_list_repeat ilist)
-
inline small_vector(asIScriptEngine *engine, int type_id)
-
inline void enum_refs()
Enumerate references for GC.
-
class const_iterator
Const iterator of small vector.
Public Types
-
using value_type = const void*
-
using iterator_category = std::random_access_iterator_tag
-
using size_type = std::size_t
-
using difference_type = std::ptrdiff_t
-
using pointer = const void*
-
using reference = const void*
-
using const_reference = const void*
Public Functions
-
const_iterator() noexcept = default
-
const_iterator(const const_iterator&) noexcept = default
-
inline bool operator==(const const_iterator &rhs) const noexcept
-
inline std::strong_ordering operator<=>(const const_iterator &rhs) const noexcept
-
inline const_iterator &operator++() noexcept
-
inline const_iterator &operator--() noexcept
-
inline const_iterator &operator++(int) noexcept
-
inline const_iterator &operator--(int) noexcept
-
inline const_iterator &operator+=(difference_type diff) noexcept
-
inline const_iterator &operator-=(difference_type diff) noexcept
-
inline reference operator[](difference_type off) const noexcept
-
inline const small_vector *get_container() const noexcept
-
inline explicit operator bool() const noexcept
Friends
-
inline friend const_iterator operator+(const_iterator lhs, const_iterator rhs) noexcept
-
inline friend const_iterator operator+(const_iterator lhs, difference_type rhs) noexcept
-
inline friend const_iterator operator+(difference_type lhs, const_iterator rhs) noexcept
-
inline friend difference_type operator-(const_iterator lhs, const_iterator rhs) noexcept
-
inline friend const_iterator operator-(const_iterator lhs, difference_type rhs) noexcept
-
using value_type = const void*
You can check the script_array from extension library as an example.
Associative Containers
Not implemented yet