2014-02-06 18:52:13 +00:00
|
|
|
/*
|
|
|
|
* 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 <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef Latan_Global_hpp_
|
|
|
|
#define Latan_Global_hpp_
|
2013-05-21 18:02:42 +01:00
|
|
|
|
2014-01-23 14:06:50 +00:00
|
|
|
#include <map>
|
2013-05-21 18:02:42 +01:00
|
|
|
#include <string>
|
|
|
|
#include <latan/Eigen/Dense>
|
|
|
|
|
2014-02-06 18:52:13 +00:00
|
|
|
#define BEGIN_NAMESPACE namespace Latan {
|
|
|
|
#define END_NAMESPACE }
|
2013-05-21 18:02:42 +01:00
|
|
|
|
2014-02-17 18:50:03 +00:00
|
|
|
// macro utilities
|
|
|
|
#define unique_arg(...) __VA_ARGS__
|
|
|
|
|
2013-05-21 18:02:42 +01:00
|
|
|
// attribute to switch off unused warnings with gcc
|
|
|
|
#ifdef __GNUC__
|
|
|
|
#define __dumb __attribute__((unused))
|
|
|
|
#else
|
|
|
|
#define __dumb
|
|
|
|
#endif
|
|
|
|
|
2014-02-12 18:33:33 +00:00
|
|
|
// max length for paths
|
2014-02-17 18:50:03 +00:00
|
|
|
#define MAX_PATH_LENGTH 512u
|
|
|
|
|
|
|
|
// copy/assignement from Eigen expression
|
|
|
|
#define EIGEN_EXPR_CTOR(ctorName, Class, Base, EigenBase) \
|
|
|
|
template <typename Derived>\
|
2014-02-20 20:20:37 +00:00
|
|
|
ctorName(const Eigen::EigenBase<Derived> &m): Base(m) {}\
|
2014-02-17 18:50:03 +00:00
|
|
|
template<typename Derived>\
|
|
|
|
Class & operator=(const Eigen::EigenBase<Derived> &m)\
|
|
|
|
{\
|
|
|
|
this->Base::operator=(m);\
|
|
|
|
return *this;\
|
|
|
|
}
|
2014-02-12 18:33:33 +00:00
|
|
|
|
2014-02-06 18:52:13 +00:00
|
|
|
BEGIN_NAMESPACE
|
2013-05-21 18:02:42 +01:00
|
|
|
|
|
|
|
// Environment
|
|
|
|
namespace Env
|
|
|
|
{
|
2014-01-22 15:57:47 +00:00
|
|
|
extern const std::string fullName;
|
|
|
|
extern const std::string name;
|
|
|
|
extern const std::string version;
|
2014-02-20 22:54:11 +00:00
|
|
|
extern const std::string msgPrefix;
|
2013-05-21 18:02:42 +01:00
|
|
|
}
|
|
|
|
|
2014-02-21 01:17:51 +00:00
|
|
|
// vector type
|
|
|
|
typedef Eigen::VectorXd DVec;
|
|
|
|
|
2014-02-18 18:09:41 +00:00
|
|
|
// pointer type test
|
|
|
|
template <typename Derived, typename Base>
|
|
|
|
inline bool isDerivedFrom(const Base *pt)
|
|
|
|
{
|
|
|
|
return (dynamic_cast<const Derived *>(pt) != nullptr);
|
|
|
|
}
|
|
|
|
|
2013-05-21 18:02:42 +01:00
|
|
|
// string conversions
|
|
|
|
template <typename T>
|
2014-02-18 18:09:41 +00:00
|
|
|
inline T strTo(const std::string &str)
|
2013-05-21 18:02:42 +01:00
|
|
|
{
|
|
|
|
T buf;
|
|
|
|
std::istringstream stream(str);
|
|
|
|
|
|
|
|
stream >> buf;
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2014-02-12 18:36:36 +00:00
|
|
|
//// optimized specializations
|
|
|
|
template <>
|
2014-02-18 18:09:41 +00:00
|
|
|
inline float strTo<float>(const std::string &str)
|
|
|
|
{
|
|
|
|
return strtof(str.c_str(), (char **)NULL);
|
|
|
|
}
|
2014-02-12 18:36:36 +00:00
|
|
|
template <>
|
2014-02-18 18:09:41 +00:00
|
|
|
inline double strTo<double>(const std::string &str)
|
|
|
|
{
|
|
|
|
return strtod(str.c_str(), (char **)NULL);
|
|
|
|
}
|
2014-02-12 18:36:36 +00:00
|
|
|
template <>
|
2014-02-18 18:09:41 +00:00
|
|
|
inline int strTo<int>(const std::string &str)
|
|
|
|
{
|
|
|
|
return (int)(strtol(str.c_str(), (char **)NULL, 10));
|
|
|
|
}
|
2014-02-12 18:36:36 +00:00
|
|
|
|
2013-05-21 18:02:42 +01:00
|
|
|
template <typename T>
|
2014-02-18 18:09:41 +00:00
|
|
|
inline std::string strFrom(const T x)
|
2013-05-21 18:02:42 +01:00
|
|
|
{
|
|
|
|
std::ostringstream stream;
|
|
|
|
|
|
|
|
stream << x;
|
|
|
|
|
|
|
|
return stream.str();
|
|
|
|
}
|
|
|
|
|
2014-02-06 18:52:13 +00:00
|
|
|
END_NAMESPACE
|
2013-05-21 18:02:42 +01:00
|
|
|
|
|
|
|
#include <latan/Exceptions.hpp>
|
|
|
|
|
2014-02-06 18:52:13 +00:00
|
|
|
#endif // Latan_Global_hpp_
|