Generalized binding class for managing instance lifecycles 더 자세히 ...
#include <binder.hpp>
Public 멤버 함수 | |
| binder (const type &type, bindTacticable &tactic) | |
| Constructs a binder with a specific type and binding tactic. | |
| binder (const me &rhs) | |
| instance * | operator-> () |
| Dereference operator to access bound instance | |
| const instance * | operator-> () const BY_CONST_FUNC(operator->()) instance &operator*() |
| const instance & | operator* () const BY_CONST_FUNC(operator*()) me &operator |
| Assigns another binder's bound instance to this binder. | |
| id | getItsId () const |
| Retrieves the unique ID of the instance currently bound by this binder. | |
| nbool | isBind () const override |
| void | rel () override |
| nbool | canBind (const type &it) const override |
| Checks if given type can be bound to this binder | |
| nbool | bind (const instance &it) override |
| Binds instance to this binder with reference counting | |
| instance * | get () |
| const instance * | get () const BY_CONST_FUNC(get()) template< typename E > E *get() |
| template<typename E > | |
| const E * | get () const BY_CONST_FUNC(get< E >()) const type &getType() const override |
| void * | cast (const type &to) override |
| nbool | canBind (const T &it) const |
| nbool | canBind (const T *it) const BY_SIDE_FUNC(canBind) |
| virtual nbool | canBind (const type &it) const=0 |
| nbool | canBind (const type *it) const BY_SIDE_FUNC(canBind) |
| virtual nbool | bind (const T &it) |
| nbool | bind (const T *it) |
| Bind to instance pointer | |
| template<typename T > | |
| T * | cast () |
| template<typename T > | |
| const T * | cast () const BY_CONST_FUNC(cast< T >()) virtual void *cast(const type &to) |
| Safe cast to target type using type hierarchy information | |
| const void * | cast (const type &to) const BY_CONST_FUNC(cast(to)) void *cast(const type *it) BY_SIDE_FUNC(cast) |
by::typeProvidable(으)로부터 상속된 Public 멤버 함수 | |
| nbool | operator== (const me &rhs) const |
| nbool | operator!= (const me &rhs) const |
| virtual const type & | getType () const =0 |
| nbool | isSub (const type &it) const |
| nbool | isSub (const type *it) const BY_SIDE_FUNC(isSub) |
| nbool | isSub (const me &it) const |
| nbool | isSub (const me *it) const BY_SIDE_FUNC(isSub) |
| nbool | isSuper (const type &it) const |
| nbool | isSuper (const type *it) const BY_SIDE_FUNC(isSuper) |
| nbool | isSuper (const me &it) const |
| nbool | isSuper (const me *it) const BY_SIDE_FUNC(isSuper) |
| template<typename T > | |
| nint | isSub () const |
| template<typename T > | |
| nint | isSuper () const |
| template<typename T > | |
| T * | cast () |
| template<typename T > | |
| const T * | cast () const BY_CONST_FUNC(cast< T >()) virtual void *cast(const type &to) |
| Safe cast to target type using type hierarchy information | |
| const void * | cast (const type &to) const BY_CONST_FUNC(cast(to)) void *cast(const type *it) BY_SIDE_FUNC(cast) |
by::tbindable< instance >(으)로부터 상속된 Public 멤버 함수 | |
| operator nbool () const | |
| nbool | bind (const instance *it) |
| Bind to instance pointer | |
| nbool | canBind (const instance &it) const |
| nbool | canBind (const instance *it) const BY_SIDE_FUNC(canBind) |
| nbool | canBind (const type *it) const BY_SIDE_FUNC(canBind) |
Protected 멤버 함수 | |
| nbool | _assign (const binder &rhs) |
| Assigns binder from another binder | |
| nbool | _onSame (const typeProvidable &rhs) const override |
| Checks if two typeProvidable objects are same instance | |
| life * | _getBindTag () const |
| Retrieves life object associated with bound instance | |
Protected 속성 | |
| id | _itsId |
| const type * | _type |
| bindTacticable * | _tactic |
Friends | |
| struct | ::binderTest |
Generalized binding class for managing instance lifecycles
Can bind any object inheriting from instance. Uses reference counting to properly destroy objects at appropriate times. Similar to std::weak_ptr and std::shared_ptr, with tweak handling weak pointers and tstr handling strong pointers.
Basic usage with bind(), isBind(), and get():
More concise real-world usage:
Several advantages over shared_ptr:
Ultimate goal of memlite is lightweight C++ memory management for byeol runtime environment. Requires GC and additional memory management, implying custom memory pool and instance lifecycle management. All instance allocation starts with instancer.
shared_ptr's algorithm stores reference counting info on heap. Using faster custom memory pool instead of heap and optimizing binding speed provides performance gains. Binding is one of the hotspots consuming most performance in byeol.
shared_ptr creates objects on heap for reference counting. memlite uses watcher to lend empty life objects from pre-allocated memory, using them as reference counting space for instances. If GC features are added later, instances may require additional lifecycle information. Unlike shared_ptr, managing each instance's lifecycle information internally allows appropriate handling of such requirements.
| by::binder::binder | ( | const type & | type, |
| bindTacticable & | tactic ) |
Constructs a binder with a specific type and binding tactic.
| type | The type of the instance this binder will manage. |
| tactic | The binding tactic (e.g., strong or weak) to use for reference counting. |
Assigns binder from another binder
|
protected |
Retrieves life object associated with bound instance
|
overrideprotected |
Checks if two typeProvidable objects are same instance
Binds instance to this binder with reference counting
by::tbindable< instance >(으)로부터 재구현되었습니다.
| nbool by::tbindable< T >::bind | ( | const T * | it | ) |
Bind to instance pointer
binder will loose previous binding instance whether given parameter it isn't nullptr or not.
Checks if given type can be bound to this binder
|
virtual |
Safe cast to target type using type hierarchy information
| id by::binder::getItsId | ( | ) | const |
Retrieves the unique ID of the instance currently bound by this binder.
|
overridevirtual |
Assigns another binder's bound instance to this binder.
This operator handles the transfer of binding, ensuring proper reference counting adjustments for both the source and target binders.
| rhs | The binder to assign from. |
| instance * by::binder::operator-> | ( | ) |
Dereference operator to access bound instance
This follows the same policy as tmay and stl. that is, if the binder does not bind any instances and tries to dereference them with get() or operator*(), it will behave as UB. this is likely to crash.
|
overridevirtual |