/* * Global.hpp, part of LatAnalyze 3 * * Copyright (C) 2013 - 2014 Antonin Portelli * * LatAnalyze 3 is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * LatAnalyze 3 is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with LatAnalyze 3. If not, see . */ #ifndef Latan_Global_hpp_ #define Latan_Global_hpp_ // supress warning for the osbolete use of 'register' keyword in Eigen #pragma GCC diagnostic ignored "-Wdeprecated-register" #include #include #include #include #include #include #include #include #define BEGIN_NAMESPACE namespace Latan { #define END_NAMESPACE } // macro utilities #define unique_arg(...) __VA_ARGS__ #define DEBUG_VAR(x) std::cout << #x << "= " << x << std::endl #define DEBUG_MAT(m) std::cout << #m << "=\n" << m << std::endl // attribute to switch off unused warnings with gcc #ifndef __GNUC__ #define __unused #endif // max length for paths #define MAX_PATH_LENGTH 512u // copy/assignement from Eigen expression #define EIGEN_EXPR_CTOR(ctorName, Class, Base, ExprType) \ template \ ctorName(const ExprType &m): Base(m) {}\ template\ Class & operator=(const ExprType &m)\ {\ this->Base::operator=(m);\ return *this;\ } BEGIN_NAMESPACE // Eigen type aliases ////////////////////////////////////////////////////////// const int dynamic = -1; // array types template using ArrayExpr = Eigen::ArrayBase; template using Array = Eigen::Array; // matrix types template using MatExpr = Eigen::MatrixBase; template using MatBase = Eigen::Matrix; typedef MatBase DMatBase; // vector types template using Vec = MatBase; typedef Vec IVec; typedef Vec LVec; typedef Vec DVec; typedef Vec> CVec; #define FOR_VEC(vec, i) for (Latan::Index i = 0; i < (vec).size(); ++i) #define FOR_ARRAY(ar, i) FOR_VEC(ar, i) // block types template using Block = Eigen::Block; template using ConstBlock = const Eigen::Block; template using Row = typename Derived::RowXpr; template using ConstRow = typename Derived::ConstRowXpr; template using Col = typename Derived::ColXpr; template using ConstCol = typename Derived::ConstColXpr; // map type template using Map = Eigen::Map; template using ConstMap = Eigen::Map; // Index type ////////////////////////////////////////////////////////////////// typedef MatBase::Index Index; // Placeholder type //////////////////////////////////////////////////////////// struct PlaceHolder {}; extern PlaceHolder _; // Type utilities ////////////////////////////////////////////////////////////// // pointer type test template inline bool isDerivedFrom(const Base *pt) { return (dynamic_cast(pt) != nullptr); } // static logical or template struct static_or; template struct static_or : static_or {}; template struct static_or : std::false_type {}; template <> struct static_or<> : std::true_type {}; // Environment ///////////////////////////////////////////////////////////////// namespace Env { extern const std::string fullName; extern const std::string name; extern const std::string version; extern const std::string msgPrefix; // empty function for library test void function(void); } // String conversions ////////////////////////////////////////////////////////// template inline T strTo(const std::string &str) { T buf; std::istringstream stream(str); stream >> buf; return buf; } // optimized specializations template <> inline float strTo(const std::string &str) { return strtof(str.c_str(), (char **)NULL); } template <> inline double strTo(const std::string &str) { return strtod(str.c_str(), (char **)NULL); } template <> inline int strTo(const std::string &str) { return (int)(strtol(str.c_str(), (char **)NULL, 10)); } template <> inline long strTo(const std::string &str) { return strtol(str.c_str(), (char **)NULL, 10); } template <> inline std::string strTo(const std::string &str) { return str; } template inline std::string strFrom(const T x) { std::ostringstream stream; stream << x; return stream.str(); } // specialization for vectors template<> inline DVec strTo(const std::string &str) { DVec res; std::vector vbuf; double buf; std::istringstream stream(str); while (!stream.eof()) { stream >> buf; vbuf.push_back(buf); } res = Map(vbuf.data(), static_cast(vbuf.size())); return res; } template<> inline IVec strTo(const std::string &str) { IVec res; std::vector vbuf; int buf; std::istringstream stream(str); while (!stream.eof()) { stream >> buf; vbuf.push_back(buf); } res = Map(vbuf.data(), static_cast(vbuf.size())); return res; } END_NAMESPACE #include #endif // Latan_Global_hpp_