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
52 #define SWIG_INOUT1(arg) INOUT1
53 #define SWIG_INOUT2(arg) INOUT2
54 #define SWIG_INOUT3(arg) INOUT3
55 #define SWIG_INOUT4(arg) INOUT4
56 #define SWIG_INOUT5(arg) INOUT5
57 #define SWIG_INOUT6(arg) INOUT6
58 #define SWIG_CONSTREF(arg) const arg
60 #define SWIG_IND1 true
62 #define SWIG_IND1 false
65 #define SWIG_IF_ELSE(is_swig, not_swig) not_swig
66 #define SWIG_OUTPUT(arg) arg
67 #define SWIG_INOUT(arg) arg
68 #define SWIG_INOUT1(arg) arg
69 #define SWIG_INOUT2(arg) arg
70 #define SWIG_INOUT3(arg) arg
71 #define SWIG_INOUT4(arg) arg
72 #define SWIG_INOUT5(arg) arg
73 #define SWIG_INOUT6(arg) arg
74 #define SWIG_CONSTREF(arg) const arg &
75 #define SWIG_IND1 false
78 #include "casadi_types.hpp"
85 template<
class T>
class Matrix;
99 #ifdef __GNUC_PATCHLEVEL__
100 #define GCC_VERSION (__GNUC__ * 10000 +__GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
109 #pragma warning(disable:4018)
112 #pragma warning(disable:4244)
115 #pragma warning(disable:4251)
119 #pragma warning(disable:4275)
122 #pragma warning(disable:4715)
125 #pragma warning(disable:4800)
128 #pragma warning(disable:4910)
132 #pragma warning(disable:4996)
142 typedef unsigned long long bvec_t;
146 const int bvec_size = CHAR_BIT*
sizeof(bvec_t);
155 typedef int (*config_t)(int,
const char**);
156 typedef void (*signal_t)(void);
157 typedef casadi_int (*getint_t)(void);
158 typedef double (*default_t)(casadi_int i);
159 typedef const char* (*name_t)(casadi_int i);
160 typedef const casadi_int* (*sparsity_t)(casadi_int i);
161 typedef int (*diff_t)(casadi_int i);
162 typedef int (*casadi_checkout_t)(void);
163 typedef void (*casadi_release_t)(int);
164 typedef int (*work_t)(casadi_int* sz_arg, casadi_int* sz_res,
165 casadi_int* sz_iw, casadi_int* sz_w);
166 typedef int (*eval_t)(
const double** arg,
double** res,
167 casadi_int* iw,
double* w, int);
171 constexpr casadi_int LOOKUP_LINEAR = 0;
172 constexpr casadi_int LOOKUP_EXACT = 1;
173 constexpr casadi_int LOOKUP_BINARY = 2;
177 std::string str(
const T& v);
181 std::string str(
const T& v,
bool more);
185 std::string str(
const std::vector<T>& v,
bool more=
false);
189 std::string str(
const std::set<T>& v,
bool more=
false);
192 template<
typename T1,
typename T2>
193 std::string str(
const std::pair<T1, T2>& p,
bool more=
false);
196 template<
typename T1,
typename T2>
197 std::string str(
const std::map<T1, T2> &p,
bool more=
false);
200 template<
typename T2>
201 std::string str(
const std::map<std::string, T2> &p,
bool more=
false);
204 template<
typename T,
size_t N>
205 std::string str(
const std::array<T, N> &p,
bool more=
false);
208 inline std::vector<std::string> strvec() {
213 template<
typename T1>
214 inline std::vector<std::string> strvec(
const T1& t1) {
219 template<
typename T1,
typename T2>
220 inline std::vector<std::string> strvec(
const T1& t1,
const T2& t2) {
221 return {str(t1), str(t2)};
225 template<
typename T1,
typename T2,
typename T3>
226 inline std::vector<std::string> strvec(
const T1& t1,
const T2& t2,
const T3& t3) {
227 return {str(t1), str(t2), str(t3)};
231 template<
typename T1,
typename T2,
typename T3,
typename T4>
232 inline std::vector<std::string> strvec(
const T1& t1,
const T2& t2,
const T3& t3,
234 return {str(t1), str(t2), str(t3), str(t4)};
238 template<
typename T1,
typename T2,
typename T3,
typename T4,
typename T5>
239 inline std::vector<std::string> strvec(
const T1& t1,
const T2& t2,
const T3& t3,
240 const T4& t4,
const T5& t5) {
241 return {str(t1), str(t2), str(t3), str(t4), str(t5)};
245 template<
typename T1,
typename T2,
typename T3,
typename T4,
typename T5,
typename T6>
246 inline std::vector<std::string> strvec(
const T1& t1,
const T2& t2,
const T3& t3,
247 const T4& t4,
const T5& t5,
const T6& t6) {
248 return {str(t1), str(t2), str(t3), str(t4), str(t5), str(t6)};
252 inline std::string fmtstr(
const std::string& fmt,
const std::vector<std::string>& args) {
254 for (
auto&& e : args) {
255 std::string::size_type n = s.find(
"%s");
256 if (n==std::string::npos)
return "** Ill-formatted string ** " + fmt;
264 std::string str(
const T& v) {
265 std::stringstream ss;
271 std::string str(
const T& v,
bool more) {
272 return v.get_str(more);
276 std::string str(
const std::vector<T>& v,
bool more) {
277 std::stringstream ss;
279 for (casadi_int i=0; i<v.size(); ++i) {
280 if (i!=0) ss <<
", ";
288 std::string str(
const std::set<T>& v,
bool more) {
289 std::stringstream ss;
292 for (
const auto& e : v) {
293 if (cnt++!=0) ss <<
", ";
300 template<
typename T1,
typename T2>
301 std::string str(
const std::pair<T1, T2>& p,
bool more) {
302 std::stringstream ss;
303 ss <<
"[" << str(p.first) <<
"," << str(p.second) <<
"]";
307 template<
typename T1,
typename T2>
308 std::string str(
const std::map<T1, T2>& p,
bool more) {
309 std::stringstream ss;
311 casadi_int count = 0;
313 ss << str(e.first) <<
": " << str(e.second);
314 if (++count < p.size()) ss <<
", ";
320 template<
typename T2>
321 std::string str(
const std::map<std::string, T2>& p,
bool more) {
322 std::stringstream ss;
324 casadi_int count = 0;
326 ss <<
"\"" << e.first <<
"\": " << str(e.second);
327 if (++count < p.size()) ss <<
", ";
333 template<
typename T,
size_t N>
334 std::string str(
const std::array<T, N> &v,
bool more) {
335 std::stringstream ss;
337 for (casadi_int i=0; i<N; ++i) {
338 if (i!=0) ss <<
", ";
355 class ThreadLocalStorage {
356 alignas(
T)
char storage_[
sizeof(T)];
364 return *
reinterpret_cast<T*
>(storage_);
369 template<
typename _Mutex>
370 class conditional_lock_guard {
372 typedef _Mutex mutex_type;
374 conditional_lock_guard(mutex_type& m,
bool condition) : mtx_(m), condition_(condition) {
375 if (condition_) mtx_.lock();
378 ~conditional_lock_guard() {
379 if (condition_) mtx_.unlock();
382 conditional_lock_guard(
const conditional_lock_guard&) =
delete;
383 conditional_lock_guard& operator=(
const conditional_lock_guard&) =
delete;
393 #include "casadi_logger.hpp"