32 SharedObject::SharedObject(){
52 SharedObject::~SharedObject(){
68 if(node == ref.
node)
return *
this;
87 bool SharedObject::isNull()
const{
91 void SharedObject::count_up(){
92 if(node) node->
count++;
95 void SharedObject::count_down(){
96 if(node && --node->count == 0){
112 SharedObjectNode::SharedObjectNode(){
117 SharedObjectNode::~SharedObjectNode(){
128 bool SharedObject::checkNode()
const{
132 void SharedObject::repr(std::ostream &stream)
const{
136 (*this)->
repr(stream);
139 void SharedObjectNode::repr(std::ostream &stream)
const{
145 if(isNull()) stream <<
"Null pointer of class \"" <<
typeid(
this).
name() <<
"\"";
146 else (*this)->print(stream);
151 stream <<
typeid(
this).
name();
154 void SharedObject::makeUnique(
bool clone_members){
155 std::map<SharedObjectNode*,SharedObject> already_copied;
156 makeUnique(already_copied,clone_members);
159 void SharedObject::makeUnique(std::map<SharedObjectNode*,SharedObject>& already_copied,
bool clone_members){
160 if(node && node->count>1){
162 std::map<SharedObjectNode*,SharedObject>::iterator it = already_copied.find(node);
164 if(it==already_copied.end()){
180 assignNode(it->second.get());
199 int SharedObject::getCount()
const{
203 int SharedObjectNode::getCount()
const{
207 void SharedObjectNode::deepCopyMembers(std::map<SharedObjectNode*,SharedObject>& already_copied){
210 bool SharedObject::isInit()
const{
211 return (*this)->isInit();
214 void SharedObject::assertInit()
const{
215 (*this)->assertInit();
218 bool SharedObjectNode::isInit()
const{
222 void SharedObjectNode::assertInit()
const{
223 casadi_assert_message(isInit(),
"You must first initialize a Shared Object before you can use it." << std::endl <<
"Use something like f.init()");
Internal class for the reference counting framework, see comments on the public class.
void assignNode(SharedObjectNode *node)
Assign the node to a node class pointer (or null)
virtual void deepCopyMembers(std::map< SharedObjectNode *, SharedObject > &already_copied)
Deep copy data members.
virtual void init()
Initialize the object.
SharedObject implements a reference counting framework simular for effient and easily-maintained memo...
unsigned int count
Number of references pointing to the object.
virtual void repr(std::ostream &stream) const
Print a representation of the object.
#define casadi_assert_message(x, msg)
BEGIN_NAMESPACE_QPOASES returnValue print(const real_t *const v, int n)
int getCount() const
Get the reference count.
void init(int nV, int nC, SymmetricMatrix *H, real_t *g, Matrix *A, const real_t *const lb, const real_t *const ub, const real_t *const lbA, const real_t *const ubA, int nWSR, const real_t *const x0, Options *options, int nOutputs, mxArray *plhs[])
bool is_init_
Has the function been initialized?
virtual SharedObjectNode * clone() const =0
Make a deep copy of the instance.