26 #ifndef CASADI_GENERIC_TYPE_HPP
27 #define CASADI_GENERIC_TYPE_HPP
29 #include "shared_object.hpp"
30 #include "printable.hpp"
31 #include "casadi_common.hpp"
36 class SerializingStream;
37 class DeserializingStream;
38 #if !(defined(SWIG) && !defined(SWIGXML))
53 OT_DOUBLEVECTORVECTOR,
60 OT_STRINGVECTORVECTOR,
73 :
public SWIG_IF_ELSE(PrintableCommon, Printable<GenericType>)
74 #if !(defined(SWIG) && !defined(SWIGXML))
80 typedef std::map<std::string, GenericType>
Dict;
82 #if !(defined(SWIG) && !defined(SWIGXML))
96 GenericType(
const std::vector< std::vector<casadi_int> >& ivv);
98 GenericType(
const std::vector< std::vector<double> >& dv);
100 GenericType(
const std::vector<std::vector<std::string> >& sv);
106 GenericType(
const std::vector<std::vector<GenericType> >& gvv);
111 static std::string type_name() {
return "GenericType";}
115 static std::string get_type_description(TypeID type);
123 static GenericType create(SharedObjectInternal* node);
128 std::string get_description()
const {
return get_type_description(getType()); }
132 static GenericType from_type(TypeID type);
136 operator bool()
const {
return to_bool();}
137 operator casadi_int()
const {
return to_int();}
138 operator int()
const {
return to_int();}
139 operator double()
const {
return to_double();}
140 operator std::string()
const {
return to_string();}
141 operator std::vector<bool>()
const {
return to_bool_vector();}
142 operator std::vector<casadi_int>()
const {
return to_int_vector();}
143 operator std::vector<int>()
const;
144 operator std::vector<std::vector<casadi_int> >()
const {
return to_int_vector_vector();}
145 operator std::vector<std::vector<int> >()
const;
146 operator std::vector<double>()
const {
return to_double_vector();}
147 operator std::vector< std::vector<double> >()
const {
148 return to_double_vector_vector();
150 operator std::vector<std::string>()
const {
return to_string_vector();}
151 operator std::vector<std::vector<std::string> >()
const {
return to_string_vector_vector();}
152 operator const Function&()
const {
return as_function();}
153 operator const std::vector<Function>&()
const {
return as_function_vector();}
154 operator const Dict&()
const {
return as_dict();}
155 operator const std::vector<Dict>&()
const {
return as_dict_vector();}
156 operator const std::vector<std::vector<GenericType> >&()
const {
return as_vector_vector();}
157 operator const std::vector<GenericType>&()
const {
return as_vector();}
160 bool can_cast_to(TypeID other)
const;
161 bool can_cast_to(
const GenericType& other)
const {
return can_cast_to(other.getType()) ;}
164 #if !(defined(SWIG) && !defined(SWIGXML))
166 TypeID getType()
const;
173 bool is_bool()
const;
175 bool is_double()
const;
176 bool is_string()
const;
177 bool is_empty_vector()
const;
178 bool is_int_vector()
const;
179 bool is_int_vector_vector()
const;
180 bool is_double_vector()
const;
181 bool is_double_vector_vector()
const;
182 bool is_bool_vector()
const;
183 bool is_string_vector()
const;
184 bool is_string_vector_vector()
const;
185 bool is_dict()
const;
186 bool is_dict_vector()
const;
187 bool is_vector_vector()
const;
188 bool is_vector()
const;
189 bool is_function()
const;
190 bool is_function_vector()
const;
191 bool is_void_pointer()
const;
198 const bool& as_bool()
const;
199 const casadi_int& as_int()
const;
200 const double& as_double()
const;
201 const std::string& as_string()
const;
202 const std::vector<casadi_int>& as_int_vector()
const;
203 const std::vector<casadi_int>& as_bool_vector()
const;
204 const std::vector<std::vector<casadi_int> >& as_int_vector_vector()
const;
205 const std::vector<double>& as_double_vector()
const;
206 const std::vector< std::vector<double> >& as_double_vector_vector()
const;
207 const std::vector<std::string>& as_string_vector()
const;
208 const std::vector<std::vector<std::string> >& as_string_vector_vector()
const;
209 const Dict& as_dict()
const;
210 const std::vector<Dict>& as_dict_vector()
const;
211 const std::vector<std::vector< GenericType> >& as_vector_vector()
const;
212 const std::vector<GenericType>& as_vector()
const;
213 const Function& as_function()
const;
214 const std::vector<Function>& as_function_vector()
const;
215 void*
const & as_void_pointer()
const;
220 bool to_bool()
const;
221 casadi_int to_int()
const;
222 double to_double()
const;
223 std::string to_string()
const;
224 std::vector<casadi_int> to_int_vector()
const;
225 std::vector<bool> to_bool_vector()
const;
226 std::vector< std::vector<casadi_int> > to_int_vector_vector()
const;
227 std::vector<double> to_double_vector()
const;
228 std::vector< std::vector<double> > to_double_vector_vector()
const;
229 std::vector<std::string> to_string_vector()
const;
230 std::vector<std::vector<std::string> > to_string_vector_vector()
const;
231 Dict to_dict()
const;
232 std::vector<Dict> to_dict_vector()
const;
233 std::vector<GenericType> to_vector()
const;
234 std::vector< std::vector< GenericType> > to_vector_vector()
const;
235 Function to_function()
const;
236 std::vector<Function> to_function_vector()
const;
237 void* to_void_pointer()
const;
238 std::vector<int> to_int_type_vector()
const;
242 bool operator==(
const GenericType& op2)
const;
243 bool operator!=(
const GenericType& op2)
const;
262 T get_from_dict(
const std::map<std::string, T>& d,
263 const std::string& key,
const T& default_value) {
264 auto it = d.find(key);
265 if (it==d.end())
return default_value;
270 T get_from_dict(
const Dict& d,
const std::string& key,
const T& default_value) {
271 auto it = d.find(key);
272 if (it==d.end())
return default_value;
277 Dict extract_from_dict(
const Dict& d,
const std::string& key, T& value) {
279 auto it = ret.find(key);
288 void extract_from_dict_inplace(
Dict& d,
const std::string& key, T& value) {
289 auto it = d.find(key);
300 CASADI_EXPORT
Dict combine(
const Dict& first,
const Dict& second,
bool recurse=
false);
305 CASADI_EXPORT
void update_dict(
Dict& target,
const Dict& source,
bool recurse=
false);
Helper class for Serialization.
Generic data type, can hold different types such as bool, casadi_int, std::string etc.
std::map< std::string, GenericType > Dict
C++ equivalent of Python's dict or MATLAB's struct.
static GenericType deserialize(DeserializingStream &s)
Deserialize with type disambiguation.
void serialize(SerializingStream &s) const
Serialize an object.
Helper class for Serialization.
SharedObject implements a reference counting framework similar for efficient and.
GenericType::Dict Dict
C++ equivalent of Python's dict or MATLAB's struct.