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)
126 typedef unsigned long long bvec_t;
130 const int bvec_size = CHAR_BIT*
sizeof(bvec_t);
139 typedef int (*config_t)(int,
const char**);
140 typedef void (*signal_t)(void);
141 typedef casadi_int (*getint_t)(void);
142 typedef double (*default_t)(casadi_int i);
143 typedef const char* (*name_t)(casadi_int i);
144 typedef const casadi_int* (*sparsity_t)(casadi_int i);
145 typedef int (*diff_t)(casadi_int i);
146 typedef int (*casadi_checkout_t)(void);
147 typedef void (*casadi_release_t)(int);
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);
155 constexpr casadi_int LOOKUP_LINEAR = 0;
156 constexpr casadi_int LOOKUP_EXACT = 1;
157 constexpr casadi_int LOOKUP_BINARY = 2;
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) {
211 return {str(t1), str(t2), str(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,
218 return {str(t1), str(t2), str(t3), str(t4)};
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) {
225 return {str(t1), str(t2), str(t3), str(t4), str(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) {
232 return {str(t1), str(t2), str(t3), str(t4), str(t5), str(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 <<
", ";
339 class ThreadLocalStorage {
340 alignas(
T)
char storage_[
sizeof(T)];
348 return *
reinterpret_cast<T*
>(storage_);
353 template<
typename _Mutex>
354 class conditional_lock_guard {
356 typedef _Mutex mutex_type;
358 conditional_lock_guard(mutex_type& m,
bool condition) : mtx_(m), condition_(condition) {
359 if (condition_) mtx_.lock();
362 ~conditional_lock_guard() {
363 if (condition_) mtx_.unlock();
366 conditional_lock_guard(
const conditional_lock_guard&) =
delete;
367 conditional_lock_guard& operator=(
const conditional_lock_guard&) =
delete;
377 #include "casadi_logger.hpp"