28 #ifndef TOMOGRAPHER_TOOLS_UTILS_H 29 #define TOMOGRAPHER_TOOLS_UTILS_H 43 #include <type_traits> 62 namespace tomo_internal {
65 FinalAction(F f) : clean_(f) {}
66 ~FinalAction() { clean_(); }
83 inline tomo_internal::FinalAction<F>
finally(F f)
85 return tomo_internal::FinalAction<F>(f);
98 template<
typename T,
typename S1,
typename S2>
struct Concatenate;
100 template<
typename T, T... I1, T... I2>
102 :
Sequence<T, I1..., (sizeof...(I1)+I2)...> {};
104 template<
typename T, T N,
typename dummy =
void>
107 template<
typename T, T N,
typename >
109 typename GenerateSequence<T, N - N/2>::type>::type {};
111 template<
typename T, T N>
115 template<
typename T, T N>
141 template<
typename T_,
bool IsDynamic_, T_ StaticValue_ = T_()>
152 static constexpr
bool IsDynamic = IsDynamic_;
154 static constexpr T StaticValue = StaticValue_;
172 inline T
value()
const {
return StaticValue; }
181 template<
typename T_,
bool IsDynamic_, T_ StaticValue_>
183 template<
typename T_,
bool IsDynamic_, T_ StaticValue_>
190 template<
typename T_, T_ StaticValue_>
198 static constexpr
bool IsDynamic =
true;
211 inline T
value()
const {
return _dyn_value; }
222 template<
typename T_, T_ StaticValue_>
238 template<
typename T_,
bool enabled>
244 static constexpr
bool IsEnabled =
false;
247 template<
typename... Args>
251 template<
typename T_,
bool enabled>
257 template<
typename T_>
263 static constexpr
bool IsEnabled =
true;
269 template<
typename... ArgTypes>
273 template<
typename T_>
284 inline std::ostream & operator<<(std::ostream & str, const StoreIfEnabled<T, false>& )
297 inline std::ostream & operator<<(std::ostream & str, const StoreIfEnabled<T, true>& val)
310 template<
typename IntType =
int>
314 return N && !(N & (N - 1));
329 template<
typename Scalar>
335 template<
typename RealScalar>
338 typedef RealScalar type;
387 #if defined(__GNUC__) || defined(__clang__) || defined(TOMOGRAPHER_PARSED_BY_DOXGEN) 407 # define PRINTF1_ARGS_SAFE __attribute__ ((__format__ (__printf__, 1, 2))) 408 # define PRINTF2_ARGS_SAFE __attribute__ ((__format__ (__printf__, 2, 3))) 410 # define PRINTF3_ARGS_SAFE __attribute__ ((__format__ (__printf__, 3, 4))) 412 # define PRINTF4_ARGS_SAFE __attribute__ ((__format__ (__printf__, 4, 5))) 415 # define PRINTF1_ARGS_SAFE 416 # define PRINTF2_ARGS_SAFE 417 # define PRINTF3_ARGS_SAFE 418 # define PRINTF4_ARGS_SAFE 424 #if TOMOGRAPHER_PARSED_BY_DOXYGEN 433 # define TOMOGRAPHER_CXX_STACK_FORCE_REALIGN 434 #else // TOMOGRAPHER_PARSED_BY_DOXYGEN 436 #if defined(__GNUC__) || defined(__clang__) 437 # if defined(__MINGW32__) || defined(__MINGW64__) 438 # define TOMOGRAPHER_CXX_STACK_FORCE_REALIGN __attribute__((force_align_arg_pointer,noinline)) 440 # define TOMOGRAPHER_CXX_STACK_FORCE_REALIGN 444 # define TOMOGRAPHER_CXX_STACK_FORCE_REALIGN 446 # warning "You are using an unknown compiler. You may run into memory alignment problems... Good luck!" 447 # define TOMOGRAPHER_CXX_STACK_FORCE_REALIGN 450 #endif // TOMOGRAPHER_PARSED_BY_DOXYGEN 457 namespace tomo_internal {
458 template<
typename Enabledtype =
void>
struct sfinae_no {
typedef int no[1]; };
459 template<
typename EnabledType =
void>
struct sfinae_yes {
typedef int yes[2]; };
480 const int offset = max_width;
482 #if defined(__MINGW32__) || defined(__MINGW64__) 491 if (cols_s != NULL) {
513 #define TOMO_FUNCTION __PRETTY_FUNCTION__ 517 namespace tomo_internal {
519 struct extractFuncName_helper {
523 constexpr extracted(
std::size_t dp,
const conststr& s) : decl_pos(dp), extr(s) { }
525 static constexpr conststr alltofirstparen(
const conststr& s)
527 return s.substr(0, s.find(conststr(
"("), 0, s.size()));
531 return found_pos == std::string::npos ? 0 : found_pos + 1;
533 static constexpr
std::size_t pos_decl(
const conststr& s)
535 return ((s.size() > 2)
536 ? declpos_from_found_spc(s.rfind(conststr(
" "), std::string::npos))
539 static constexpr extracted allfromfirstspace(
const conststr& s)
541 return extracted(pos_decl(s),
542 s.substr_e(pos_decl(s),
545 static constexpr extracted do_extract(
const conststr& funcname)
547 return allfromfirstspace(alltofirstparen(funcname));
549 static constexpr conststr extract_choose(
const extracted& do_extracted,
550 const conststr& funcname)
552 return (do_extracted.extr.substr(0,8) == conststr(
"operator")
553 ? funcname.substr(do_extracted.decl_pos)
554 : do_extracted.extr);
556 static constexpr conststr extract(
const conststr& funcname)
558 return extract_choose(do_extract(funcname), funcname);
571 return tomo_internal::extractFuncName_helper::extract(funcname);
617 #define TOMOGRAPHER_DEFINE_MSG_EXCEPTION(ClassName, ErrPrefix) \ 618 class TOMOGRAPHER_EXPORT ClassName : public std::exception { \ 621 ClassName(std::string msg) : _msg(std::string(ErrPrefix) + std::move(msg)) { } \ 622 virtual ~ClassName() throw() { } \ 623 std::string msg() const { return _msg; } \ 624 const char * what() const throw() { return _msg.c_str(); } \ 635 #define TOMOGRAPHER_DEFINE_MSG_EXCEPTION_BASE(ClassName, ErrPrefix, BaseClass) \ 636 class TOMOGRAPHER_EXPORT ClassName : public BaseClass { \ 638 ClassName(std::string msg) : BaseClass(std::string(ErrPrefix) + std::move(msg)) { } \ 639 virtual ~ClassName() throw() { } \ 659 template<
typename ExceptionClass = std::runtime_error>
662 throw ExceptionClass(message);
Base namespace for the Tomographer project.
#define TOMO_STATIC_ASSERT_EXPR(...)
Tool for static assertions without message.
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.
Basic definitions, which may have to be defined before any Eigen headers or further utilities are inc...
#define tomographer_assert(...)
Assertion test macro.