GenericShared implements a reference counting framework similar for efficient and. More...
#include <shared_object.hpp>
easily-maintained memory management.
To use the class, both the GenericShared class (the public class), and the GenericSharedInternal class (the internal class) must be inherited from. It can be done in two different files and together with memory management, this approach provides a clear distinction of which methods of the class are to be considered "public", i.e. methods for public use that can be considered to remain over time with small changes, and the internal memory.
When interfacing a software, which typically includes including some header file, this is best done only in the file where the internal class is defined, to avoid polluting the global namespace and other side effects.
The default constructor always means creating a null pointer to an internal class only. To allocate an internal class (this works only when the internal class isn't abstract), use the constructor with arguments.
The copy constructor and the assignment operator perform shallow copies only, to make a deep copy you must use the clone method explicitly. This will give a shared pointer instance.
In an inheritance hierarchy, you can cast down automatically, e.g. (SXFunction is a child class of Function): SXFunction derived(...); Function base = derived;
To cast up, use the shared_cast template function, which works analogously to dynamic_cast, static_cast, const_cast etc, e.g.: SXFunction derived(...); Function base = derived; SXFunction derived_from_base = shared_cast<SXFunction>(base);
A failed shared_cast will result in a null pointer (cf. dynamic_cast)
Extra doc: https://github.com/casadi/casadi/wiki/L_as
Definition at line 78 of file shared_object.hpp.
Public Types | |
using | internal_base_type = SharedObjectInternal |
using | base_type = SharedObject |
Public Member Functions | |
std::string | class_name () const |
Get class name. More... | |
void | disp (std::ostream &stream, bool more=false) const |
Print a description of the object. More... | |
std::string | get_str (bool more=false) const |
Get string representation. More... | |
void | print_ptr (std::ostream &stream=casadi::uout()) const |
void | own (SharedObjectInternal *node) |
void | assign (SharedObjectInternal *node) |
Assign the node to a node class pointer without reference counting. More... | |
SharedObjectInternal * | get () const |
Get a const pointer to the node. More... | |
casadi_int | getCount () const |
Get the reference count. More... | |
void | swap (GenericShared &other) |
Swap content with another instance. More... | |
SharedObjectInternal * | operator-> () const |
Access a member function or object. More... | |
std::string | debug_repr () const |
bool | is_null () const |
Is a null pointer? More... | |
casadi_int | __hash__ () const |
Returns a number that is unique for a given Node. More... | |
GenericWeakRef< SharedObject, SharedObjectInternal > * | weak () |
Get a weak reference to the object. More... | |
Protected Member Functions | |
void | count_up () |
void | count_down () |
Definition at line 103 of file shared_object.hpp.
Definition at line 102 of file shared_object.hpp.
|
inherited |
If the Object does not point to any node, "0" is returned.
Extra doc: https://github.com/casadi/casadi/wiki/L_av
Definition at line 124 of file generic_shared_impl.hpp.
|
inherited |
improper use will cause memory leaks!
Extra doc: https://github.com/casadi/casadi/wiki/L_at
Definition at line 97 of file generic_shared_impl.hpp.
std::string casadi::SharedObject::class_name | ( | ) | const |
Extra doc: https://github.com/casadi/casadi/wiki/L_au
Definition at line 31 of file shared_object.cpp.
Referenced by casadi::FmuFunction::check_mem_count(), casadi::MXFunction::export_code_body(), and casadi::BlazingSplineFunction::merge().
|
protectedinherited |
Definition at line 134 of file generic_shared_impl.hpp.
|
protectedinherited |
Definition at line 133 of file generic_shared_impl.hpp.
|
inherited |
Definition at line 113 of file generic_shared_impl.hpp.
void casadi::SharedObject::disp | ( | std::ostream & | stream, |
bool | more = false |
||
) | const |
Definition at line 35 of file shared_object.cpp.
References casadi::GenericShared< SharedObject, SharedObjectInternal >::is_null().
Referenced by casadi::Nlpsol::disp_more(), and casadi::CsparseInterface::nfact().
|
inherited |
Definition at line 100 of file generic_shared_impl.hpp.
|
inline |
Definition at line 91 of file shared_object.hpp.
|
inherited |
Definition at line 103 of file generic_shared_impl.hpp.
|
inherited |
Definition at line 117 of file generic_shared_impl.hpp.
|
inherited |
Definition at line 109 of file generic_shared_impl.hpp.
|
inherited |
Assign the node to a node class pointer (or null)
Definition at line 90 of file generic_shared_impl.hpp.
void casadi::SharedObject::print_ptr | ( | std::ostream & | stream = casadi::uout() | ) | const |
Print the pointer to the internal class
Definition at line 43 of file shared_object.cpp.
References casadi::GenericShared< SharedObject, SharedObjectInternal >::get().
|
inherited |
Definition at line 106 of file generic_shared_impl.hpp.
|
inherited |
Extra doc: https://github.com/casadi/casadi/wiki/L_aw
Definition at line 131 of file generic_shared_impl.hpp.