28 #ifndef TOMOGRAPHER_TOOLS_UTILS_H 29 #define TOMOGRAPHER_TOOLS_UTILS_H 41 #include <type_traits> 62 #define TOMO_STATIC_ASSERT_EXPR(...) \ 63 static_assert(__VA_ARGS__, #__VA_ARGS__) 66 #ifndef tomographer_assert 67 #define tomographer_assert(...) eigen_assert((__VA_ARGS__) && "assert: " #__VA_ARGS__) 72 #ifndef TOMOGRAPHER_PARSED_BY_DOXYGEN 75 #define TOMOGRAPHER_ENABLED_IF(...) \ 76 template<bool _dummy__enabledif = false, \ 77 typename std::enable_if<_dummy__enabledif || (__VA_ARGS__), bool>::type \ 78 _dummy__enabledif2 = false> 79 #define TOMOGRAPHER_ENABLED_IF_TMPL(...) \ 80 bool _dummy__enabledif = false, \ 81 typename std::enable_if<_dummy__enabledif || (__VA_ARGS__), bool>::type \ 82 _dummy__enabledif2 = true 90 #define TOMOGRAPHER_ENABLED_IF_TMPL_REPEAT(...) \ 91 bool _dummy__enabledif, \ 92 typename std::enable_if<_dummy__enabledif || (__VA_ARGS__), bool>::type \ 93 _dummy__enabledifAlt2 = true 108 namespace tomo_internal {
109 template <
typename F>
111 FinalAction(F f) : clean_{f} {}
112 ~FinalAction() { clean_(); }
128 template <
typename F>
129 inline tomo_internal::FinalAction<F>
finally(F f)
131 return tomo_internal::FinalAction<F>(f);
158 template<
typename T_,
bool IsDynamic_, T_ StaticValue_ = T_()>
169 static constexpr
bool IsDynamic = IsDynamic_;
171 static constexpr T StaticValue = StaticValue_;
181 tomographer_assert(val == StaticValue);
189 inline T
value()
const {
return StaticValue; }
198 template<
typename T_,
bool IsDynamic_, T_ StaticValue_>
200 template<
typename T_,
bool IsDynamic_, T_ StaticValue_>
207 template<
typename T_, T_ StaticValue_>
215 static constexpr
bool IsDynamic =
true;
228 inline T
value()
const {
return _dyn_value; }
239 template<
typename T_, T_ StaticValue_>
255 template<
typename T_,
bool enabled>
261 static constexpr
bool IsEnabled =
false;
264 template<
typename... Args>
268 template<
typename T_,
bool enabled>
274 template<
typename T_>
280 static constexpr
bool IsEnabled =
true;
286 template<
typename... ArgTypes>
290 template<
typename T_>
301 inline std::ostream & operator<<(std::ostream & str, const StoreIfEnabled<T, false>& )
314 inline std::ostream & operator<<(std::ostream & str, const StoreIfEnabled<T, true>& val)
327 template<
typename IntType =
int>
331 return N && !(N & (N - 1));
343 template<
typename Scalar>
358 template<
typename Scalar>
364 template<
typename RealScalar>
367 typedef RealScalar type;
405 #if defined(__GNUC__) || defined(__clang__) || defined(TOMOGRAPHER_PARSED_BY_DOXGEN) 425 # define PRINTF1_ARGS_SAFE __attribute__ ((__format__ (__printf__, 1, 2))) 426 # define PRINTF2_ARGS_SAFE __attribute__ ((__format__ (__printf__, 2, 3))) 428 # define PRINTF3_ARGS_SAFE __attribute__ ((__format__ (__printf__, 3, 4))) 430 # define PRINTF4_ARGS_SAFE __attribute__ ((__format__ (__printf__, 4, 5))) 433 # define PRINTF1_ARGS_SAFE 434 # define PRINTF2_ARGS_SAFE 435 # define PRINTF3_ARGS_SAFE 436 # define PRINTF4_ARGS_SAFE 442 #if TOMOGRAPHER_PARSED_BY_DOXYGEN 451 # define TOMOGRAPHER_CXX_STACK_FORCE_REALIGN 452 #else // TOMOGRAPHER_PARSED_BY_DOXYGEN 454 #if defined(__GNUC__) || defined(__clang__) 455 # if defined(__MINGW32__) || defined(__MINGW64__) 456 # define TOMOGRAPHER_CXX_STACK_FORCE_REALIGN __attribute__((force_align_arg_pointer,noinline)) 458 # define TOMOGRAPHER_CXX_STACK_FORCE_REALIGN 462 # define TOMOGRAPHER_CXX_STACK_FORCE_REALIGN 464 # warning "You are using an unknown compiler. You may run into memory alignment problems... Good luck!" 465 # define TOMOGRAPHER_CXX_STACK_FORCE_REALIGN 468 #endif // TOMOGRAPHER_PARSED_BY_DOXYGEN 475 namespace tomo_internal {
476 template<
typename Enabledtype =
void>
struct sfinae_no {
typedef int no[1]; };
477 template<
typename EnabledType =
void>
struct sfinae_yes {
typedef int yes[2]; };
498 const int offset = max_width;
500 #if defined(__MINGW32__) || defined(__MINGW64__) 509 if (cols_s != NULL) {
531 #define TOMO_FUNCTION __PRETTY_FUNCTION__ 535 namespace tomo_internal {
537 struct extractFuncName_helper {
541 constexpr extracted(
std::size_t dp,
const conststr& s) : decl_pos(dp), extr(s) { }
543 static constexpr conststr alltofirstparen(
const conststr& s)
545 return s.substr(0, s.find(conststr(
"("), 0, s.size()));
549 return found_pos == std::string::npos ? 0 : found_pos + 1;
551 static constexpr
std::size_t pos_decl(
const conststr& s)
553 return ((s.size() > 2)
554 ? declpos_from_found_spc(s.rfind(conststr(
" "), std::string::npos))
557 static constexpr extracted allfromfirstspace(
const conststr& s)
559 return extracted(pos_decl(s),
560 s.substr_e(pos_decl(s),
563 static constexpr extracted do_extract(
const conststr& funcname)
565 return allfromfirstspace(alltofirstparen(funcname));
567 static constexpr conststr extract_choose(
const extracted& do_extracted,
568 const conststr& funcname)
570 return (do_extracted.extr.substr(0,8) == conststr(
"operator")
571 ? funcname.substr(do_extracted.decl_pos)
572 : do_extracted.extr);
574 static constexpr conststr extract(
const conststr& funcname)
576 return extract_choose(do_extract(funcname), funcname);
589 return tomo_internal::extractFuncName_helper::extract(funcname);
635 #define TOMOGRAPHER_DEFINE_MSG_EXCEPTION(ClassName, ErrPrefix) \ 636 class ClassName : public std::exception { \ 639 ClassName(std::string msg) : _msg(std::string(ErrPrefix) + std::move(msg)) { } \ 640 virtual ~ClassName() throw() { } \ 641 std::string msg() const { return _msg; } \ 642 const char * what() const throw() { return _msg.c_str(); } \ 653 #define TOMOGRAPHER_DEFINE_MSG_EXCEPTION_BASE(ClassName, ErrPrefix, BaseClass) \ 654 class ClassName : public BaseClass { \ 656 ClassName(std::string msg) : BaseClass(std::string(ErrPrefix) + std::move(msg)) { } \ 657 virtual ~ClassName() throw() { } \ 677 template<
typename ExceptionClass = std::runtime_error>
680 throw ExceptionClass(message);
#define TOMO_STATIC_ASSERT_EXPR(...)
Tool for static assertions without message.
Base namespace for the Tomographer project.
A constexpr string type, suitable for basic compile-time string processing.
VarValueDecoder< T >::RetType value(const Var &var)
Access the value of the given variable, as a C++ type.