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< bool > & 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 252 of file generic_type.cpp.

252  {
253  }

◆ GenericType() [2/22]

casadi::GenericType::GenericType ( bool  b)

Definition at line 255 of file generic_type.cpp.

255  {
256  own(new BoolType(b));
257  }
GenericTypeInternal< OT_BOOL, bool > BoolType

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

◆ GenericType() [3/22]

casadi::GenericType::GenericType ( casadi_int  i)

Definition at line 259 of file generic_type.cpp.

259  {
260  own(new IntType(i));
261  }
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 263 of file generic_type.cpp.

263  {
264  own(new DoubleType(d));
265  }
GenericTypeInternal< OT_DOUBLE, double > DoubleType

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

◆ GenericType() [6/22]

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

Definition at line 303 of file generic_type.cpp.

303  {
304  own(new StringType(s));
305  }
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 281 of file generic_type.cpp.

281  {
282  std::vector<bool> i_vec(b_vec.size());
283  std::copy(b_vec.begin(), b_vec.end(), i_vec.begin());
284  own(new BoolVectorType(i_vec));
285  }
GenericTypeInternal< OT_BOOLVECTOR, std::vector< bool > > BoolVectorType

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

◆ GenericType() [8/22]

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

Definition at line 267 of file generic_type.cpp.

267  {
268  own(new IntVectorType(iv));
269  }
GenericTypeInternal< OT_INTVECTOR, std::vector< casadi_int > > IntVectorType

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

◆ GenericType() [9/22]

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

Definition at line 271 of file generic_type.cpp.

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

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

◆ GenericType() [10/22]

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

Definition at line 277 of file generic_type.cpp.

277  {
278  own(new IntVectorVectorType(ivv));
279  }
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 287 of file generic_type.cpp.

287  {
288  own(new DoubleVectorType(dv));
289  }
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 291 of file generic_type.cpp.

291  {
292  own(new DoubleVectorVectorType(dv));
293  }
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 295 of file generic_type.cpp.

295  {
296  own(new StringVectorType(sv));
297  }
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 299 of file generic_type.cpp.

299  {
300  own(new StringVectorVectorType(sv));
301  }
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 307 of file generic_type.cpp.

307  {
308  own(new StringType(s));
309  }

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

◆ GenericType() [16/22]

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

Definition at line 311 of file generic_type.cpp.

311  {
312  own(new FunctionType(f));
313  }
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 315 of file generic_type.cpp.

315  {
316  own(new FunctionVectorType(f));
317  }
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 745 of file generic_type.cpp.

745  {
746  own(new DictType(dict));
747  }
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 749 of file generic_type.cpp.

749  {
750  own(new DictVectorType(dictv));
751  }
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 757 of file generic_type.cpp.

757  {
758  own(new VectorVectorType(gvv));
759  }
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 753 of file generic_type.cpp.

753  {
754  own(new VectorType(gv));
755  }
GenericTypeInternal< OT_VECTOR, std::vector< GenericType > > VectorType

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

◆ GenericType() [22/22]

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

Definition at line 761 of file generic_type.cpp.

761  {
762  own(new VoidPointerType(ptr));
763  }
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 123 of file generic_shared_impl.hpp.

148  {
149  return reinterpret_cast<casadi_int>(get());
150  }

◆ as_bool()

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

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

Definition at line 319 of file generic_type.cpp.

319  {
320  casadi_assert_dev(is_bool());
321  return static_cast<const BoolType*>(get())->d_;
322  }
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(), to_bool_vector(), to_double_vector(), and to_int_vector().

◆ as_bool_vector()

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

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

Definition at line 344 of file generic_type.cpp.

344  {
345  casadi_assert_dev(is_bool_vector());
346  return static_cast<const BoolVectorType*>(get())->d_;
347  }
bool is_bool_vector() const
Check if a particular type.

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

Referenced by to_bool_vector(), and 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 374 of file generic_type.cpp.

374  {
375  casadi_assert_dev(is_dict());
376  return static_cast<const DictType*>(get())->d_;
377  }
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 379 of file generic_type.cpp.

379  {
380  casadi_assert_dev(is_dict_vector());
381  return static_cast<const DictVectorType*>(get())->d_;
382  }
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 329 of file generic_type.cpp.

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

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

Referenced by to_bool_vector(), to_double(), to_double_vector(), and to_int_vector().

◆ 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 354 of file generic_type.cpp.

354  {
355  casadi_assert_dev(is_double_vector());
356  return static_cast<const DoubleVectorType*>(get())->d_;
357  }
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 359 of file generic_type.cpp.

359  {
360  casadi_assert_dev(is_double_vector_vector());
361  return static_cast<const DoubleVectorVectorType*>(get())->d_;
362  }
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 394 of file generic_type.cpp.

394  {
395  casadi_assert_dev(is_function());
396  return static_cast<const FunctionType*>(get())->d_;
397  }
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 399 of file generic_type.cpp.

399  {
400  casadi_assert_dev(is_function_vector());
401  return static_cast<const FunctionVectorType*>(get())->d_;
402  }
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 324 of file generic_type.cpp.

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

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

Referenced by to_bool_vector(), to_double_vector(), to_int(), to_int_vector(), 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 339 of file generic_type.cpp.

339  {
340  casadi_assert_dev(is_int_vector());
341  return static_cast<const IntVectorType*>(get())->d_;
342  }
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 349 of file generic_type.cpp.

349  {
350  casadi_assert_dev(is_int_vector_vector());
351  return static_cast<const IntVectorVectorType*>(get())->d_;
352  }
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 334 of file generic_type.cpp.

334  {
335  casadi_assert_dev(is_string());
336  return static_cast<const StringType*>(get())->d_;
337  }
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 364 of file generic_type.cpp.

364  {
365  casadi_assert_dev(is_string_vector());
366  return static_cast<const StringVectorType*>(get())->d_;
367  }
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 369 of file generic_type.cpp.

369  {
370  casadi_assert_dev(is_string_vector_vector());
371  return static_cast<const StringVectorVectorType*>(get())->d_;
372  }
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 389 of file generic_type.cpp.

389  {
390  casadi_assert_dev(is_vector());
391  return static_cast<const VectorType*>(get())->d_;
392  }
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 384 of file generic_type.cpp.

384  {
385  casadi_assert_dev(is_vector_vector());
386  return static_cast<const VectorVectorType*>(get())->d_;
387  }
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 404 of file generic_type.cpp.

404  {
405  casadi_assert_dev(is_void_pointer());
406  return static_cast<const VoidPointerType*>(get())->d_;
407  }
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 96 of file generic_shared_impl.hpp.

86  {
87  node = node_;
88  }

◆ 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 61 of file generic_type.cpp.

61  {
62  switch (other) {
63  case OT_BOOL:
64  return is_bool() || is_int() || is_double();
65  case OT_BOOLVECTOR:
67  || is_bool() || is_int() || is_double();
68  case OT_INT:
69  case OT_DOUBLE:
70  return is_bool() || is_int() || is_double();
71  case OT_INTVECTOR:
72  case OT_DOUBLEVECTOR:
74  || is_bool() || is_int() || is_double();
75  case OT_INTVECTORVECTOR:
78  case OT_STRINGVECTOR:
80  case OT_VECTOR:
81  return is_vector() || is_double_vector() || is_int_vector() || is_string_vector() ||
85  case OT_VECTORVECTOR:
86  return is_vector_vector() ||
88  case OT_VOIDPTR:
89  return is_void_pointer() || is_int();
90  default:
91  return getType() == other;
92  }
93  }
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 133 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 #ifdef CASADI_WITH_THREADSAFE_SYMBOLICS
52  GenericWeakRef<Shared, Internal>* weak_ref =
53  node->weak_ref_.load(std::memory_order_acquire);
54 #else
55  GenericWeakRef<Shared, Internal>* weak_ref = node->weak_ref_;
56 #endif // CASADI_WITH_THREADSAFE_SYMBOLICS
57  if (weak_ref) {
58 #ifdef CASADI_WITH_THREADSAFE_SYMBOLICS
59  // get_mutex() returns a shared_ptr copy, so the mutex outlives this lock
60  // even if delete node (below) destroys the WeakRefInternal holding it
61  auto mutex = weak_ref->get_mutex();
62  // Avoid triggering a delete while a weak_ref.shared_if_alive is being called
63  std::lock_guard<std::mutex> lock(*mutex);
64 #endif // CASADI_WITH_THREADSAFE_SYMBOLICS
65 
66  if (--static_cast<Internal*>(node)->count == 0) {
67  delete node;
68  node = nullptr;
69  }
70  } else {
71  if (--static_cast<Internal*>(node)->count == 0) {
72  delete node;
73  node = nullptr;
74  }
75  }
76  }

◆ count_up()

void casadi::GenericShared< SharedObject , SharedObjectInternal >::count_up
protectedinherited

Definition at line 132 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  }

◆ create()

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

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

Definition at line 820 of file generic_type.cpp.

820  {
821  GenericType ret;
822  ret.own(node);
823  return ret;
824  }

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

◆ debug_repr()

std::string casadi::GenericShared< SharedObject , SharedObjectInternal >::debug_repr
inherited

Definition at line 112 of file generic_shared_impl.hpp.

91  {
92  if (node) {
93  return node->debug_repr(node);
94  } else {
95  return "NULL";
96  }
97  }
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 778 of file generic_type.cpp.

778  {
779  int itype;
780  s.unpack("GenericType::type", itype);
781  TypeID type = static_cast<TypeID>(itype);
782  switch (type) {
783  case OT_STRING:
784  return StringType::deserialize(s);
785  case OT_DOUBLE:
786  return DoubleType::deserialize(s);
787  case OT_INT:
788  return IntType::deserialize(s);
789  case OT_BOOL:
790  return BoolType::deserialize(s);
791  case OT_DOUBLEVECTOR:
795  case OT_INTVECTOR:
796  return IntVectorType::deserialize(s);
797  case OT_INTVECTORVECTOR:
799  case OT_STRINGVECTOR:
803  case OT_FUNCTION:
804  return FunctionType::deserialize(s);
805  case OT_FUNCTIONVECTOR:
807  case OT_DICT:
808  return DictType::deserialize(s);
809  case OT_DICTVECTOR:
810  return DictVectorType::deserialize(s);
811  case OT_VECTOR:
812  return VectorType::deserialize(s);
813  case OT_VECTORVECTOR:
815  default:
816  casadi_error("Not implemented: " + get_type_description(type));
817  }
818  }
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 95 of file generic_type.cpp.

95  {
96  switch (type) {
97  case OT_INTVECTOR:
98  return std::vector<casadi_int>();
99  case OT_INTVECTORVECTOR:
100  return std::vector< std::vector<casadi_int> >();
101  case OT_BOOLVECTOR:
102  return std::vector<bool>();
103  case OT_DOUBLEVECTOR:
104  return std::vector<double>();
106  return std::vector< std::vector<double> >();
107  case OT_STRINGVECTOR:
108  return std::vector<std::string>();
110  return std::vector<std::vector<std::string> >();
111  case OT_DICTVECTOR:
112  return std::vector<GenericType::Dict>();
113  case OT_VECTORVECTOR:
114  return std::vector<std::vector< GenericType> >();
115  case OT_VECTOR:
116  return std::vector<GenericType>();
117  default:
118  casadi_error("empty_from_type. Unsupported type " + str(type));
119  }
120  }
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 99 of file generic_shared_impl.hpp.

115  {
116  return node;
117  }

◆ 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 122 of file generic_type.cpp.

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

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

138  {
139  return (*this)->getCount();
140  }

◆ getType()

TypeID casadi::GenericType::getType ( ) const

◆ is_bool()

bool casadi::GenericType::is_bool ( ) const

◆ is_bool_vector()

bool casadi::GenericType::is_bool_vector ( ) const

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

Definition at line 200 of file generic_type.cpp.

200  {
201  return getType()==OT_BOOLVECTOR;
202  }

References getType(), and casadi::OT_BOOLVECTOR.

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

◆ is_dict()

bool casadi::GenericType::is_dict ( ) const

◆ is_dict_vector()

bool casadi::GenericType::is_dict_vector ( ) const

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

Definition at line 240 of file generic_type.cpp.

240  {
241  return getType()==OT_DICTVECTOR;
242  }

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

◆ 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 183 of file generic_type.cpp.

183  {
184  return (is_int_vector() && to_int_vector().empty()) ||
185  (is_int_vector_vector() && to_int_vector_vector().empty()) ||
187  (is_double_vector() && to_double_vector().empty()) ||
188  (is_string_vector() && to_string_vector().empty()) ||
190  (is_bool_vector() && to_bool_vector().empty()) ||
191  (is_dict_vector() && as_dict_vector().empty()) ||
192  (is_vector_vector() && to_vector_vector().empty()) ||
193  (is_vector() && to_vector().empty());
194  }
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 224 of file generic_type.cpp.

224  {
225  return getType()==OT_FUNCTION;
226  }

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 228 of file generic_type.cpp.

228  {
229  return getType()==OT_FUNCTIONVECTOR;
230  }

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

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

120  {
121  return node==nullptr;
122  }

◆ is_string()

bool casadi::GenericType::is_string ( ) const

◆ 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 248 of file generic_type.cpp.

248  {
249  return getType()==OT_VECTOR;
250  }

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 232 of file generic_type.cpp.

232  {
233  return getType()==OT_VOIDPTR;
234  }

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 464 of file generic_type.cpp.

464  {
465  std::vector<int> ret;
466  std::vector<casadi_int> source = to_int_vector();
467  return casadi::to_int(source);
468  }
int to_int(casadi_int rhs)
Definition: casadi_misc.cpp:60

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 684 of file generic_type.cpp.

684  {
685  if (is_string() && op2.is_string()) {
686  return to_string() != op2.to_string();
687  }
688 
689  if (is_int() && op2.is_int()) {
690  return to_int() != op2.to_int();
691  }
692 
693  if (is_double() && op2.is_double()) {
694  return to_double() != op2.to_double();
695  }
696 
697  if (is_double_vector() && op2.is_double_vector()) {
698  const std::vector<double> &v1 = to_double_vector();
699  const std::vector<double> &v2 = op2.to_double_vector();
700  if (v1.size() != v2.size()) return true;
701  for (casadi_int i=0; i<v1.size(); ++i)
702  if (v1[i] != v2[i]) return true;
703  return false;
704  }
705 
706  if (is_int_vector() && op2.is_int_vector()) {
707  const std::vector<casadi_int> &v1 = to_int_vector();
708  const std::vector<casadi_int> &v2 = op2.to_int_vector();
709  if (v1.size() != v2.size()) return true;
710  for (casadi_int i=0; i<v1.size(); ++i)
711  if (v1[i] != v2[i]) return true;
712  return false;
713  }
714 
715  if (is_int_vector_vector() && op2.is_int_vector_vector()) {
716  const std::vector< std::vector<casadi_int> > &v1 = to_int_vector_vector();
717  const std::vector< std::vector<casadi_int> > &v2 = op2.to_int_vector_vector();
718  if (v1.size() != v2.size()) return true;
719  for (casadi_int i=0; i<v1.size(); ++i) {
720  if (v1[i].size() != v2[i].size()) return true;
721  for (casadi_int j=0; j<v1[i].size(); ++j) {
722  if (v1[i][j] != v2[i][j]) return true;
723  }
724  }
725  return false;
726  }
727 
728  if (is_double_vector_vector() && op2.is_double_vector_vector()) {
729  const std::vector< std::vector<double> > &v1 = to_double_vector_vector();
730  const std::vector< std::vector<double> > &v2 = op2.to_double_vector_vector();
731  if (v1.size() != v2.size()) return true;
732  for (casadi_int i=0; i<v1.size(); ++i) {
733  if (v1[i].size() != v2[i].size()) return true;
734  for (casadi_int j=0; j<v1[i].size(); ++j) {
735  if (v1[i][j] != v2[i][j]) return true;
736  }
737  }
738  return false;
739  }
740 
741  // Different types
742  return true;
743  }

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

125  {
126  casadi_assert_dev(!is_null());
127  return node;
128  }

◆ operator==()

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

Definition at line 680 of file generic_type.cpp.

680  {
681  return !(*this != op2);
682  }

◆ own()

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

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

Definition at line 89 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 773 of file generic_type.cpp.

773  {
774  s.pack("GenericType::type", static_cast<int>(getType()));
775  static_cast<const GenericTypeBase*>(get())->serialize(s);
776  }
void serialize(SerializingStream &s) const
Serialize an object.

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

◆ swap()

Definition at line 105 of file generic_shared_impl.hpp.

131  {
132  GenericShared<Shared, Internal> temp = *this;
133  *this = other;
134  other = temp;
135  }

◆ to_bool()

bool casadi::GenericType::to_bool ( ) const

Definition at line 409 of file generic_type.cpp.

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

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

Referenced by casadi::set_uno_option(), to_double(), and to_int().

◆ to_bool_vector()

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

Definition at line 470 of file generic_type.cpp.

470  {
471  if (is_bool()) {
472  return std::vector<bool>(1, as_bool());
473  } else if (is_int()) {
474  casadi_int v = as_int();
475  casadi_assert(v==0 || v==1, "Entry must be zero or one");
476  return std::vector<bool>(1, v==1);
477  } else if (is_double()) {
478  double v = as_double();
479  casadi_assert(v==0.0 || v==1.0, "Entry must be zero or one");
480  return std::vector<bool>(1, v==1.0);
481  } else if (is_bool_vector()) {
482  return as_bool_vector();
483  }
484  casadi_assert(is_int_vector(), "type mismatch");
485  std::vector<casadi_int> v = to_int_vector();
486  std::vector<bool> ret(v.size());
487  for (casadi_int i=0; i<v.size(); ++i) {
488  casadi_assert(v[i]==0 || v[i]==1, "Entries must be zero or one");
489  ret[i] = v[i]==1;
490  }
491  return ret;
492  }
const casadi_int & as_int() const
Cast to the internal type.
const double & as_double() const
Cast to the internal type.
const std::vector< bool > & as_bool_vector() const
Cast to the internal type.

References as_bool(), as_bool_vector(), as_double(), as_int(), is_bool(), is_bool_vector(), is_double(), is_int(), is_int_vector(), and to_int_vector().

Referenced by is_empty_vector().

◆ to_dict()

Dict casadi::GenericType::to_dict ( ) const

Definition at line 551 of file generic_type.cpp.

551  {
552  casadi_assert(is_dict(), "type mismatch");
553  return as_dict();
554  }

References as_dict(), and is_dict().

Referenced by casadi::transform_token_str().

◆ to_dict_vector()

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

Definition at line 556 of file generic_type.cpp.

556  {
557  if (is_empty_vector()) return {};
558  if (is_dict()) {
559  Dict e = as_dict();
560  return std::vector<Dict>(1, e);
561  }
562  casadi_assert(is_dict_vector(), "type mismatch");
563  return as_dict_vector();
564  }
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 431 of file generic_type.cpp.

431  {
432  if (is_bool()) {
433  return static_cast<double>(to_bool());
434  } else if (is_int()) {
435  return static_cast<double>(to_int());
436  } else {
437  casadi_assert(is_double(), "type mismatch");
438  return as_double();
439  }
440  }

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

Referenced by operator!=(), casadi::set_uno_option(), and to_int().

◆ to_double_vector()

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

Definition at line 499 of file generic_type.cpp.

499  {
500  if (is_bool()) {
501  return std::vector<double>(1, as_bool() ? 1.0 : 0.0);
502  } else if (is_int()) {
503  return std::vector<double>(1, static_cast<double>(as_int()));
504  } else if (is_double()) {
505  return std::vector<double>(1, as_double());
506  } else if (is_int_vector()) {
507  auto v = as_int_vector();
508  return std::vector<double>(v.begin(), v.end());
509  } else {
510  casadi_assert(is_double_vector(), "type mismatch");
511  return as_double_vector();
512  }
513  }
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_bool(), as_double(), as_double_vector(), as_int(), as_int_vector(), is_bool(), is_double(), is_double_vector(), is_int(), 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 515 of file generic_type.cpp.

515  {
516  if (is_int_vector_vector()) {
517  auto v = as_int_vector_vector();
518  std::vector< std::vector<double> > ret(v.size());
519  for (casadi_int i=0;i<v.size();++i)
520  ret[i].assign(v[i].begin(), v[i].end());
521  return ret;
522  } else {
523  casadi_assert(is_double_vector_vector(), "type mismatch");
524  return as_double_vector_vector();
525  }
526  }
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 660 of file generic_type.cpp.

660  {
661  casadi_assert(is_function(), "type mismatch");
662  return as_function();
663  }

References as_function(), and is_function().

◆ to_function_vector()

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

Definition at line 665 of file generic_type.cpp.

665  {
666  casadi_assert(is_function_vector(), "type mismatch");
667  return as_function_vector();
668  }

References as_function_vector(), and is_function_vector().

◆ to_int()

casadi_int casadi::GenericType::to_int ( ) const

Definition at line 420 of file generic_type.cpp.

420  {
421  if (is_double()) {
422  return static_cast<casadi_int>(to_double());
423  } else if (is_bool()) {
424  return static_cast<casadi_int>(to_bool());
425  } else {
426  casadi_assert(is_int(), "type mismatch");
427  return as_int();
428  }
429  }

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

Referenced by operator!=(), casadi::set_uno_option(), to_bool(), to_double(), and casadi::transform_token_str().

◆ to_int_type_vector()

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

Definition at line 447 of file generic_type.cpp.

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

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 452 of file generic_type.cpp.

452  {
453  if (is_bool()) {
454  return std::vector<casadi_int>(1, as_bool() ? 1 : 0);
455  } else if (is_int()) {
456  return std::vector<casadi_int>(1, as_int());
457  } else if (is_double()) {
458  return std::vector<casadi_int>(1, static_cast<casadi_int>(as_double()));
459  }
460  casadi_assert(is_int_vector(), "type mismatch");
461  return as_int_vector();
462  }

References as_bool(), as_double(), as_int(), as_int_vector(), is_bool(), is_double(), is_int(), 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 494 of file generic_type.cpp.

494  {
495  casadi_assert(is_int_vector_vector(), "type mismatch");
496  return as_int_vector_vector();
497  }

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 442 of file generic_type.cpp.

442  {
443  casadi_assert(is_string(), "type mismatch");
444  return as_string();
445  }
const std::string & as_string() const
Cast to the internal type.

References as_string(), and is_string().

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

◆ to_string_vector()

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

Definition at line 528 of file generic_type.cpp.

528  {
529  if (is_string()) {
530  std::string s = as_string();
531  return std::vector<std::string>(1, s);
532  } else if (is_double_vector()) {
533  auto v = as_double_vector();
534  casadi_assert(v.empty(), "Cast only permitted for zero-length vectors");
535  return {};
536  } else if (is_int_vector()) {
537  auto v = as_int_vector();
538  casadi_assert(v.empty(), "Cast only permitted for zero-length vectors");
539  return {};
540  } else {
541  casadi_assert(is_string_vector(), "type mismatch");
542  return as_string_vector();
543  }
544  }
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 546 of file generic_type.cpp.

546  {
547  casadi_assert(is_string_vector_vector(), "type mismatch");
548  return as_string_vector_vector();
549  }
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 566 of file generic_type.cpp.

566  {
567  if (is_double_vector()) {
568  auto v = as_double_vector();
569  std::vector<GenericType> ret(v.size());
570  for (casadi_int i=0;i<v.size();++i) ret[i] = v[i];
571  return ret;
572  } else if (is_int_vector()) {
573  auto v = as_int_vector();
574  std::vector<GenericType> ret(v.size());
575  for (casadi_int i=0;i<v.size();++i) ret[i] = v[i];
576  return ret;
577  } else if (is_string_vector()) {
578  auto v = as_string_vector();
579  std::vector<GenericType> ret(v.size());
580  for (casadi_int i=0;i<v.size();++i) ret[i] = v[i];
581  return ret;
582  } else if (is_function_vector()) {
583  auto v = as_function_vector();
584  std::vector<GenericType> ret(v.size());
585  for (casadi_int i=0;i<v.size();++i) ret[i] = v[i];
586  return ret;
587  } else if (is_double_vector_vector()) {
588  auto v = as_double_vector_vector();
589  std::vector<GenericType> ret(v.size());
590  for (casadi_int i=0;i<v.size();++i) ret[i] = v[i];
591  return ret;
592  } else if (is_int_vector_vector()) {
593  auto v = as_int_vector_vector();
594  std::vector<GenericType> ret(v.size());
595  for (casadi_int i=0;i<v.size();++i) ret[i] = v[i];
596  return ret;
597  } else if (is_string_vector_vector()) {
598  auto v = as_string_vector_vector();
599  std::vector<GenericType> ret(v.size());
600  for (casadi_int i=0;i<v.size();++i) ret[i] = v[i];
601  return ret;
602  } else if (is_bool_vector()) {
603  auto v = as_bool_vector();
604  std::vector<GenericType> ret(v.size());
605  for (casadi_int i=0;i<v.size();++i) ret[i] = static_cast<bool>(v[i]);
606  return ret;
607  } else if (is_dict_vector()) {
608  auto v = as_dict_vector();
609  std::vector<GenericType> ret(v.size());
610  for (casadi_int i=0;i<v.size();++i) ret[i] = v[i];
611  return ret;
612  } else if (is_vector_vector()) {
613  auto v = as_vector_vector();
614  std::vector<GenericType> ret(v.size());
615  for (casadi_int i=0;i<v.size();++i) ret[i] = v[i];
616  return ret;
617  } else {
618  casadi_assert(is_vector(), "type mismatch");
619  return as_vector();
620  }
621  }

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 623 of file generic_type.cpp.

623  {
624  if (is_double_vector_vector()) {
625  auto v = as_double_vector_vector();
626  std::vector<std::vector<GenericType> > ret(v.size());
627  for (casadi_int i=0;i<v.size();++i) {
628  ret[i].resize(v[i].size());
629  for (casadi_int j=0;j<v[i].size();++j) {
630  ret[i][j] = v[i][j];
631  }
632  }
633  return ret;
634  } else if (is_int_vector_vector()) {
635  auto v = as_int_vector_vector();
636  std::vector<std::vector<GenericType> > ret(v.size());
637  for (casadi_int i=0;i<v.size();++i) {
638  ret[i].resize(v[i].size());
639  for (casadi_int j=0;j<v[i].size();++j) {
640  ret[i][j] = v[i][j];
641  }
642  }
643  return ret;
644  } else if (is_string_vector_vector()) {
645  auto v = as_string_vector_vector();
646  std::vector<std::vector<GenericType> > ret(v.size());
647  for (casadi_int i=0;i<v.size();++i) {
648  ret[i].resize(v[i].size());
649  for (casadi_int j=0;j<v[i].size();++j) {
650  ret[i][j] = v[i][j];
651  }
652  }
653  return ret;
654  } else {
655  casadi_assert(is_vector_vector(), "type mismatch");
656  return as_vector_vector();
657  }
658  }

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 670 of file generic_type.cpp.

670  {
671  if (is_void_pointer()) {
672  return as_void_pointer();
673  } else {
674  casadi_int i = as_int();
675  casadi_assert(i==0, "Only zero pointers accepted");
676  return nullptr;
677  }
678  }
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 130 of file generic_shared_impl.hpp.

143  {
144  return (*this)->weak();
145  }

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