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 142 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 142 of file generic_shared_impl.hpp.

142  {
143  casadi_assert_dev(dummy==0);
144  }

◆ 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 189 of file generic_shared_impl.hpp.

189  {
190  this->own(shared.weak()->get());
191  }
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 137 of file generic_shared_impl.hpp.

137  {
138  return reinterpret_cast<casadi_int>(get());
139  }
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 147 of file generic_shared_impl.hpp.

147  {
148  return !is_null() && (*this)->raw_ != nullptr;
149  }
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 75 of file generic_shared_impl.hpp.

75  {
76  node = node_;
77  }

◆ count_down()

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

Definition at line 42 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()

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

Definition at line 32 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()

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

Definition at line 80 of file generic_shared_impl.hpp.

80  {
81  if (node) {
82  return node->debug_repr(node);
83  } else {
84  return "NULL";
85  }
86  }

◆ get()

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

Definition at line 104 of file generic_shared_impl.hpp.

104  {
105  return node;
106  }

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

◆ getCount()

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

Definition at line 127 of file generic_shared_impl.hpp.

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

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

◆ is_null()

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

Definition at line 109 of file generic_shared_impl.hpp.

109  {
110  return node==nullptr;
111  }

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 183 of file generic_shared_impl.hpp.

183  {
184  return static_cast<GenericWeakRefInternal<Shared, Internal>*>(
186  }
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 176 of file generic_shared_impl.hpp.

176  {
177  return static_cast<const GenericWeakRefInternal<Shared, Internal>*>(
179  }

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 152 of file generic_shared_impl.hpp.

152  {
153  Shared ret;
154  if (alive()) {
155  ret.own((*this)->raw_);
156  }
157  return ret;
158  }
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 161 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  }

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 120 of file generic_shared_impl.hpp.

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

◆ 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 132 of file generic_shared_impl.hpp.

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

Friends And Related Function Documentation

◆ GenericSharedInternal< Shared, Internal >

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

Definition at line 136 of file generic_shared.hpp.


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