List of all members | Public Member Functions | Protected Member Functions | Friends
casadi::GenericWeakRef< Shared, Internal > Class Template Reference

#include <generic_shared.hpp>

Detailed Description

template<typename Shared, typename Internal>
class casadi::GenericWeakRef< Shared, Internal >

Definition at line 141 of file generic_shared.hpp.

Inheritance diagram for casadi::GenericWeakRef< Shared, Internal >:
Inheritance graph
[legend]
Collaboration diagram for casadi::GenericWeakRef< Shared, Internal >:
Collaboration graph
[legend]

Public Member Functions

 GenericWeakRef (int dummy=0)
 Default constructor. More...
 
 GenericWeakRef (Shared shared)
 Construct from a shared object (also implicit type conversion) More...
 
Shared shared () const
 Get a shared (owning) reference. More...
 
bool alive () const
 Check if alive. More...
 
bool shared_if_alive (Shared &shared) const
 Thread-safe alternative to alive()/shared() More...
 
GenericWeakRefInternal< Shared, Internal > * operator-> ()
 Access functions of the node. More...
 
const GenericWeakRefInternal< Shared, Internal > * operator-> () const
 Const access functions of the node. More...
 
void own (Internal *node)
 
void assign (Internal *node)
 Assign the node to a node class pointer without reference counting. More...
 
Internal * 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...
 
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< Shared, Internal > * weak ()
 Get a weak reference to the object. More...
 

Protected Member Functions

void count_up ()
 
void count_down ()
 

Friends

class GenericSharedInternal< Shared, Internal >
 

Constructor & Destructor Documentation

◆ GenericWeakRef() [1/2]

template<typename Shared , typename Internal >
casadi::GenericWeakRef< Shared, Internal >::GenericWeakRef ( int  dummy = 0)

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

Definition at line 146 of file generic_shared_impl.hpp.

146  {
147  casadi_assert_dev(dummy==0);
148  }

◆ GenericWeakRef() [2/2]

template<typename Shared , typename Internal >
casadi::GenericWeakRef< Shared, Internal >::GenericWeakRef ( Shared  shared)

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

Definition at line 193 of file generic_shared_impl.hpp.

193  {
194  this->own(shared.weak()->get());
195  }
void own(Internal *node)
Shared shared() const
Get a shared (owning) reference.

Member Function Documentation

◆ __hash__()

template<typename Shared , typename Internal >
casadi_int casadi::GenericShared< Shared, Internal >::__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 141 of file generic_shared_impl.hpp.

141  {
142  return reinterpret_cast<casadi_int>(get());
143  }
Internal * get() const
Get a const pointer to the node.

◆ alive()

template<typename Shared , typename Internal >
bool casadi::GenericWeakRef< Shared, Internal >::alive

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

Definition at line 151 of file generic_shared_impl.hpp.

151  {
152  return !is_null() && (*this)->raw_ != nullptr;
153  }
bool is_null() const
Is a null pointer?

◆ assign()

template<typename Shared , typename Internal >
void casadi::GenericShared< Shared, Internal >::assign ( Internal *  node)
inherited

improper use will cause memory leaks!

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

Definition at line 79 of file generic_shared_impl.hpp.

79  {
80  node = node_;
81  }

◆ count_down()

template<typename Shared , typename Internal >
void casadi::GenericShared< Shared, Internal >::count_down
protectedinherited

Definition at line 46 of file generic_shared_impl.hpp.

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

◆ count_up()

template<typename Shared , typename Internal >
void casadi::GenericShared< Shared, Internal >::count_up
protectedinherited

Definition at line 36 of file generic_shared_impl.hpp.

36  {
37 #ifdef WITH_EXTRA_CHECKS
38  casadi_assert_dev(Function::call_depth_==0);
39 #endif // WITH_EXTRA_CHECKS
40 
41  if (node) static_cast<Internal*>(node)->count++;
42 
43  }

◆ debug_repr()

template<typename Shared , typename Internal >
std::string casadi::GenericShared< Shared, Internal >::debug_repr
inherited

Definition at line 84 of file generic_shared_impl.hpp.

84  {
85  if (node) {
86  return node->debug_repr(node);
87  } else {
88  return "NULL";
89  }
90  }

◆ get()

template<typename Shared , typename Internal >
Internal * casadi::GenericShared< Shared, Internal >::get
inherited

Definition at line 108 of file generic_shared_impl.hpp.

108  {
109  return node;
110  }

Referenced by casadi::CallSX::get_output().

◆ getCount()

template<typename Shared , typename Internal >
casadi_int casadi::GenericShared< Shared, Internal >::getCount
inherited

Definition at line 131 of file generic_shared_impl.hpp.

131  {
132  return (*this)->getCount();
133  }

Referenced by casadi::MXNode::~MXNode().

◆ is_null()

template<typename Shared , typename Internal >
bool casadi::GenericShared< Shared, Internal >::is_null
inherited

Definition at line 113 of file generic_shared_impl.hpp.

113  {
114  return node==nullptr;
115  }

Referenced by casadi::FunctionInternal::add_embedded(), casadi::FunctionInternal::alloc(), casadi::Nlpsol::callback(), casadi::DaeBuilderInternal::clear_cache(), casadi::Switch::codegen_body(), casadi::Conic::Conic(), casadi::conic_debug(), casadi::DaeBuilderInternal::export_fmu(), casadi::FunctionInternal::finalize(), casadi::Switch::find(), casadi::FunctionInternal::FunctionInternal(), casadi::FunctionInternal::get_n_in(), casadi::Switch::get_n_in(), casadi::FunctionInternal::get_n_out(), casadi::Switch::get_n_out(), casadi::FunctionInternal::get_name_in(), casadi::FunctionInternal::get_name_out(), casadi::FunctionInternal::get_partition(), casadi::FunctionInternal::get_sparsity_in(), casadi::Switch::get_sparsity_in(), casadi::FunctionInternal::get_sparsity_out(), casadi::Switch::get_sparsity_out(), casadi::MXFunction::get_stats(), casadi::Integrator::init(), casadi::Nlpsol::init(), casadi::Rootfinder::init(), casadi::Switch::init(), casadi::SLEQPInterface::init(), casadi::SnoptInterface::init(), casadi::SundialsInterface::init(), casadi::FastNewton::init(), casadi::Newton::init(), casadi::Scpgen::init(), casadi::BonminInterface::intermediate_callback(), casadi::IpoptInterface::intermediate_callback(), casadi::XFunction< DerivedType, MatType, NodeType >::jac(), casadi::FunctionInternal::jac_is_symm(), casadi::FunctionInternal::jac_sparsity(), casadi::OracleFunction::jit_dependencies(), casadi::SparsityInternal::maxtrans(), casadi::BlazingSplineFunction::merge(), casadi::Function::operator==(), casadi::DaeBuilderInternal::oracle(), casadi::SLEQPInterface::set_work(), casadi::SnoptInterface::set_work(), casadi::OptiNode::solve(), casadi::KnitroInterface::solve(), casadi::SLEQPInterface::solve(), casadi::WorhpInterface::solve(), casadi::FunctionInternal::sp_forward_block(), casadi::FunctionInternal::sp_reverse(), and casadi::Sparsity::uni_coloring().

◆ operator->() [1/2]

template<typename Shared , typename Internal >
GenericWeakRefInternal< Shared, Internal > * casadi::GenericWeakRef< Shared, Internal >::operator->

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

Definition at line 187 of file generic_shared_impl.hpp.

187  {
188  return static_cast<GenericWeakRefInternal<Shared, Internal>*>(
190  }
Internal * operator->() const
Access a member function or object.

References casadi::GenericShared< Shared, Internal >::operator->().

◆ operator->() [2/2]

template<typename Shared , typename Internal >
const GenericWeakRefInternal< Shared, Internal > * casadi::GenericWeakRef< Shared, Internal >::operator->

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

Definition at line 180 of file generic_shared_impl.hpp.

180  {
181  return static_cast<const GenericWeakRefInternal<Shared, Internal>*>(
183  }

References casadi::GenericShared< Shared, Internal >::operator->().

◆ own()

template<typename Shared , typename Internal >
void casadi::GenericShared< Shared, Internal >::own ( Internal *  node)
inherited

◆ shared()

template<typename Shared , typename Internal >
Shared casadi::GenericWeakRef< Shared, Internal >::shared

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

Definition at line 156 of file generic_shared_impl.hpp.

156  {
157  Shared ret;
158  if (alive()) {
159  ret.own((*this)->raw_);
160  }
161  return ret;
162  }
bool alive() const
Check if alive.

◆ shared_if_alive()

template<typename Shared , typename Internal >
bool casadi::GenericWeakRef< Shared, Internal >::shared_if_alive ( Shared &  shared) const

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

Definition at line 165 of file generic_shared_impl.hpp.

165  {
166  if (is_null()) return false;
167 #ifdef CASADI_WITH_THREADSAFE_SYMBOLICS
168  // Safe access to ...
169  std::lock_guard<std::mutex> lock(*(*this)->mutex_);
170 #endif // CASADI_WITH_THREADSAFE_SYMBOLICS
171  if (alive()) {
172  shared.own((*this)->raw_);
173  return true;
174  }
175  return false;
176  }

Referenced by casadi::Nlpsol::kkt().

◆ swap()

template<typename Shared , typename Internal >
void casadi::GenericShared< Shared, Internal >::swap ( GenericShared< Shared, Internal > &  other)
inherited

Definition at line 124 of file generic_shared_impl.hpp.

124  {
125  GenericShared<Shared, Internal> temp = *this;
126  *this = other;
127  other = temp;
128  }

◆ weak()

template<typename Shared , typename Internal >
GenericWeakRef< Shared, Internal > * casadi::GenericShared< Shared, Internal >::weak
inherited

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

Definition at line 136 of file generic_shared_impl.hpp.

136  {
137  return (*this)->weak();
138  }

Friends And Related Function Documentation

◆ GenericSharedInternal< Shared, Internal >

template<typename Shared , typename Internal >
friend class GenericSharedInternal< Shared, Internal >
friend

Definition at line 135 of file generic_shared.hpp.


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