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);
112 template<
typename T_,
bool IsDynamic_, T_ StaticValue_ = T_()>
123 static constexpr
bool IsDynamic = IsDynamic_;
125 static constexpr T StaticValue = StaticValue_;
143 inline T
value()
const {
return StaticValue; }
152 template<
typename T_,
bool IsDynamic_, T_ StaticValue_>
154 template<
typename T_,
bool IsDynamic_, T_ StaticValue_>
161 template<
typename T_, T_ StaticValue_>
169 static constexpr
bool IsDynamic =
true;
182 inline T
value()
const {
return _dyn_value; }
193 template<
typename T_, T_ StaticValue_>
209 template<
typename T_,
bool enabled>
215 static constexpr
bool IsEnabled =
false;
218 template<
typename... Args>
222 template<
typename T_,
bool enabled>
228 template<
typename T_>
234 static constexpr
bool IsEnabled =
true;
240 template<
typename... ArgTypes>
244 template<
typename T_>
255 inline std::ostream & operator<<(std::ostream & str, const StoreIfEnabled<T, false>& )
268 inline std::ostream & operator<<(std::ostream & str, const StoreIfEnabled<T, true>& val)
281 template<
typename IntType =
int>
285 return N && !(N & (N - 1));
300 template<
typename Scalar>
306 template<
typename RealScalar>
309 typedef RealScalar type;
347 #if defined(__GNUC__) || defined(__clang__) || defined(TOMOGRAPHER_PARSED_BY_DOXGEN) 367 # define PRINTF1_ARGS_SAFE __attribute__ ((__format__ (__printf__, 1, 2))) 368 # define PRINTF2_ARGS_SAFE __attribute__ ((__format__ (__printf__, 2, 3))) 370 # define PRINTF3_ARGS_SAFE __attribute__ ((__format__ (__printf__, 3, 4))) 372 # define PRINTF4_ARGS_SAFE __attribute__ ((__format__ (__printf__, 4, 5))) 375 # define PRINTF1_ARGS_SAFE 376 # define PRINTF2_ARGS_SAFE 377 # define PRINTF3_ARGS_SAFE 378 # define PRINTF4_ARGS_SAFE 384 #if TOMOGRAPHER_PARSED_BY_DOXYGEN 393 # define TOMOGRAPHER_CXX_STACK_FORCE_REALIGN 394 #else // TOMOGRAPHER_PARSED_BY_DOXYGEN 396 #if defined(__GNUC__) || defined(__clang__) 397 # if defined(__MINGW32__) || defined(__MINGW64__) 398 # define TOMOGRAPHER_CXX_STACK_FORCE_REALIGN __attribute__((force_align_arg_pointer,noinline)) 400 # define TOMOGRAPHER_CXX_STACK_FORCE_REALIGN 404 # define TOMOGRAPHER_CXX_STACK_FORCE_REALIGN 406 # warning "You are using an unknown compiler. You may run into memory alignment problems... Good luck!" 407 # define TOMOGRAPHER_CXX_STACK_FORCE_REALIGN 410 #endif // TOMOGRAPHER_PARSED_BY_DOXYGEN 417 namespace tomo_internal {
418 template<
typename Enabledtype =
void>
struct sfinae_no {
typedef int no[1]; };
419 template<
typename EnabledType =
void>
struct sfinae_yes {
typedef int yes[2]; };
440 const int offset = max_width;
442 #if defined(__MINGW32__) || defined(__MINGW64__) 451 if (cols_s != NULL) {
473 #define TOMO_FUNCTION __PRETTY_FUNCTION__ 477 namespace tomo_internal {
479 struct extractFuncName_helper {
483 constexpr extracted(
std::size_t dp,
const conststr& s) : decl_pos(dp), extr(s) { }
485 static constexpr conststr alltofirstparen(
const conststr& s)
487 return s.substr(0, s.find(conststr(
"("), 0, s.size()));
491 return found_pos == std::string::npos ? 0 : found_pos + 1;
493 static constexpr
std::size_t pos_decl(
const conststr& s)
495 return ((s.size() > 2)
496 ? declpos_from_found_spc(s.rfind(conststr(
" "), std::string::npos))
499 static constexpr extracted allfromfirstspace(
const conststr& s)
501 return extracted(pos_decl(s),
502 s.substr_e(pos_decl(s),
505 static constexpr extracted do_extract(
const conststr& funcname)
507 return allfromfirstspace(alltofirstparen(funcname));
509 static constexpr conststr extract_choose(
const extracted& do_extracted,
510 const conststr& funcname)
512 return (do_extracted.extr.substr(0,8) == conststr(
"operator")
513 ? funcname.substr(do_extracted.decl_pos)
514 : do_extracted.extr);
516 static constexpr conststr extract(
const conststr& funcname)
518 return extract_choose(do_extract(funcname), funcname);
531 return tomo_internal::extractFuncName_helper::extract(funcname);
577 #define TOMOGRAPHER_DEFINE_MSG_EXCEPTION(ClassName, ErrPrefix) \ 578 TOMOGRAPHER_EXPORT class ClassName : public std::exception { \ 581 ClassName(std::string msg) : _msg(std::string(ErrPrefix) + std::move(msg)) { } \ 582 virtual ~ClassName() throw() { } \ 583 std::string msg() const { return _msg; } \ 584 const char * what() const throw() { return _msg.c_str(); } \ 595 #define TOMOGRAPHER_DEFINE_MSG_EXCEPTION_BASE(ClassName, ErrPrefix, BaseClass) \ 596 TOMOGRAPHER_EXPORT class ClassName : public BaseClass { \ 598 ClassName(std::string msg) : BaseClass(std::string(ErrPrefix) + std::move(msg)) { } \ 599 virtual ~ClassName() throw() { } \ 619 template<
typename ExceptionClass = std::runtime_error>
622 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.