cppyabm
1.0.17
An agent-based library to integrate C++ and Python
|
|
Go to the documentation of this file. 1 #if !defined(__OBJECT_H)
20 void incRef()
const { ++m_refCount; }
28 void decRef(
bool dealloc =
true)
const {
30 if (m_refCount == 0 && dealloc)
32 else if (m_refCount < 0)
33 throw std::runtime_error(
"Internal error: reference count < 0!");
43 mutable std::atomic<int> m_refCount { 0 };
62 template <
typename T>
class ref {
68 ref(T *ptr) : m_ptr(ptr) {
69 if (m_ptr) ((
Object *) m_ptr)->incRef();
78 ((
Object *) m_ptr)->incRef();
93 ((
Object *) m_ptr)->decRef();
105 ((
Object *) m_ptr)->decRef();
115 if (m_ptr == r.m_ptr)
118 ((
Object *) m_ptr)->decRef();
121 ((
Object *) m_ptr)->incRef();
132 ((
Object *) m_ptr)->decRef();
135 ((
Object *) m_ptr)->incRef();
164 operator T* () {
return m_ptr; }
void track_destroyed(T *inst)
void track_copy_assigned(T *, Values &&...values)
void track_values(T *, Values &&...values)
virtual ~Object()
Virtual protected deconstructor. (Will only be called by ref)
void decRef(bool dealloc=true) const
Decrease the reference count of the object and possibly deallocate it.
T * get_ptr()
Return a const pointer to the referenced object.
const T * get_ptr() const
Return a pointer to the referenced object.
virtual std::string toString() const =0
bool operator==(const ref &r) const
Compare this reference with another reference.
ref(T *ptr)
Construct a reference from a pointer.
ref(ref &&r)
Move constructor.
void print_copy_created(T *inst, Values &&...values)
void track_move_created(T *inst)
void print_default_created(T *inst, Values &&...values)
void incRef() const
Increase the object's reference count by one.
bool operator!=(const T *ptr) const
Compare this reference with a pointer.
ref()
Create a nullptr reference.
~ref()
Destroy this reference.
T & operator*()
Return a C++ reference to the referenced object.
bool operator!=(const ref &r) const
Compare this reference with another reference.
void print_copy_assigned(T *inst, Values &&...values)
int getRefCount() const
Return the current reference count.
Reference counted object base class.
const T * operator->() const
Access the object referenced by this reference.
void track_copy_created(T *inst)
ref & operator=(const ref &r)
Overwrite this reference with another reference.
const T & operator*() const
Return a const C++ reference to the referenced object.
void track_default_created(T *inst, Values &&...values)
ref & operator=(T *ptr)
Overwrite this reference with a pointer to another object.
Object(const Object &)
Copy constructor.
void print_move_created(T *inst, Values &&...values)
bool operator==(const T *ptr) const
Compare this reference with a pointer.
void track_created(T *inst, Values &&...values)
void print_destroyed(T *inst, Values &&...values)
Reference counting helper.
ref & operator=(ref &&r)
Move another reference into the current one.
T * operator->()
Access the object referenced by this reference.
void print_move_assigned(T *inst, Values &&...values)
void track_move_assigned(T *, Values &&...values)
Object()
Default constructor.
ref(const ref &r)
Copy constructor.
void print_created(T *inst, Values &&...values)
void print_values(T *inst, Values &&...values)