26 #ifndef CASADI_COMMON_HPP
27 #define CASADI_COMMON_HPP
45 #define SWIG_IF_ELSE(is_swig, not_swig) is_swig
46 #define SWIG_OUTPUT(arg) OUTPUT
47 #define SWIG_INOUT(arg) INOUT
48 #define SWIG_CONSTREF(arg) const arg
50 #define SWIG_IND1 true
52 #define SWIG_IND1 false
55 #define SWIG_IF_ELSE(is_swig, not_swig) not_swig
56 #define SWIG_OUTPUT(arg) arg
57 #define SWIG_INOUT(arg) arg
58 #define SWIG_CONSTREF(arg) const arg &
59 #define SWIG_IND1 false
62 #include "casadi_types.hpp"
69 template<
class T>
class Matrix;
83 #ifdef __GNUC_PATCHLEVEL__
84 #define GCC_VERSION (__GNUC__ * 10000 +__GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
93 #pragma warning(disable:4018)
96 #pragma warning(disable:4244)
99 #pragma warning(disable:4251)
103 #pragma warning(disable:4275)
106 #pragma warning(disable:4715)
109 #pragma warning(disable:4800)
112 #pragma warning(disable:4910)
116 #pragma warning(disable:4996)
143 typedef const char* (*name_t)(casadi_int i);
144 typedef const casadi_int* (*sparsity_t)(casadi_int i);
148 typedef int (*
work_t)(casadi_int* sz_arg, casadi_int* sz_res,
149 casadi_int* sz_iw, casadi_int* sz_w);
150 typedef int (*
eval_t)(
const double** arg,
double** res,
151 casadi_int* iw,
double* w, int);
161 std::string
str(
const T& v);
165 std::string
str(
const T& v,
bool more);
169 std::string
str(
const std::vector<T>& v,
bool more=
false);
173 std::string
str(
const std::set<T>& v,
bool more=
false);
176 template<
typename T1,
typename T2>
177 std::string
str(
const std::pair<T1, T2>& p,
bool more=
false);
180 template<
typename T1,
typename T2>
181 std::string
str(
const std::map<T1, T2> &p,
bool more=
false);
184 template<
typename T2>
185 std::string
str(
const std::map<std::string, T2> &p,
bool more=
false);
188 template<
typename T,
size_t N>
189 std::string
str(
const std::array<T, N> &p,
bool more=
false);
192 inline std::vector<std::string>
strvec() {
197 template<
typename T1>
198 inline std::vector<std::string>
strvec(
const T1& t1) {
203 template<
typename T1,
typename T2>
204 inline std::vector<std::string>
strvec(
const T1& t1,
const T2& t2) {
205 return {
str(t1),
str(t2)};
209 template<
typename T1,
typename T2,
typename T3>
210 inline std::vector<std::string>
strvec(
const T1& t1,
const T2& t2,
const T3& t3) {
215 template<
typename T1,
typename T2,
typename T3,
typename T4>
216 inline std::vector<std::string>
strvec(
const T1& t1,
const T2& t2,
const T3& t3,
222 template<
typename T1,
typename T2,
typename T3,
typename T4,
typename T5>
223 inline std::vector<std::string>
strvec(
const T1& t1,
const T2& t2,
const T3& t3,
224 const T4& t4,
const T5& t5) {
229 template<
typename T1,
typename T2,
typename T3,
typename T4,
typename T5,
typename T6>
230 inline std::vector<std::string>
strvec(
const T1& t1,
const T2& t2,
const T3& t3,
231 const T4& t4,
const T5& t5,
const T6& t6) {
236 inline std::string
fmtstr(
const std::string& fmt,
const std::vector<std::string>& args) {
238 for (
auto&& e : args) {
239 std::string::size_type n = s.find(
"%s");
240 if (n==std::string::npos)
return "** Ill-formatted string ** " + fmt;
248 std::string
str(
const T& v) {
249 std::stringstream ss;
255 std::string
str(
const T& v,
bool more) {
256 return v.get_str(more);
260 std::string
str(
const std::vector<T>& v,
bool more) {
261 std::stringstream ss;
263 for (casadi_int i=0; i<v.size(); ++i) {
264 if (i!=0) ss <<
", ";
272 std::string
str(
const std::set<T>& v,
bool more) {
273 std::stringstream ss;
276 for (
const auto& e : v) {
277 if (cnt++!=0) ss <<
", ";
284 template<
typename T1,
typename T2>
285 std::string
str(
const std::pair<T1, T2>& p,
bool more) {
286 std::stringstream ss;
287 ss <<
"[" <<
str(p.first) <<
"," <<
str(p.second) <<
"]";
291 template<
typename T1,
typename T2>
292 std::string
str(
const std::map<T1, T2>& p,
bool more) {
293 std::stringstream ss;
295 casadi_int count = 0;
297 ss <<
str(e.first) <<
": " <<
str(e.second);
298 if (++count < p.size()) ss <<
", ";
304 template<
typename T2>
305 std::string
str(
const std::map<std::string, T2>& p,
bool more) {
306 std::stringstream ss;
308 casadi_int count = 0;
310 ss <<
"\"" << e.first <<
"\": " <<
str(e.second);
311 if (++count < p.size()) ss <<
", ";
317 template<
typename T,
size_t N>
318 std::string
str(
const std::array<T, N> &v,
bool more) {
319 std::stringstream ss;
321 for (casadi_int i=0; i<N; ++i) {
322 if (i!=0) ss <<
", ";
340 alignas(
T)
char storage_[
sizeof(
T)];
348 return *
reinterpret_cast<T*
>(storage_);
353 template<
typename _Mutex>
359 if (condition_) mtx_.lock();
363 if (condition_) mtx_.unlock();
377 #include "casadi_logger.hpp"
Thread-local storage wrapper that avoids destructor calls.
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.