List of all members | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions
casadi::Resource Class Reference

RAII class for reading from a zip file. More...

#include <resource.hpp>

Detailed Description

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

Definition at line 42 of file resource.hpp.

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

Public Types

using internal_base_type = SharedObjectInternal
 
using base_type = SharedObject
 

Public Member Functions

 Resource (const std::string &path)
 Initialize with a path. More...
 
 Resource ()
 Default constructor. More...
 
ResourceInternalget () const
 
const ResourceInternaloperator-> () const
 Access a member function or object. More...
 
ResourceInternaloperator-> ()
 Access a member function or object. More...
 
const ResourceInternaloperator* () const
 Reference to internal structure. More...
 
const std::string & path () const
 Get path for a consumer. More...
 
void serialize (SerializingStream &s) const
 Serialize an object. More...
 
void change_option (const std::string &option_name, const GenericType &option_value)
 Change option after object creation for debugging. More...
 
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...
 
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< SharedObject, SharedObjectInternal > * weak ()
 Get a weak reference to the object. More...
 

Static Public Member Functions

static std::string type_name ()
 Readable name of the public class. More...
 
static bool test_cast (const SharedObjectInternal *ptr)
 Check if a particular cast is allowed. More...
 
static Resource create (ResourceInternal *node)
 Create from node. More...
 
static Resource deserialize (DeserializingStream &s)
 Deserialize with type disambiguation. More...
 

Protected Member Functions

void count_up ()
 
void count_down ()
 

Member Typedef Documentation

◆ base_type

Definition at line 103 of file shared_object.hpp.

◆ internal_base_type

Definition at line 102 of file shared_object.hpp.

Constructor & Destructor Documentation

◆ Resource() [1/2]

casadi::Resource::Resource ( const std::string &  path)

If the path is a directory or empty, the path is passed through to the consumer. Otherwise, the zip file is extracted to a temporary directory.

Upon destruction, the temporary directory is removed.

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

Definition at line 35 of file resource.cpp.

35  {
36  // Pass through empty strings
38  own(new DirResource(path));
39  return;
40  }
41  own(new ZipResource(path));
42  }
static bool is_directory(const std::string &path)
Definition: filesystem.cpp:38
static bool is_enabled()
Definition: filesystem.cpp:83
const std::string & path() const
Get path for a consumer.
Definition: resource.cpp:70

References casadi::Filesystem::is_directory(), casadi::Filesystem::is_enabled(), casadi::GenericShared< SharedObject, SharedObjectInternal >::own(), and path().

◆ Resource() [2/2]

casadi::Resource::Resource ( )
explicit

Definition at line 32 of file resource.cpp.

32  {
33  }

Member Function Documentation

◆ __hash__()

casadi_int casadi::GenericShared< SharedObject , SharedObjectInternal >::__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  }

◆ assign()

void casadi::GenericShared< SharedObject , SharedObjectInternal >::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  }

◆ change_option()

void casadi::Resource::change_option ( const std::string &  option_name,
const GenericType option_value 
)

This is only possible for a selected number of options that do not change the numerical results of the comput

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

Definition at line 74 of file resource.cpp.

74  {
75  return (*this)->change_option(option_name, option_value);
76  }

Referenced by casadi::DaeBuilderInternal::DaeBuilderInternal().

◆ class_name()

std::string casadi::SharedObject::class_name ( ) const
inherited

◆ count_down()

void casadi::GenericShared< SharedObject , SharedObjectInternal >::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< SharedObject , SharedObjectInternal >::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  }

◆ create()

Resource casadi::Resource::create ( ResourceInternal node)
static

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

Definition at line 44 of file resource.cpp.

44  {
45  Resource ret;
46  ret.own(node);
47  return ret;
48  }
Resource()
Default constructor.
Definition: resource.cpp:32

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

Referenced by deserialize().

◆ debug_repr()

std::string casadi::GenericShared< SharedObject , SharedObjectInternal >::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

◆ deserialize()

Resource casadi::Resource::deserialize ( DeserializingStream s)
static

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

Definition at line 82 of file resource.cpp.

82  {
84  }
static ResourceInternal * deserialize(DeserializingStream &s)
static Resource create(ResourceInternal *node)
Create from node.
Definition: resource.cpp:44

References create(), and casadi::ResourceInternal::deserialize().

◆ disp()

void casadi::SharedObject::disp ( std::ostream &  stream,
bool  more = false 
) const
inherited

Definition at line 35 of file shared_object.cpp.

35  {
36  if (is_null()) {
37  stream << "NULL";
38  } else {
39  (*this)->disp(stream, more);
40  }
41  }

References casadi::GenericShared< SharedObject, SharedObjectInternal >::is_null().

Referenced by casadi::Nlpsol::disp_more(), and casadi::CsparseInterface::nfact().

◆ get()

ResourceInternal * casadi::Resource::get ( ) const

Definition at line 66 of file resource.cpp.

66  {
67  return static_cast<ResourceInternal*>(SharedObject::get());
68  }
SharedObjectInternal * get() const
Get a const pointer to the node.

References casadi::GenericShared< SharedObject, SharedObjectInternal >::get().

Referenced by operator*().

◆ get_str()

std::string casadi::SharedObject::get_str ( bool  more = false) const
inlineinherited

Definition at line 91 of file shared_object.hpp.

91  {
92  std::stringstream ss;
93  disp(ss, more);
94  return ss.str();
95  }
void disp(std::ostream &stream, bool more=false) const
Print a description of the object.

◆ getCount()

casadi_int casadi::GenericShared< SharedObject , SharedObjectInternal >::getCount
inherited

Definition at line 103 of file generic_shared_impl.hpp.

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

◆ is_null()

Definition at line 117 of file generic_shared_impl.hpp.

109  {
110  return node==nullptr;
111  }

◆ operator*()

const ResourceInternal & casadi::Resource::operator* ( ) const

Definition at line 58 of file resource.cpp.

58  {
59  return *static_cast<const ResourceInternal*>(get());
60  }
ResourceInternal * get() const
Definition: resource.cpp:66

References get().

◆ operator->() [1/2]

ResourceInternal * casadi::Resource::operator-> ( )

Definition at line 54 of file resource.cpp.

54  {
55  return static_cast<ResourceInternal*>(SharedObject::operator->());
56  }
SharedObjectInternal * operator->() const
Access a member function or object.

References casadi::GenericShared< SharedObject, SharedObjectInternal >::operator->().

◆ operator->() [2/2]

const ResourceInternal * casadi::Resource::operator-> ( ) const

Definition at line 50 of file resource.cpp.

50  {
51  return static_cast<const ResourceInternal*>(SharedObject::operator->());
52  }

References casadi::GenericShared< SharedObject, SharedObjectInternal >::operator->().

◆ own()

void casadi::GenericShared< SharedObject , SharedObjectInternal >::own ( Internal *  node)
inherited

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

Definition at line 90 of file generic_shared_impl.hpp.

◆ path()

const std::string & casadi::Resource::path ( ) const

Definition at line 70 of file resource.cpp.

70  {
71  return (*this)->path();
72  }

Referenced by casadi::FmuInternal::finalize(), and Resource().

◆ print_ptr()

void casadi::SharedObject::print_ptr ( std::ostream &  stream = casadi::uout()) const
inherited

Print the pointer to the internal class

Definition at line 43 of file shared_object.cpp.

43  {
44  stream << get();
45  }

References casadi::GenericShared< SharedObject, SharedObjectInternal >::get().

◆ serialize()

void casadi::Resource::serialize ( SerializingStream s) const

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

Definition at line 78 of file resource.cpp.

78  {
79  return (*this)->serialize(s);
80  }

◆ swap()

Definition at line 106 of file generic_shared_impl.hpp.

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

◆ test_cast()

bool casadi::Resource::test_cast ( const SharedObjectInternal ptr)
static

Definition at line 62 of file resource.cpp.

62  {
63  return dynamic_cast<const ResourceInternal*>(ptr)!=nullptr;
64  }

◆ type_name()

static std::string casadi::Resource::type_name ( )
inlinestatic

Definition at line 59 of file resource.hpp.

59 {return "Resource";}

◆ 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 files: