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

Generic data type, can hold different types such as bool, casadi_int, std::string etc. More...

#include <generic_type.hpp>

Detailed Description

Author
Joel Andersson
Date
2010

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

Definition at line 72 of file generic_type.hpp.

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

Public Types

typedef std::map< std::string, GenericTypeDict
 C++ equivalent of Python's dict or MATLAB's struct. More...
 
using internal_base_type = SharedObjectInternal
 
using base_type = SharedObject
 

Public Member Functions

 GenericType ()
 Default constructor. More...
 
 GenericType (bool b)
 Constructors (implicit type conversion) More...
 
 GenericType (casadi_int i)
 
 GenericType (int i)
 
 GenericType (double d)
 
 GenericType (const std::string &s)
 
 GenericType (const std::vector< bool > &iv)
 
 GenericType (const std::vector< casadi_int > &iv)
 
 GenericType (const std::vector< int > &iv)
 
 GenericType (const std::vector< std::vector< casadi_int > > &ivv)
 
 GenericType (const std::vector< double > &dv)
 
 GenericType (const std::vector< std::vector< double > > &dv)
 
 GenericType (const std::vector< std::string > &sv)
 
 GenericType (const std::vector< std::vector< std::string > > &sv)
 
 GenericType (const char s[])
 
 GenericType (const Function &f)
 
 GenericType (const std::vector< Function > &f)
 
 GenericType (const Dict &dict)
 
 GenericType (const std::vector< Dict > &dictv)
 
 GenericType (const std::vector< std::vector< GenericType > > &gvv)
 
 GenericType (const std::vector< GenericType > &gv)
 
 GenericType (void *ptr)
 
std::string get_description () const
 Get a description of the object's type. More...
 
bool can_cast_to (TypeID other) const
 
bool can_cast_to (const GenericType &other) const
 
TypeID getType () const
 
bool operator== (const GenericType &op2) const
 Equality. More...
 
bool operator!= (const GenericType &op2) const
 
void serialize (SerializingStream &s) const
 Serialize an object. 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...
 
SharedObjectInternalget () 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...
 
SharedObjectInternaloperator-> () const
 Access a member function or object. 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...
 
 operator bool () const
 
 operator casadi_int () const
 
 operator int () const
 
 operator double () const
 
 operator std::string () const
 
 operator std::vector< bool > () const
 
 operator std::vector< casadi_int > () const
 
 operator std::vector< int > () const
 
 operator std::vector< std::vector< casadi_int > > () const
 
 operator std::vector< std::vector< int > > () const
 
 operator std::vector< double > () const
 
 operator std::vector< std::vector< double > > () const
 
 operator std::vector< std::string > () const
 
 operator std::vector< std::vector< std::string > > () const
 
 operator const Function & () const
 
 operator const std::vector< Function > & () const
 
 operator const Dict & () const
 
 operator const std::vector< Dict > & () const
 
 operator const std::vector< std::vector< GenericType > > & () const
 
 operator const std::vector< GenericType > & () const
 
bool is_bool () const
 Check if a particular type. More...
 
bool is_int () const
 Check if a particular type. More...
 
bool is_double () const
 Check if a particular type. More...
 
bool is_string () const
 Check if a particular type. More...
 
bool is_empty_vector () const
 Check if a particular type. More...
 
bool is_int_vector () const
 Check if a particular type. More...
 
bool is_int_vector_vector () const
 Check if a particular type. More...
 
bool is_double_vector () const
 Check if a particular type. More...
 
bool is_double_vector_vector () const
 Check if a particular type. More...
 
bool is_bool_vector () const
 Check if a particular type. More...
 
bool is_string_vector () const
 Check if a particular type. More...
 
bool is_string_vector_vector () const
 Check if a particular type. More...
 
bool is_dict () const
 Check if a particular type. More...
 
bool is_dict_vector () const
 Check if a particular type. More...
 
bool is_vector_vector () const
 Check if a particular type. More...
 
bool is_vector () const
 Check if a particular type. More...
 
bool is_function () const
 Check if a particular type. More...
 
bool is_function_vector () const
 Check if a particular type. More...
 
bool is_void_pointer () const
 Check if a particular type. More...
 
const bool & as_bool () const
 Cast to the internal type. More...
 
const casadi_int & as_int () const
 Cast to the internal type. More...
 
const double & as_double () const
 Cast to the internal type. More...
 
const std::string & as_string () const
 Cast to the internal type. More...
 
const std::vector< casadi_int > & as_int_vector () const
 Cast to the internal type. More...
 
const std::vector< casadi_int > & as_bool_vector () const
 Cast to the internal type. More...
 
const std::vector< std::vector< casadi_int > > & as_int_vector_vector () const
 Cast to the internal type. More...
 
const std::vector< double > & as_double_vector () const
 Cast to the internal type. More...
 
const std::vector< std::vector< double > > & as_double_vector_vector () const
 Cast to the internal type. More...
 
const std::vector< std::string > & as_string_vector () const
 Cast to the internal type. More...
 
const std::vector< std::vector< std::string > > & as_string_vector_vector () const
 Cast to the internal type. More...
 
const Dictas_dict () const
 Cast to the internal type. More...
 
const std::vector< Dict > & as_dict_vector () const
 Cast to the internal type. More...
 
const std::vector< std::vector< GenericType > > & as_vector_vector () const
 Cast to the internal type. More...
 
const std::vector< GenericType > & as_vector () const
 Cast to the internal type. More...
 
const Functionas_function () const
 Cast to the internal type. More...
 
const std::vector< Function > & as_function_vector () const
 Cast to the internal type. More...
 
void *const & as_void_pointer () const
 Cast to the internal type. More...
 
bool to_bool () const
 Convert to a type. More...
 
casadi_int to_int () const
 Convert to a type. More...
 
double to_double () const
 Convert to a type. More...
 
std::string to_string () const
 Convert to a type. More...
 
std::vector< casadi_int > to_int_vector () const
 Convert to a type. More...
 
std::vector< bool > to_bool_vector () const
 Convert to a type. More...
 
std::vector< std::vector< casadi_int > > to_int_vector_vector () const
 Convert to a type. More...
 
std::vector< double > to_double_vector () const
 Convert to a type. More...
 
std::vector< std::vector< double > > to_double_vector_vector () const
 Convert to a type. More...
 
std::vector< std::string > to_string_vector () const
 Convert to a type. More...
 
std::vector< std::vector< std::string > > to_string_vector_vector () const
 Convert to a type. More...
 
Dict to_dict () const
 Convert to a type. More...
 
std::vector< Dictto_dict_vector () const
 Convert to a type. More...
 
std::vector< GenericTypeto_vector () const
 Convert to a type. More...
 
std::vector< std::vector< GenericType > > to_vector_vector () const
 Convert to a type. More...
 
Function to_function () const
 Convert to a type. More...
 
std::vector< Functionto_function_vector () const
 Convert to a type. More...
 
void * to_void_pointer () const
 Convert to a type. More...
 
std::vector< int > to_int_type_vector () const
 Convert to a type. More...
 

Static Public Member Functions

static std::string type_name ()
 Public class name. More...
 
static std::string get_type_description (TypeID type)
 Get a description of a type. More...
 
static GenericType create (SharedObjectInternal *node)
 Create from node. More...
 
static GenericType from_type (TypeID type)
 Construct a GenericType given an TypeID. More...
 
static GenericType 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.

◆ Dict

typedef std::map<std::string, GenericType> casadi::GenericType::Dict

Definition at line 80 of file generic_type.hpp.

◆ internal_base_type

Definition at line 102 of file shared_object.hpp.

Constructor & Destructor Documentation

◆ GenericType() [1/22]

casadi::GenericType::GenericType ( )

Definition at line 249 of file generic_type.cpp.

249  {
250  }

◆ GenericType() [2/22]

casadi::GenericType::GenericType ( bool  b)

Definition at line 252 of file generic_type.cpp.

252  {
253  own(new BoolType(b));
254  }
GenericTypeInternal< OT_BOOL, bool > BoolType

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

◆ GenericType() [3/22]

casadi::GenericType::GenericType ( casadi_int  i)

Definition at line 256 of file generic_type.cpp.

256  {
257  own(new IntType(i));
258  }
GenericTypeInternal< OT_INT, casadi_int > IntType

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

◆ GenericType() [4/22]

casadi::GenericType::GenericType ( int  i)
inline

Definition at line 90 of file generic_type.hpp.

90 : GenericType(static_cast<casadi_int>(i)) {}
GenericType()
Default constructor.

◆ GenericType() [5/22]

casadi::GenericType::GenericType ( double  d)

Definition at line 260 of file generic_type.cpp.

260  {
261  own(new DoubleType(d));
262  }
GenericTypeInternal< OT_DOUBLE, double > DoubleType

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

◆ GenericType() [6/22]

casadi::GenericType::GenericType ( const std::string &  s)

Definition at line 300 of file generic_type.cpp.

300  {
301  own(new StringType(s));
302  }
GenericTypeInternal< OT_STRING, std::string > StringType

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

◆ GenericType() [7/22]

casadi::GenericType::GenericType ( const std::vector< bool > &  iv)

Definition at line 278 of file generic_type.cpp.

278  {
279  std::vector<casadi_int> i_vec(b_vec.size());
280  std::copy(b_vec.begin(), b_vec.end(), i_vec.begin());
281  own(new IntVectorType(i_vec));
282  }
GenericTypeInternal< OT_INTVECTOR, std::vector< casadi_int > > IntVectorType

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

◆ GenericType() [8/22]

casadi::GenericType::GenericType ( const std::vector< casadi_int > &  iv)

Definition at line 264 of file generic_type.cpp.

264  {
265  own(new IntVectorType(iv));
266  }

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

◆ GenericType() [9/22]

casadi::GenericType::GenericType ( const std::vector< int > &  iv)

Definition at line 268 of file generic_type.cpp.

268  {
269  std::vector<casadi_int> temp(iv.size());
270  std::copy(iv.begin(), iv.end(), temp.begin());
271  own(new IntVectorType(temp));
272  }

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

◆ GenericType() [10/22]

casadi::GenericType::GenericType ( const std::vector< std::vector< casadi_int > > &  ivv)

Definition at line 274 of file generic_type.cpp.

274  {
275  own(new IntVectorVectorType(ivv));
276  }
GenericTypeInternal< OT_INTVECTORVECTOR, std::vector< std::vector< casadi_int > > > IntVectorVectorType

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

◆ GenericType() [11/22]

casadi::GenericType::GenericType ( const std::vector< double > &  dv)

Definition at line 284 of file generic_type.cpp.

284  {
285  own(new DoubleVectorType(dv));
286  }
GenericTypeInternal< OT_DOUBLEVECTOR, std::vector< double > > DoubleVectorType

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

◆ GenericType() [12/22]

casadi::GenericType::GenericType ( const std::vector< std::vector< double > > &  dv)

Definition at line 288 of file generic_type.cpp.

288  {
289  own(new DoubleVectorVectorType(dv));
290  }
GenericTypeInternal< OT_DOUBLEVECTORVECTOR, std::vector< std::vector< double > > > DoubleVectorVectorType

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

◆ GenericType() [13/22]

casadi::GenericType::GenericType ( const std::vector< std::string > &  sv)

Definition at line 292 of file generic_type.cpp.

292  {
293  own(new StringVectorType(sv));
294  }
GenericTypeInternal< OT_STRINGVECTOR, std::vector< std::string > > StringVectorType

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

◆ GenericType() [14/22]

casadi::GenericType::GenericType ( const std::vector< std::vector< std::string > > &  sv)

Definition at line 296 of file generic_type.cpp.

296  {
297  own(new StringVectorVectorType(sv));
298  }
GenericTypeInternal< OT_STRINGVECTORVECTOR, std::vector< std::vector< std::string > > > StringVectorVectorType

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

◆ GenericType() [15/22]

casadi::GenericType::GenericType ( const char  s[])

Definition at line 304 of file generic_type.cpp.

304  {
305  own(new StringType(s));
306  }

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

◆ GenericType() [16/22]

casadi::GenericType::GenericType ( const Function f)

Definition at line 308 of file generic_type.cpp.

308  {
309  own(new FunctionType(f));
310  }
GenericTypeInternal< OT_FUNCTION, Function > FunctionType

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

◆ GenericType() [17/22]

casadi::GenericType::GenericType ( const std::vector< Function > &  f)

Definition at line 312 of file generic_type.cpp.

312  {
313  own(new FunctionVectorType(f));
314  }
GenericTypeInternal< OT_FUNCTIONVECTOR, std::vector< Function > > FunctionVectorType

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

◆ GenericType() [18/22]

casadi::GenericType::GenericType ( const Dict dict)

Definition at line 714 of file generic_type.cpp.

714  {
715  own(new DictType(dict));
716  }
GenericTypeInternal< OT_DICT, Dict > DictType

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

◆ GenericType() [19/22]

casadi::GenericType::GenericType ( const std::vector< Dict > &  dictv)

Definition at line 718 of file generic_type.cpp.

718  {
719  own(new DictVectorType(dictv));
720  }
GenericTypeInternal< OT_DICTVECTOR, std::vector< Dict > > DictVectorType

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

◆ GenericType() [20/22]

casadi::GenericType::GenericType ( const std::vector< std::vector< GenericType > > &  gvv)

Definition at line 726 of file generic_type.cpp.

726  {
727  own(new VectorVectorType(gvv));
728  }
GenericTypeInternal< OT_VECTORVECTOR, std::vector< std::vector< GenericType > > > VectorVectorType

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

◆ GenericType() [21/22]

casadi::GenericType::GenericType ( const std::vector< GenericType > &  gv)

Definition at line 722 of file generic_type.cpp.

722  {
723  own(new VectorType(gv));
724  }
GenericTypeInternal< OT_VECTOR, std::vector< GenericType > > VectorType

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

◆ GenericType() [22/22]

casadi::GenericType::GenericType ( void *  ptr)

Definition at line 730 of file generic_type.cpp.

730  {
731  own(new VoidPointerType(ptr));
732  }
GenericTypeInternal< OT_VOIDPTR, void * > VoidPointerType

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

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  }

◆ as_bool()

const bool & casadi::GenericType::as_bool ( ) const

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

Definition at line 316 of file generic_type.cpp.

316  {
317  casadi_assert_dev(is_bool());
318  return static_cast<const BoolType*>(get())->d_;
319  }
SharedObjectInternal * get() const
Get a const pointer to the node.
bool is_bool() const
Check if a particular type.

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

Referenced by to_bool().

◆ as_bool_vector()

const std::vector< casadi_int > & casadi::GenericType::as_bool_vector ( ) const

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

Definition at line 341 of file generic_type.cpp.

341  {
342  casadi_assert_dev(is_bool_vector());
343  return static_cast<const IntVectorType*>(get())->d_;
344  }
bool is_bool_vector() const
Check if a particular type.

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

Referenced by to_vector().

◆ as_dict()

const GenericType::Dict & casadi::GenericType::as_dict ( ) const

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

Definition at line 371 of file generic_type.cpp.

371  {
372  casadi_assert_dev(is_dict());
373  return static_cast<const DictType*>(get())->d_;
374  }
bool is_dict() const
Check if a particular type.

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

Referenced by to_dict(), and to_dict_vector().

◆ as_dict_vector()

const std::vector< GenericType::Dict > & casadi::GenericType::as_dict_vector ( ) const

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

Definition at line 376 of file generic_type.cpp.

376  {
377  casadi_assert_dev(is_dict_vector());
378  return static_cast<const DictVectorType*>(get())->d_;
379  }
bool is_dict_vector() const
Check if a particular type.

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

Referenced by is_empty_vector(), to_dict_vector(), and to_vector().

◆ as_double()

const double & casadi::GenericType::as_double ( ) const

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

Definition at line 326 of file generic_type.cpp.

326  {
327  casadi_assert_dev(is_double());
328  return static_cast<const DoubleType*>(get())->d_;
329  }
bool is_double() const
Check if a particular type.

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

Referenced by to_double().

◆ as_double_vector()

const std::vector< double > & casadi::GenericType::as_double_vector ( ) const

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

Definition at line 351 of file generic_type.cpp.

351  {
352  casadi_assert_dev(is_double_vector());
353  return static_cast<const DoubleVectorType*>(get())->d_;
354  }
bool is_double_vector() const
Check if a particular type.

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

Referenced by to_double_vector(), to_string_vector(), and to_vector().

◆ as_double_vector_vector()

const std::vector< std::vector< double > > & casadi::GenericType::as_double_vector_vector ( ) const

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

Definition at line 356 of file generic_type.cpp.

356  {
357  casadi_assert_dev(is_double_vector_vector());
358  return static_cast<const DoubleVectorVectorType*>(get())->d_;
359  }
bool is_double_vector_vector() const
Check if a particular type.

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

Referenced by to_double_vector_vector(), to_vector(), and to_vector_vector().

◆ as_function()

const Function & casadi::GenericType::as_function ( ) const

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

Definition at line 391 of file generic_type.cpp.

391  {
392  casadi_assert_dev(is_function());
393  return static_cast<const FunctionType*>(get())->d_;
394  }
bool is_function() const
Check if a particular type.

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

Referenced by to_function().

◆ as_function_vector()

const std::vector< Function > & casadi::GenericType::as_function_vector ( ) const

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

Definition at line 396 of file generic_type.cpp.

396  {
397  casadi_assert_dev(is_function_vector());
398  return static_cast<const FunctionVectorType*>(get())->d_;
399  }
bool is_function_vector() const
Check if a particular type.

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

Referenced by to_function_vector(), and to_vector().

◆ as_int()

const casadi_int & casadi::GenericType::as_int ( ) const

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

Definition at line 321 of file generic_type.cpp.

321  {
322  casadi_assert_dev(is_int());
323  return static_cast<const IntType*>(get())->d_;
324  }
bool is_int() const
Check if a particular type.

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

Referenced by to_int(), and to_void_pointer().

◆ as_int_vector()

const std::vector< casadi_int > & casadi::GenericType::as_int_vector ( ) const

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

Definition at line 336 of file generic_type.cpp.

336  {
337  casadi_assert_dev(is_int_vector());
338  return static_cast<const IntVectorType*>(get())->d_;
339  }
bool is_int_vector() const
Check if a particular type.

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

Referenced by to_double_vector(), to_int_type_vector(), to_int_vector(), to_string_vector(), and to_vector().

◆ as_int_vector_vector()

const std::vector< std::vector< casadi_int > > & casadi::GenericType::as_int_vector_vector ( ) const

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

Definition at line 346 of file generic_type.cpp.

346  {
347  casadi_assert_dev(is_int_vector_vector());
348  return static_cast<const IntVectorVectorType*>(get())->d_;
349  }
bool is_int_vector_vector() const
Check if a particular type.

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

Referenced by to_double_vector_vector(), to_int_vector_vector(), to_vector(), and to_vector_vector().

◆ as_string()

const std::string & casadi::GenericType::as_string ( ) const

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

Definition at line 331 of file generic_type.cpp.

331  {
332  casadi_assert_dev(is_string());
333  return static_cast<const StringType*>(get())->d_;
334  }
bool is_string() const
Check if a particular type.

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

Referenced by to_string(), and to_string_vector().

◆ as_string_vector()

const std::vector< std::string > & casadi::GenericType::as_string_vector ( ) const

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

Definition at line 361 of file generic_type.cpp.

361  {
362  casadi_assert_dev(is_string_vector());
363  return static_cast<const StringVectorType*>(get())->d_;
364  }
bool is_string_vector() const
Check if a particular type.

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

Referenced by to_string_vector(), and to_vector().

◆ as_string_vector_vector()

const std::vector< std::vector< std::string > > & casadi::GenericType::as_string_vector_vector ( ) const

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

Definition at line 366 of file generic_type.cpp.

366  {
367  casadi_assert_dev(is_string_vector_vector());
368  return static_cast<const StringVectorVectorType*>(get())->d_;
369  }
bool is_string_vector_vector() const
Check if a particular type.

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

Referenced by to_string_vector_vector(), to_vector(), and to_vector_vector().

◆ as_vector()

const std::vector< GenericType > & casadi::GenericType::as_vector ( ) const

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

Definition at line 386 of file generic_type.cpp.

386  {
387  casadi_assert_dev(is_vector());
388  return static_cast<const VectorType*>(get())->d_;
389  }
bool is_vector() const
Check if a particular type.

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

Referenced by to_vector().

◆ as_vector_vector()

const std::vector< std::vector< GenericType > > & casadi::GenericType::as_vector_vector ( ) const

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

Definition at line 381 of file generic_type.cpp.

381  {
382  casadi_assert_dev(is_vector_vector());
383  return static_cast<const VectorVectorType*>(get())->d_;
384  }
bool is_vector_vector() const
Check if a particular type.

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

Referenced by to_vector(), and to_vector_vector().

◆ as_void_pointer()

void *const & casadi::GenericType::as_void_pointer ( ) const

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

Definition at line 401 of file generic_type.cpp.

401  {
402  casadi_assert_dev(is_void_pointer());
403  return static_cast<const VoidPointerType*>(get())->d_;
404  }
bool is_void_pointer() const
Check if a particular type.

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

Referenced by to_void_pointer().

◆ 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  }

◆ can_cast_to() [1/2]

bool casadi::GenericType::can_cast_to ( const GenericType other) const
inline

Definition at line 161 of file generic_type.hpp.

161 { return can_cast_to(other.getType()) ;}
bool can_cast_to(TypeID other) const

References can_cast_to(), and getType().

Referenced by can_cast_to().

◆ can_cast_to() [2/2]

bool casadi::GenericType::can_cast_to ( TypeID  other) const

Definition at line 60 of file generic_type.cpp.

60  {
61  switch (other) {
62  case OT_BOOL:
63  return is_bool() || is_int() || is_double();
64  case OT_BOOLVECTOR:
65  return is_int_vector() || is_double_vector();
66  case OT_INT:
67  case OT_DOUBLE:
68  return is_int() || is_double();
69  case OT_INTVECTOR:
70  case OT_DOUBLEVECTOR:
71  return is_double_vector() || is_int_vector();
72  case OT_INTVECTORVECTOR:
75  case OT_STRINGVECTOR:
77  case OT_VECTOR:
78  return is_vector() || is_double_vector() || is_int_vector() || is_string_vector() ||
82  case OT_VECTORVECTOR:
83  return is_vector_vector() ||
85  case OT_VOIDPTR:
86  return is_void_pointer() || is_int();
87  default:
88  return getType() == other;
89  }
90  }
TypeID getType() const
@ OT_STRINGVECTOR
@ OT_BOOLVECTOR
@ OT_INTVECTOR
@ OT_DOUBLEVECTORVECTOR
@ OT_VECTORVECTOR
@ OT_INTVECTORVECTOR
@ OT_DOUBLEVECTOR

References getType(), is_bool(), is_bool_vector(), is_dict_vector(), is_double(), is_double_vector(), is_double_vector_vector(), is_function_vector(), is_int(), is_int_vector(), is_int_vector_vector(), is_string(), is_string_vector(), is_string_vector_vector(), is_vector(), is_vector_vector(), is_void_pointer(), casadi::OT_BOOL, casadi::OT_BOOLVECTOR, casadi::OT_DOUBLE, casadi::OT_DOUBLEVECTOR, casadi::OT_DOUBLEVECTORVECTOR, casadi::OT_INT, casadi::OT_INTVECTOR, casadi::OT_INTVECTORVECTOR, casadi::OT_STRINGVECTOR, casadi::OT_VECTOR, casadi::OT_VECTORVECTOR, and casadi::OT_VOIDPTR.

◆ 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()

GenericType casadi::GenericType::create ( SharedObjectInternal node)
static

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

Definition at line 789 of file generic_type.cpp.

789  {
790  GenericType ret;
791  ret.own(node);
792  return ret;
793  }

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

◆ 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()

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

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

Definition at line 747 of file generic_type.cpp.

747  {
748  int itype;
749  s.unpack("GenericType::type", itype);
750  TypeID type = static_cast<TypeID>(itype);
751  switch (type) {
752  case OT_STRING:
753  return StringType::deserialize(s);
754  case OT_DOUBLE:
755  return DoubleType::deserialize(s);
756  case OT_INT:
757  return IntType::deserialize(s);
758  case OT_BOOL:
759  return BoolType::deserialize(s);
760  case OT_DOUBLEVECTOR:
764  case OT_INTVECTOR:
765  return IntVectorType::deserialize(s);
766  case OT_INTVECTORVECTOR:
768  case OT_STRINGVECTOR:
772  case OT_FUNCTION:
773  return FunctionType::deserialize(s);
774  case OT_FUNCTIONVECTOR:
776  case OT_DICT:
777  return DictType::deserialize(s);
778  case OT_DICTVECTOR:
779  return VectorType::deserialize(s);
780  case OT_VECTOR:
781  return VectorType::deserialize(s);
782  case OT_VECTORVECTOR:
784  default:
785  casadi_error("Not implemented: " + get_type_description(type));
786  }
787  }
static GenericType deserialize(DeserializingStream &s)
static std::string get_type_description(TypeID type)
Get a description of a type.
TypeID
Types of options.
@ OT_STRINGVECTORVECTOR
@ OT_FUNCTIONVECTOR
@ OT_DICTVECTOR

References casadi::GenericTypeInternal< ID, T >::deserialize(), get_type_description(), casadi::OT_BOOL, casadi::OT_DICT, casadi::OT_DICTVECTOR, casadi::OT_DOUBLE, casadi::OT_DOUBLEVECTOR, casadi::OT_DOUBLEVECTORVECTOR, casadi::OT_FUNCTION, casadi::OT_FUNCTIONVECTOR, casadi::OT_INT, casadi::OT_INTVECTOR, casadi::OT_INTVECTORVECTOR, casadi::OT_STRING, casadi::OT_STRINGVECTOR, casadi::OT_STRINGVECTORVECTOR, casadi::OT_VECTOR, casadi::OT_VECTORVECTOR, and casadi::DeserializingStream::unpack().

◆ 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().

◆ from_type()

GenericType casadi::GenericType::from_type ( TypeID  type)
static

Definition at line 92 of file generic_type.cpp.

92  {
93  switch (type) {
94  case OT_INTVECTOR:
95  return std::vector<casadi_int>();
96  case OT_INTVECTORVECTOR:
97  return std::vector< std::vector<casadi_int> >();
98  case OT_BOOLVECTOR:
99  return std::vector<bool>();
100  case OT_DOUBLEVECTOR:
101  return std::vector<double>();
103  return std::vector< std::vector<double> >();
104  case OT_STRINGVECTOR:
105  return std::vector<std::string>();
107  return std::vector<std::vector<std::string> >();
108  case OT_DICTVECTOR:
109  return std::vector<GenericType::Dict>();
110  case OT_VECTORVECTOR:
111  return std::vector<std::vector< GenericType> >();
112  case OT_VECTOR:
113  return std::vector<GenericType>();
114  default:
115  casadi_error("empty_from_type. Unsupported type " + str(type));
116  }
117  }
std::string str(const T &v)
String representation, any type.

References casadi::OT_BOOLVECTOR, casadi::OT_DICTVECTOR, casadi::OT_DOUBLEVECTOR, casadi::OT_DOUBLEVECTORVECTOR, casadi::OT_INTVECTOR, casadi::OT_INTVECTORVECTOR, casadi::OT_STRINGVECTOR, casadi::OT_STRINGVECTORVECTOR, casadi::OT_VECTOR, casadi::OT_VECTORVECTOR, and casadi::str().

◆ get()

Definition at line 100 of file generic_shared_impl.hpp.

104  {
105  return node;
106  }

◆ get_description()

std::string casadi::GenericType::get_description ( ) const
inline

Definition at line 128 of file generic_type.hpp.

128 { return get_type_description(getType()); }

◆ 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.

◆ get_type_description()

std::string casadi::GenericType::get_type_description ( TypeID  type)
static

Definition at line 119 of file generic_type.cpp.

119  {
120  switch (type) {
121  case OT_BOOL:
122  return "OT_BOOL";
123  case OT_INT:
124  return "OT_INT";
125  case OT_DOUBLE:
126  return "OT_DOUBLE";
127  case OT_STRING:
128  return "OT_STRING";
129  case OT_INTVECTOR:
130  return "OT_INTVECTOR";
131  case OT_INTVECTORVECTOR:
132  return "OT_INTVECTORVECTOR";
133  case OT_BOOLVECTOR:
134  return "OT_BOOLVECTOR";
135  case OT_DOUBLEVECTOR:
136  return "OT_DOUBLEVECTOR";
138  return "OT_DOUBLEVECTORVECTOR";
139  case OT_STRINGVECTOR:
140  return "OT_STRINGVECTOR";
142  return "OT_STRINGVECTORVECTOR";
143  case OT_DICT:
144  return "OT_DICT";
145  case OT_DICTVECTOR:
146  return "OT_DICTVECTOR";
147  case OT_VECTORVECTOR:
148  return "OT_VECTORVECTOR";
149  case OT_VECTOR:
150  return "OT_VECTOR";
151  case OT_FUNCTION:
152  return "OT_FUNCTION";
153  case OT_FUNCTIONVECTOR:
154  return "OT_FUNCTIONVECTOR";
155  case OT_VOIDPTR:
156  return "OT_VOIDPTR";
157  default:
158  return "OT_UNKNOWN";
159 
160  }
161  }

References casadi::OT_BOOL, casadi::OT_BOOLVECTOR, casadi::OT_DICT, casadi::OT_DICTVECTOR, casadi::OT_DOUBLE, casadi::OT_DOUBLEVECTOR, casadi::OT_DOUBLEVECTORVECTOR, casadi::OT_FUNCTION, casadi::OT_FUNCTIONVECTOR, casadi::OT_INT, casadi::OT_INTVECTOR, casadi::OT_INTVECTORVECTOR, casadi::OT_STRING, casadi::OT_STRINGVECTOR, casadi::OT_STRINGVECTORVECTOR, casadi::OT_VECTOR, casadi::OT_VECTORVECTOR, and casadi::OT_VOIDPTR.

Referenced by casadi::Options::check(), deserialize(), casadi::Options::Entry::disp(), and casadi::Options::type().

◆ 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  }

◆ getType()

TypeID casadi::GenericType::getType ( ) const

◆ is_bool()

bool casadi::GenericType::is_bool ( ) const

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

Definition at line 164 of file generic_type.cpp.

164  {
165  return getType()==OT_BOOL;
166  }

References getType(), and casadi::OT_BOOL.

Referenced by as_bool(), can_cast_to(), to_bool(), and to_int().

◆ is_bool_vector()

bool casadi::GenericType::is_bool_vector ( ) const

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

Definition at line 197 of file generic_type.cpp.

197  {
198  return getType()==OT_BOOLVECTOR;
199  }

References getType(), and casadi::OT_BOOLVECTOR.

Referenced by as_bool_vector(), can_cast_to(), is_empty_vector(), and to_vector().

◆ is_dict()

bool casadi::GenericType::is_dict ( ) const

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

Definition at line 233 of file generic_type.cpp.

233  {
234  return getType()==OT_DICT;
235  }

References getType(), and casadi::OT_DICT.

Referenced by as_dict(), casadi::Options::sanitize(), to_dict(), to_dict_vector(), and casadi::update_dict().

◆ is_dict_vector()

bool casadi::GenericType::is_dict_vector ( ) const

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

Definition at line 237 of file generic_type.cpp.

237  {
238  return getType()==OT_DICTVECTOR;
239  }

References getType(), and casadi::OT_DICTVECTOR.

Referenced by as_dict_vector(), can_cast_to(), is_empty_vector(), to_dict_vector(), and to_vector().

◆ is_double()

bool casadi::GenericType::is_double ( ) const

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

Definition at line 172 of file generic_type.cpp.

172  {
173  return getType()==OT_DOUBLE;
174  }

References getType(), and casadi::OT_DOUBLE.

Referenced by as_double(), can_cast_to(), operator!=(), to_double(), and to_int().

◆ is_double_vector()

bool casadi::GenericType::is_double_vector ( ) const

◆ is_double_vector_vector()

bool casadi::GenericType::is_double_vector_vector ( ) const

◆ is_empty_vector()

bool casadi::GenericType::is_empty_vector ( ) const

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

Definition at line 180 of file generic_type.cpp.

180  {
181  return (is_int_vector() && to_int_vector().empty()) ||
182  (is_int_vector_vector() && to_int_vector_vector().empty()) ||
184  (is_double_vector() && to_double_vector().empty()) ||
185  (is_string_vector() && to_string_vector().empty()) ||
187  (is_bool_vector() && to_bool_vector().empty()) ||
188  (is_dict_vector() && as_dict_vector().empty()) ||
189  (is_vector_vector() && to_vector_vector().empty()) ||
190  (is_vector() && to_vector().empty());
191  }
std::vector< std::vector< casadi_int > > to_int_vector_vector() const
Convert to a type.
const std::vector< Dict > & as_dict_vector() const
Cast to the internal type.
std::vector< std::vector< GenericType > > to_vector_vector() const
Convert to a type.
std::vector< std::vector< double > > to_double_vector_vector() const
Convert to a type.
std::vector< double > to_double_vector() const
Convert to a type.
std::vector< casadi_int > to_int_vector() const
Convert to a type.
std::vector< GenericType > to_vector() const
Convert to a type.
std::vector< std::string > to_string_vector() const
Convert to a type.
std::vector< std::vector< std::string > > to_string_vector_vector() const
Convert to a type.
std::vector< bool > to_bool_vector() const
Convert to a type.

References as_dict_vector(), is_bool_vector(), is_dict_vector(), is_double_vector(), is_double_vector_vector(), is_int_vector(), is_int_vector_vector(), is_string_vector(), is_string_vector_vector(), is_vector(), is_vector_vector(), to_bool_vector(), to_double_vector(), to_double_vector_vector(), to_int_vector(), to_int_vector_vector(), to_string_vector(), to_string_vector_vector(), to_vector(), and to_vector_vector().

Referenced by to_dict_vector().

◆ is_function()

bool casadi::GenericType::is_function ( ) const

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

Definition at line 221 of file generic_type.cpp.

221  {
222  return getType()==OT_FUNCTION;
223  }

References getType(), and casadi::OT_FUNCTION.

Referenced by as_function(), and to_function().

◆ is_function_vector()

bool casadi::GenericType::is_function_vector ( ) const

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

Definition at line 225 of file generic_type.cpp.

225  {
226  return getType()==OT_FUNCTIONVECTOR;
227  }

References getType(), and casadi::OT_FUNCTIONVECTOR.

Referenced by as_function_vector(), can_cast_to(), to_function_vector(), and to_vector().

◆ is_int()

bool casadi::GenericType::is_int ( ) const

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

Definition at line 168 of file generic_type.cpp.

168  {
169  return getType()==OT_INT;
170  }

References getType(), and casadi::OT_INT.

Referenced by as_int(), can_cast_to(), operator!=(), to_bool(), to_double(), and to_int().

◆ is_int_vector()

bool casadi::GenericType::is_int_vector ( ) const

◆ is_int_vector_vector()

bool casadi::GenericType::is_int_vector_vector ( ) const

◆ is_null()

Definition at line 117 of file generic_shared_impl.hpp.

109  {
110  return node==nullptr;
111  }

◆ is_string()

bool casadi::GenericType::is_string ( ) const

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

Definition at line 176 of file generic_type.cpp.

176  {
177  return getType()==OT_STRING;
178  }

References getType(), and casadi::OT_STRING.

Referenced by as_string(), can_cast_to(), operator!=(), to_string(), and to_string_vector().

◆ is_string_vector()

bool casadi::GenericType::is_string_vector ( ) const

◆ is_string_vector_vector()

bool casadi::GenericType::is_string_vector_vector ( ) const

◆ is_vector()

bool casadi::GenericType::is_vector ( ) const

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

Definition at line 245 of file generic_type.cpp.

245  {
246  return getType()==OT_VECTOR;
247  }

References getType(), and casadi::OT_VECTOR.

Referenced by as_vector(), can_cast_to(), is_empty_vector(), and to_vector().

◆ is_vector_vector()

bool casadi::GenericType::is_vector_vector ( ) const

◆ is_void_pointer()

bool casadi::GenericType::is_void_pointer ( ) const

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

Definition at line 229 of file generic_type.cpp.

229  {
230  return getType()==OT_VOIDPTR;
231  }

References getType(), and casadi::OT_VOIDPTR.

Referenced by as_void_pointer(), can_cast_to(), and to_void_pointer().

◆ operator bool()

casadi::GenericType::operator bool ( ) const
inline

Implicit typecasting

Definition at line 136 of file generic_type.hpp.

136 { return to_bool();}
bool to_bool() const
Convert to a type.

◆ operator casadi_int()

casadi::GenericType::operator casadi_int ( ) const
inline

Implicit typecasting

Definition at line 137 of file generic_type.hpp.

137 { return to_int();}
casadi_int to_int() const
Convert to a type.

References casadi::to_int().

◆ operator const Dict &()

casadi::GenericType::operator const Dict & ( ) const
inline

Implicit typecasting

Definition at line 154 of file generic_type.hpp.

154 { return as_dict();}
const Dict & as_dict() const
Cast to the internal type.

◆ operator const Function &()

casadi::GenericType::operator const Function & ( ) const
inline

Implicit typecasting

Definition at line 152 of file generic_type.hpp.

152 { return as_function();}
const Function & as_function() const
Cast to the internal type.

◆ operator const std::vector< Dict > &()

casadi::GenericType::operator const std::vector< Dict > & ( ) const
inline

Implicit typecasting

Definition at line 155 of file generic_type.hpp.

155 { return as_dict_vector();}

◆ operator const std::vector< Function > &()

casadi::GenericType::operator const std::vector< Function > & ( ) const
inline

Implicit typecasting

Definition at line 153 of file generic_type.hpp.

153 { return as_function_vector();}
const std::vector< Function > & as_function_vector() const
Cast to the internal type.

◆ operator const std::vector< GenericType > &()

casadi::GenericType::operator const std::vector< GenericType > & ( ) const
inline

Implicit typecasting

Definition at line 157 of file generic_type.hpp.

157 { return as_vector();}
const std::vector< GenericType > & as_vector() const
Cast to the internal type.

◆ operator const std::vector< std::vector< GenericType > > &()

casadi::GenericType::operator const std::vector< std::vector< GenericType > > & ( ) const
inline

Implicit typecasting

Definition at line 156 of file generic_type.hpp.

156 { return as_vector_vector();}
const std::vector< std::vector< GenericType > > & as_vector_vector() const
Cast to the internal type.

◆ operator double()

casadi::GenericType::operator double ( ) const
inline

Implicit typecasting

Definition at line 139 of file generic_type.hpp.

139 { return to_double();}
double to_double() const
Convert to a type.

◆ operator int()

casadi::GenericType::operator int ( ) const
inline

Implicit typecasting

Definition at line 138 of file generic_type.hpp.

138 { return to_int();}

References casadi::to_int().

◆ operator std::string()

casadi::GenericType::operator std::string ( ) const
inline

Implicit typecasting

Definition at line 140 of file generic_type.hpp.

140 { return to_string();}
std::string to_string() const
Convert to a type.

References casadi::to_string().

◆ operator std::vector< bool >()

casadi::GenericType::operator std::vector< bool > ( ) const
inline

Implicit typecasting

Definition at line 141 of file generic_type.hpp.

141 { return to_bool_vector();}

◆ operator std::vector< casadi_int >()

casadi::GenericType::operator std::vector< casadi_int > ( ) const
inline

Implicit typecasting

Definition at line 142 of file generic_type.hpp.

142 { return to_int_vector();}

◆ operator std::vector< double >()

casadi::GenericType::operator std::vector< double > ( ) const
inline

Implicit typecasting

Definition at line 146 of file generic_type.hpp.

146 { return to_double_vector();}

◆ operator std::vector< int >()

casadi::GenericType::operator std::vector< int > ( ) const

Implicit typecasting

Definition at line 452 of file generic_type.cpp.

452  {
453  std::vector<int> ret;
454  std::vector<casadi_int> source = to_int_vector();
455  return casadi::to_int(source);
456  }
int to_int(casadi_int rhs)
Definition: casadi_misc.cpp:56

References casadi::to_int().

◆ operator std::vector< std::string >()

casadi::GenericType::operator std::vector< std::string > ( ) const
inline

Implicit typecasting

Definition at line 150 of file generic_type.hpp.

150 { return to_string_vector();}

◆ operator std::vector< std::vector< casadi_int > >()

casadi::GenericType::operator std::vector< std::vector< casadi_int > > ( ) const
inline

Implicit typecasting

Definition at line 144 of file generic_type.hpp.

144 { return to_int_vector_vector();}

◆ operator std::vector< std::vector< double > >()

casadi::GenericType::operator std::vector< std::vector< double > > ( ) const
inline

Implicit typecasting

Definition at line 147 of file generic_type.hpp.

147  {
148  return to_double_vector_vector();
149  }

◆ operator std::vector< std::vector< int > >()

casadi::GenericType::operator std::vector< std::vector< int > > ( ) const

Implicit typecasting

◆ operator std::vector< std::vector< std::string > >()

casadi::GenericType::operator std::vector< std::vector< std::string > > ( ) const
inline

Implicit typecasting

Definition at line 151 of file generic_type.hpp.

151 { return to_string_vector_vector();}

◆ operator!=()

bool casadi::GenericType::operator!= ( const GenericType op2) const

Definition at line 653 of file generic_type.cpp.

653  {
654  if (is_string() && op2.is_string()) {
655  return to_string() != op2.to_string();
656  }
657 
658  if (is_int() && op2.is_int()) {
659  return to_int() != op2.to_int();
660  }
661 
662  if (is_double() && op2.is_double()) {
663  return to_double() != op2.to_double();
664  }
665 
666  if (is_double_vector() && op2.is_double_vector()) {
667  const std::vector<double> &v1 = to_double_vector();
668  const std::vector<double> &v2 = op2.to_double_vector();
669  if (v1.size() != v2.size()) return true;
670  for (casadi_int i=0; i<v1.size(); ++i)
671  if (v1[i] != v2[i]) return true;
672  return false;
673  }
674 
675  if (is_int_vector() && op2.is_int_vector()) {
676  const std::vector<casadi_int> &v1 = to_int_vector();
677  const std::vector<casadi_int> &v2 = op2.to_int_vector();
678  if (v1.size() != v2.size()) return true;
679  for (casadi_int i=0; i<v1.size(); ++i)
680  if (v1[i] != v2[i]) return true;
681  return false;
682  }
683 
684  if (is_int_vector_vector() && op2.is_int_vector_vector()) {
685  const std::vector< std::vector<casadi_int> > &v1 = to_int_vector_vector();
686  const std::vector< std::vector<casadi_int> > &v2 = op2.to_int_vector_vector();
687  if (v1.size() != v2.size()) return true;
688  for (casadi_int i=0; i<v1.size(); ++i) {
689  if (v1[i].size() != v2[i].size()) return true;
690  for (casadi_int j=0; j<v1[i].size(); ++j) {
691  if (v1[i][j] != v2[i][j]) return true;
692  }
693  }
694  return false;
695  }
696 
697  if (is_double_vector_vector() && op2.is_double_vector_vector()) {
698  const std::vector< std::vector<double> > &v1 = to_double_vector_vector();
699  const std::vector< std::vector<double> > &v2 = op2.to_double_vector_vector();
700  if (v1.size() != v2.size()) return true;
701  for (casadi_int i=0; i<v1.size(); ++i) {
702  if (v1[i].size() != v2[i].size()) return true;
703  for (casadi_int j=0; j<v1[i].size(); ++j) {
704  if (v1[i][j] != v2[i][j]) return true;
705  }
706  }
707  return false;
708  }
709 
710  // Different types
711  return true;
712  }

References is_double(), is_double_vector(), is_double_vector_vector(), is_int(), is_int_vector(), is_int_vector_vector(), is_string(), to_double(), to_double_vector(), to_double_vector_vector(), to_int(), to_int_vector(), to_int_vector_vector(), and to_string().

◆ operator->()

Definition at line 109 of file generic_shared_impl.hpp.

114  {
115  casadi_assert_dev(!is_null());
116  return node;
117  }

◆ operator==()

bool casadi::GenericType::operator== ( const GenericType op2) const

Definition at line 649 of file generic_type.cpp.

649  {
650  return !(*this != op2);
651  }

◆ 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.

◆ 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::GenericType::serialize ( SerializingStream s) const

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

Definition at line 742 of file generic_type.cpp.

742  {
743  s.pack("GenericType::type", static_cast<int>(getType()));
744  static_cast<const GenericTypeBase*>(get())->serialize(s);
745  }
void serialize(SerializingStream &s) const
Serialize an object.

References casadi::GenericShared< SharedObject, SharedObjectInternal >::get(), getType(), and casadi::SerializingStream::pack().

◆ 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  }

◆ to_bool()

bool casadi::GenericType::to_bool ( ) const

Definition at line 406 of file generic_type.cpp.

406  {
407  if (is_bool()) {
408  return as_bool();
409  } else if (is_int()) {
410  return static_cast<bool>(to_int());
411  } else {
412  casadi_assert(is_bool(), "type mismatch");
413  return false;
414  }
415  }
const bool & as_bool() const
Cast to the internal type.

References as_bool(), is_bool(), is_int(), and to_int().

Referenced by to_int().

◆ to_bool_vector()

std::vector< bool > casadi::GenericType::to_bool_vector ( ) const

Definition at line 458 of file generic_type.cpp.

458  {
459  casadi_assert(is_int_vector(), "type mismatch");
460  std::vector<casadi_int> v = to_int_vector();
461  std::vector<bool> ret(v.size());
462  for (casadi_int i=0; i<v.size(); ++i) {
463  casadi_assert(v[i]==0 || v[i]==1, "Entries must be zero or one");
464  ret[i] = v[i]==1;
465  }
466  return ret;
467  }

References is_int_vector(), and to_int_vector().

Referenced by is_empty_vector().

◆ to_dict()

Dict casadi::GenericType::to_dict ( ) const

Definition at line 520 of file generic_type.cpp.

520  {
521  casadi_assert(is_dict(), "type mismatch");
522  return as_dict();
523  }

References as_dict(), and is_dict().

◆ to_dict_vector()

std::vector< Dict > casadi::GenericType::to_dict_vector ( ) const

Definition at line 525 of file generic_type.cpp.

525  {
526  if (is_empty_vector()) return {};
527  if (is_dict()) {
528  Dict e = as_dict();
529  return std::vector<Dict>(1, e);
530  }
531  casadi_assert(is_dict_vector(), "type mismatch");
532  return as_dict_vector();
533  }
std::map< std::string, GenericType > Dict
C++ equivalent of Python's dict or MATLAB's struct.
bool is_empty_vector() const
Check if a particular type.

References as_dict(), as_dict_vector(), is_dict(), is_dict_vector(), and is_empty_vector().

◆ to_double()

double casadi::GenericType::to_double ( ) const

Definition at line 428 of file generic_type.cpp.

428  {
429  if (is_int()) {
430  return static_cast<double>(to_int());
431  } else {
432  casadi_assert(is_double(), "type mismatch");
433  return as_double();
434  }
435  }
const double & as_double() const
Cast to the internal type.

References as_double(), is_double(), is_int(), and to_int().

Referenced by operator!=(), and to_int().

◆ to_double_vector()

std::vector< double > casadi::GenericType::to_double_vector ( ) const

Definition at line 474 of file generic_type.cpp.

474  {
475  if (is_int_vector()) {
476  auto v = as_int_vector();
477  return std::vector<double>(v.begin(), v.end());
478  } else {
479  casadi_assert(is_double_vector(), "type mismatch");
480  return as_double_vector();
481  }
482  }
const std::vector< double > & as_double_vector() const
Cast to the internal type.
const std::vector< casadi_int > & as_int_vector() const
Cast to the internal type.

References as_double_vector(), as_int_vector(), is_double_vector(), and is_int_vector().

Referenced by is_empty_vector(), and operator!=().

◆ to_double_vector_vector()

std::vector< std::vector< double > > casadi::GenericType::to_double_vector_vector ( ) const

Definition at line 484 of file generic_type.cpp.

484  {
485  if (is_int_vector_vector()) {
486  auto v = as_int_vector_vector();
487  std::vector< std::vector<double> > ret(v.size());
488  for (casadi_int i=0;i<v.size();++i)
489  ret[i].assign(v[i].begin(), v[i].end());
490  return ret;
491  } else {
492  casadi_assert(is_double_vector_vector(), "type mismatch");
493  return as_double_vector_vector();
494  }
495  }
void assign(SharedObjectInternal *node)
Assign the node to a node class pointer without reference counting.
const std::vector< std::vector< casadi_int > > & as_int_vector_vector() const
Cast to the internal type.
const std::vector< std::vector< double > > & as_double_vector_vector() const
Cast to the internal type.

References as_double_vector_vector(), as_int_vector_vector(), casadi::GenericShared< SharedObject, SharedObjectInternal >::assign(), is_double_vector_vector(), and is_int_vector_vector().

Referenced by is_empty_vector(), and operator!=().

◆ to_function()

Function casadi::GenericType::to_function ( ) const

Definition at line 629 of file generic_type.cpp.

629  {
630  casadi_assert(is_function(), "type mismatch");
631  return as_function();
632  }

References as_function(), and is_function().

◆ to_function_vector()

std::vector< Function > casadi::GenericType::to_function_vector ( ) const

Definition at line 634 of file generic_type.cpp.

634  {
635  casadi_assert(is_function_vector(), "type mismatch");
636  return as_function_vector();
637  }

References as_function_vector(), and is_function_vector().

◆ to_int()

casadi_int casadi::GenericType::to_int ( ) const

Definition at line 417 of file generic_type.cpp.

417  {
418  if (is_double()) {
419  return static_cast<casadi_int>(to_double());
420  } else if (is_bool()) {
421  return static_cast<casadi_int>(to_bool());
422  } else {
423  casadi_assert(is_int(), "type mismatch");
424  return as_int();
425  }
426  }
const casadi_int & as_int() const
Cast to the internal type.

References as_int(), is_bool(), is_double(), is_int(), to_bool(), and to_double().

Referenced by operator!=(), to_bool(), and to_double().

◆ to_int_type_vector()

std::vector< int > casadi::GenericType::to_int_type_vector ( ) const

Definition at line 442 of file generic_type.cpp.

442  {
443  casadi_assert(is_int_vector(), "type mismatch");
444  return casadi::to_int(as_int_vector());
445  }

References as_int_vector(), is_int_vector(), and casadi::to_int().

◆ to_int_vector()

std::vector< casadi_int > casadi::GenericType::to_int_vector ( ) const

Definition at line 447 of file generic_type.cpp.

447  {
448  casadi_assert(is_int_vector(), "type mismatch");
449  return as_int_vector();
450  }

References as_int_vector(), and is_int_vector().

Referenced by is_empty_vector(), operator!=(), and to_bool_vector().

◆ to_int_vector_vector()

std::vector< std::vector< casadi_int > > casadi::GenericType::to_int_vector_vector ( ) const

Definition at line 469 of file generic_type.cpp.

469  {
470  casadi_assert(is_int_vector_vector(), "type mismatch");
471  return as_int_vector_vector();
472  }

References as_int_vector_vector(), and is_int_vector_vector().

Referenced by is_empty_vector(), and operator!=().

◆ to_string()

std::string casadi::GenericType::to_string ( ) const

Definition at line 437 of file generic_type.cpp.

437  {
438  casadi_assert(is_string(), "type mismatch");
439  return as_string();
440  }
const std::string & as_string() const
Cast to the internal type.

References as_string(), and is_string().

Referenced by casadi::ResourceInternal::change_option(), casadi::FunctionInternal::change_option(), and operator!=().

◆ to_string_vector()

std::vector< std::string > casadi::GenericType::to_string_vector ( ) const

Definition at line 497 of file generic_type.cpp.

497  {
498  if (is_string()) {
499  std::string s = as_string();
500  return std::vector<std::string>(1, s);
501  } else if (is_double_vector()) {
502  auto v = as_double_vector();
503  casadi_assert(v.empty(), "Cast only permitted for zero-length vectors");
504  return {};
505  } else if (is_int_vector()) {
506  auto v = as_int_vector();
507  casadi_assert(v.empty(), "Cast only permitted for zero-length vectors");
508  return {};
509  } else {
510  casadi_assert(is_string_vector(), "type mismatch");
511  return as_string_vector();
512  }
513  }
const std::vector< std::string > & as_string_vector() const
Cast to the internal type.

References as_double_vector(), as_int_vector(), as_string(), as_string_vector(), is_double_vector(), is_int_vector(), is_string(), and is_string_vector().

Referenced by is_empty_vector().

◆ to_string_vector_vector()

std::vector< std::vector< std::string > > casadi::GenericType::to_string_vector_vector ( ) const

Definition at line 515 of file generic_type.cpp.

515  {
516  casadi_assert(is_string_vector_vector(), "type mismatch");
517  return as_string_vector_vector();
518  }
const std::vector< std::vector< std::string > > & as_string_vector_vector() const
Cast to the internal type.

References as_string_vector_vector(), and is_string_vector_vector().

Referenced by is_empty_vector().

◆ to_vector()

std::vector< GenericType > casadi::GenericType::to_vector ( ) const

Definition at line 535 of file generic_type.cpp.

535  {
536  if (is_double_vector()) {
537  auto v = as_double_vector();
538  std::vector<GenericType> ret(v.size());
539  for (casadi_int i=0;i<v.size();++i) ret[i] = v[i];
540  return ret;
541  } else if (is_int_vector()) {
542  auto v = as_int_vector();
543  std::vector<GenericType> ret(v.size());
544  for (casadi_int i=0;i<v.size();++i) ret[i] = v[i];
545  return ret;
546  } else if (is_string_vector()) {
547  auto v = as_string_vector();
548  std::vector<GenericType> ret(v.size());
549  for (casadi_int i=0;i<v.size();++i) ret[i] = v[i];
550  return ret;
551  } else if (is_function_vector()) {
552  auto v = as_function_vector();
553  std::vector<GenericType> ret(v.size());
554  for (casadi_int i=0;i<v.size();++i) ret[i] = v[i];
555  return ret;
556  } else if (is_double_vector_vector()) {
557  auto v = as_double_vector_vector();
558  std::vector<GenericType> ret(v.size());
559  for (casadi_int i=0;i<v.size();++i) ret[i] = v[i];
560  return ret;
561  } else if (is_int_vector_vector()) {
562  auto v = as_int_vector_vector();
563  std::vector<GenericType> ret(v.size());
564  for (casadi_int i=0;i<v.size();++i) ret[i] = v[i];
565  return ret;
566  } else if (is_string_vector_vector()) {
567  auto v = as_string_vector_vector();
568  std::vector<GenericType> ret(v.size());
569  for (casadi_int i=0;i<v.size();++i) ret[i] = v[i];
570  return ret;
571  } else if (is_bool_vector()) {
572  auto v = as_bool_vector();
573  std::vector<GenericType> ret(v.size());
574  for (casadi_int i=0;i<v.size();++i) ret[i] = v[i];
575  return ret;
576  } else if (is_dict_vector()) {
577  auto v = as_dict_vector();
578  std::vector<GenericType> ret(v.size());
579  for (casadi_int i=0;i<v.size();++i) ret[i] = v[i];
580  return ret;
581  } else if (is_vector_vector()) {
582  auto v = as_vector_vector();
583  std::vector<GenericType> ret(v.size());
584  for (casadi_int i=0;i<v.size();++i) ret[i] = v[i];
585  return ret;
586  } else {
587  casadi_assert(is_vector(), "type mismatch");
588  return as_vector();
589  }
590  }
const std::vector< casadi_int > & as_bool_vector() const
Cast to the internal type.

References as_bool_vector(), as_dict_vector(), as_double_vector(), as_double_vector_vector(), as_function_vector(), as_int_vector(), as_int_vector_vector(), as_string_vector(), as_string_vector_vector(), as_vector(), as_vector_vector(), is_bool_vector(), is_dict_vector(), is_double_vector(), is_double_vector_vector(), is_function_vector(), is_int_vector(), is_int_vector_vector(), is_string_vector(), is_string_vector_vector(), is_vector(), and is_vector_vector().

Referenced by is_empty_vector().

◆ to_vector_vector()

std::vector< std::vector< GenericType > > casadi::GenericType::to_vector_vector ( ) const

Definition at line 592 of file generic_type.cpp.

592  {
593  if (is_double_vector_vector()) {
594  auto v = as_double_vector_vector();
595  std::vector<std::vector<GenericType> > ret(v.size());
596  for (casadi_int i=0;i<v.size();++i) {
597  ret[i].resize(v[i].size());
598  for (casadi_int j=0;j<v[i].size();++j) {
599  ret[i][j] = v[i][j];
600  }
601  }
602  return ret;
603  } else if (is_int_vector_vector()) {
604  auto v = as_int_vector_vector();
605  std::vector<std::vector<GenericType> > ret(v.size());
606  for (casadi_int i=0;i<v.size();++i) {
607  ret[i].resize(v[i].size());
608  for (casadi_int j=0;j<v[i].size();++j) {
609  ret[i][j] = v[i][j];
610  }
611  }
612  return ret;
613  } else if (is_string_vector_vector()) {
614  auto v = as_string_vector_vector();
615  std::vector<std::vector<GenericType> > ret(v.size());
616  for (casadi_int i=0;i<v.size();++i) {
617  ret[i].resize(v[i].size());
618  for (casadi_int j=0;j<v[i].size();++j) {
619  ret[i][j] = v[i][j];
620  }
621  }
622  return ret;
623  } else {
624  casadi_assert(is_vector_vector(), "type mismatch");
625  return as_vector_vector();
626  }
627  }

References as_double_vector_vector(), as_int_vector_vector(), as_string_vector_vector(), as_vector_vector(), is_double_vector_vector(), is_int_vector_vector(), is_string_vector_vector(), and is_vector_vector().

Referenced by is_empty_vector().

◆ to_void_pointer()

void * casadi::GenericType::to_void_pointer ( ) const

Definition at line 639 of file generic_type.cpp.

639  {
640  if (is_void_pointer()) {
641  return as_void_pointer();
642  } else {
643  casadi_int i = as_int();
644  casadi_assert(i==0, "Only zero pointers accepted");
645  return nullptr;
646  }
647  }
void *const & as_void_pointer() const
Cast to the internal type.

References as_int(), as_void_pointer(), and is_void_pointer().

◆ type_name()

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

Definition at line 111 of file generic_type.hpp.

111 {return "GenericType";}

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