26 #ifndef CASADI_COMMON_HPP
27 #define CASADI_COMMON_HPP
44 #define SWIG_IF_ELSE(is_swig, not_swig) is_swig
45 #define SWIG_OUTPUT(arg) OUTPUT
46 #define SWIG_INOUT(arg) INOUT
47 #define SWIG_CONSTREF(arg) const arg
49 #define SWIG_IND1 true
51 #define SWIG_IND1 false
54 #define SWIG_IF_ELSE(is_swig, not_swig) not_swig
55 #define SWIG_OUTPUT(arg) arg
56 #define SWIG_INOUT(arg) arg
57 #define SWIG_CONSTREF(arg) const arg &
58 #define SWIG_IND1 false
61 #include "casadi_types.hpp"
68 template<
class T>
class Matrix;
82 #ifdef __GNUC_PATCHLEVEL__
83 #define GCC_VERSION (__GNUC__ * 10000 +__GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
92 #pragma warning(disable:4018)
95 #pragma warning(disable:4244)
98 #pragma warning(disable:4251)
102 #pragma warning(disable:4275)
105 #pragma warning(disable:4715)
108 #pragma warning(disable:4800)
111 #pragma warning(disable:4910)
115 #pragma warning(disable:4996)
142 typedef const char* (*name_t)(casadi_int i);
143 typedef const casadi_int* (*sparsity_t)(casadi_int i);
147 typedef int (*
work_t)(casadi_int* sz_arg, casadi_int* sz_res,
148 casadi_int* sz_iw, casadi_int* sz_w);
149 typedef int (*
eval_t)(
const double** arg,
double** res,
150 casadi_int* iw,
double* w, int);
160 std::string
str(
const T& v);
164 std::string
str(
const T& v,
bool more);
168 std::string
str(
const std::vector<T>& v,
bool more=
false);
172 std::string
str(
const std::set<T>& v,
bool more=
false);
175 template<
typename T1,
typename T2>
176 std::string
str(
const std::pair<T1, T2>& p,
bool more=
false);
179 template<
typename T1,
typename T2>
180 std::string
str(
const std::map<T1, T2> &p,
bool more=
false);
183 template<
typename T2>
184 std::string
str(
const std::map<std::string, T2> &p,
bool more=
false);
187 template<
typename T,
size_t N>
188 std::string
str(
const std::array<T, N> &p,
bool more=
false);
191 inline std::vector<std::string>
strvec() {
196 template<
typename T1>
197 inline std::vector<std::string>
strvec(
const T1& t1) {
202 template<
typename T1,
typename T2>
203 inline std::vector<std::string>
strvec(
const T1& t1,
const T2& t2) {
204 return {
str(t1),
str(t2)};
208 template<
typename T1,
typename T2,
typename T3>
209 inline std::vector<std::string>
strvec(
const T1& t1,
const T2& t2,
const T3& t3) {
214 template<
typename T1,
typename T2,
typename T3,
typename T4>
215 inline std::vector<std::string>
strvec(
const T1& t1,
const T2& t2,
const T3& t3,
221 template<
typename T1,
typename T2,
typename T3,
typename T4,
typename T5>
222 inline std::vector<std::string>
strvec(
const T1& t1,
const T2& t2,
const T3& t3,
223 const T4& t4,
const T5& t5) {
228 template<
typename T1,
typename T2,
typename T3,
typename T4,
typename T5,
typename T6>
229 inline std::vector<std::string>
strvec(
const T1& t1,
const T2& t2,
const T3& t3,
230 const T4& t4,
const T5& t5,
const T6& t6) {
235 inline std::string
fmtstr(
const std::string& fmt,
const std::vector<std::string>& args) {
237 for (
auto&& e : args) {
238 std::string::size_type n = s.find(
"%s");
239 if (n==std::string::npos)
return "** Ill-formatted string ** " + fmt;
247 std::string
str(
const T& v) {
248 std::stringstream ss;
254 std::string
str(
const T& v,
bool more) {
255 return v.get_str(more);
259 std::string
str(
const std::vector<T>& v,
bool more) {
260 std::stringstream ss;
262 for (casadi_int i=0; i<v.size(); ++i) {
263 if (i!=0) ss <<
", ";
271 std::string
str(
const std::set<T>& v,
bool more) {
272 std::stringstream ss;
275 for (
const auto& e : v) {
276 if (cnt++!=0) ss <<
", ";
283 template<
typename T1,
typename T2>
284 std::string
str(
const std::pair<T1, T2>& p,
bool more) {
285 std::stringstream ss;
286 ss <<
"[" << p.first <<
"," << p.second <<
"]";
290 template<
typename T1,
typename T2>
291 std::string
str(
const std::map<T1, T2>& p,
bool more) {
292 std::stringstream ss;
294 casadi_int count = 0;
296 ss << e.first <<
": " << e.second;
297 if (++count < p.size()) ss <<
", ";
303 template<
typename T2>
304 std::string
str(
const std::map<std::string, T2>& p,
bool more) {
305 std::stringstream ss;
307 casadi_int count = 0;
309 ss <<
"\"" << e.first <<
"\": " << e.second;
310 if (++count < p.size()) ss <<
", ";
316 template<
typename T,
size_t N>
317 std::string
str(
const std::array<T, N> &v,
bool more) {
318 std::stringstream ss;
320 for (casadi_int i=0; i<N; ++i) {
321 if (i!=0) ss <<
", ";
330 template<
typename _Mutex>
336 if (condition_) mtx_.lock();
340 if (condition_) mtx_.unlock();
353 #include "casadi_logger.hpp"
conditional_lock_guard & operator=(const conditional_lock_guard &)=delete
~conditional_lock_guard()
conditional_lock_guard(mutex_type &m, bool condition)
conditional_lock_guard(const conditional_lock_guard &)=delete
struct VariableStruct Variable
unsigned long long bvec_t
int(* casadi_checkout_t)(void)
Function pointer types for the C API.
int(* diff_t)(casadi_int i)
Function pointer types for the C API.
std::string fmtstr(const std::string &fmt, const std::vector< std::string > &args)
Create a string from a formatted string.
int(* eval_t)(const double **arg, double **res, casadi_int *iw, double *w, int)
Function pointer types for the C API.
casadi_int(* getint_t)(void)
Function pointer types for the C API.
int(* config_t)(int, const char **)
Function pointer types for the C API.
constexpr casadi_int LOOKUP_BINARY
std::string str(const T &v)
String representation, any type.
void(* casadi_release_t)(int)
Function pointer types for the C API.
void(* signal_t)(void)
Function pointer types for the C API.
constexpr casadi_int LOOKUP_EXACT
constexpr casadi_int LOOKUP_LINEAR
double(* default_t)(casadi_int i)
Function pointer types for the C API.
int(* work_t)(casadi_int *sz_arg, casadi_int *sz_res, casadi_int *sz_iw, casadi_int *sz_w)
Function pointer types for the C API.
std::vector< std::string > strvec()
Create a list of strings from VA_ARGS, no argument.