List of all members | Public Member Functions | Protected Member Functions
casadi::WeakRefSXElem Class Reference

#include <output_sx.hpp>

Detailed Description

Definition at line 51 of file output_sx.hpp.

Inheritance diagram for casadi::WeakRefSXElem:
Inheritance graph
[legend]
Collaboration diagram for casadi::WeakRefSXElem:
Collaboration graph
[legend]

Public Member Functions

 WeakRefSXElem (int dummy=0)
 
 WeakRefSXElem (SharedSXElem shared)
 
SharedSXElem shared () const
 Get a shared (owning) reference. More...
 
bool alive () const
 Check if alive. More...
 
bool shared_if_alive (SharedSXElem &shared) const
 Thread-safe alternative to alive()/shared() More...
 
GenericWeakRefInternal< SharedSXElem, OutputSX > * operator-> ()
 Access functions of the node. More...
 
const GenericWeakRefInternal< SharedSXElem, OutputSX > * operator-> () const
 Const access functions of the node. More...
 
void own (OutputSX *node)
 
void assign (OutputSX *node)
 Assign the node to a node class pointer without reference counting. More...
 
OutputSXget () 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...
 
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< SharedSXElem, OutputSX > * weak ()
 Get a weak reference to the object. More...
 

Protected Member Functions

void count_up ()
 
void count_down ()
 

Constructor & Destructor Documentation

◆ WeakRefSXElem() [1/2]

casadi::WeakRefSXElem::WeakRefSXElem ( int  dummy = 0)
inline

Definition at line 54 of file output_sx.hpp.

55  }
template class CASADI_EXPORT GenericWeakRef< SharedSXElem, OutputSX >
Definition: output_sx.cpp:35

◆ WeakRefSXElem() [2/2]

casadi::WeakRefSXElem::WeakRefSXElem ( SharedSXElem  shared)
inline

Definition at line 56 of file output_sx.hpp.

57  }
SharedSXElem shared() const
Get a shared (owning) reference.

Member Function Documentation

◆ __hash__()

casadi_int casadi::GenericShared< SharedSXElem , OutputSX >::__hash__
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.

137  {
138  return reinterpret_cast<casadi_int>(get());
139  }

◆ alive()

bool casadi::GenericWeakRef< SharedSXElem , OutputSX >::alive
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_b1

Definition at line 166 of file generic_shared_impl.hpp.

147  {
148  return !is_null() && (*this)->raw_ != nullptr;
149  }

◆ assign()

void casadi::GenericShared< SharedSXElem , OutputSX >::assign ( Internal *  node)
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.

75  {
76  node = node_;
77  }

◆ count_down()

void casadi::GenericShared< SharedSXElem , OutputSX >::count_down
protectedinherited

Definition at line 134 of file generic_shared_impl.hpp.

42  {
43 #ifdef WITH_EXTRA_CHECKS
44  casadi_assert_dev(Function::call_depth_==0);
45 #endif // WITH_EXTRA_CHECKS
46  if (!node) return;
47  if (node->weak_ref_) {
48 #ifdef CASADI_WITH_THREADSAFE_SYMBOLICS
49  auto mutex = node->weak_ref_->get_mutex();
50  // Avoid triggering a delete while a weak_ref.shared_if_alive is being called
51  std::lock_guard<std::mutex> lock(*mutex);
52  // Could it be that this mutex is destroyed when the lock goes out of scope?
53 #endif // CASADI_WITH_THREADSAFE_SYMBOLICS
54 
55  if (--static_cast<Internal*>(node)->count == 0) {
56  delete node;
57  node = nullptr;
58  }
59  } else {
60  if (--static_cast<Internal*>(node)->count == 0) {
61  delete node;
62  node = nullptr;
63  }
64  }
65  }

◆ count_up()

void casadi::GenericShared< SharedSXElem , OutputSX >::count_up
protectedinherited

Definition at line 133 of file generic_shared_impl.hpp.

32  {
33 #ifdef WITH_EXTRA_CHECKS
34  casadi_assert_dev(Function::call_depth_==0);
35 #endif // WITH_EXTRA_CHECKS
36 
37  if (node) static_cast<Internal*>(node)->count++;
38 
39  }

◆ debug_repr()

std::string casadi::GenericShared< SharedSXElem , OutputSX >::debug_repr
inherited

Definition at line 113 of file generic_shared_impl.hpp.

80  {
81  if (node) {
82  return node->debug_repr(node);
83  } else {
84  return "NULL";
85  }
86  }
std::string debug_repr(const Internal *) const

◆ get()

Definition at line 100 of file generic_shared_impl.hpp.

104  {
105  return node;
106  }

◆ getCount()

casadi_int casadi::GenericShared< SharedSXElem , OutputSX >::getCount
inherited

Definition at line 103 of file generic_shared_impl.hpp.

127  {
128  return (*this)->getCount();
129  }

◆ is_null()

bool casadi::GenericShared< SharedSXElem , OutputSX >::is_null
inherited

Definition at line 117 of file generic_shared_impl.hpp.

109  {
110  return node==nullptr;
111  }

◆ operator->() [1/2]

Extra doc: https://github.com/casadi/casadi/wiki/L_b2

Definition at line 176 of file generic_shared_impl.hpp.

183  {
184  return static_cast<GenericWeakRefInternal<Shared, Internal>*>(
185  GenericShared<Shared, Internal>::operator->());
186  }

◆ operator->() [2/2]

Extra doc: https://github.com/casadi/casadi/wiki/L_b3

Definition at line 181 of file generic_shared_impl.hpp.

176  {
177  return static_cast<const GenericWeakRefInternal<Shared, Internal>*>(
178  GenericShared<Shared, Internal>::operator->());
179  }

◆ own()

void casadi::GenericShared< SharedSXElem , OutputSX >::own ( Internal *  node)
inherited

Assign the node to a node class pointer (or null)

Definition at line 90 of file generic_shared_impl.hpp.

◆ shared()

Extra doc: https://github.com/casadi/casadi/wiki/L_b0

Definition at line 161 of file generic_shared_impl.hpp.

152  {
153  Shared ret;
154  if (alive()) {
155  ret.own((*this)->raw_);
156  }
157  return ret;
158  }

◆ shared_if_alive()

bool casadi::GenericWeakRef< SharedSXElem , OutputSX >::shared_if_alive ( SharedSXElem shared) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_29i

Definition at line 171 of file generic_shared_impl.hpp.

161  {
162  if (is_null()) return false;
163 #ifdef CASADI_WITH_THREADSAFE_SYMBOLICS
164  // Safe access to ...
165  std::lock_guard<std::mutex> lock(*(*this)->mutex_);
166 #endif // CASADI_WITH_THREADSAFE_SYMBOLICS
167  if (alive()) {
168  shared.own((*this)->raw_);
169  return true;
170  }
171  return false;
172  }
void own(Internal *node)

◆ swap()

void casadi::GenericShared< SharedSXElem , OutputSX >::swap ( GenericShared< SharedSXElem, OutputSX > &  other)
inherited

Definition at line 106 of file generic_shared_impl.hpp.

120  {
121  GenericShared<Shared, Internal> temp = *this;
122  *this = other;
123  other = temp;
124  }

◆ weak()

Extra doc: https://github.com/casadi/casadi/wiki/L_aw

Definition at line 131 of file generic_shared_impl.hpp.

132  {
133  return (*this)->weak();
134  }

The documentation for this class was generated from the following file: