28 #ifndef TOMOGRAPHER_TOOLS_UTILS_H 29 #define TOMOGRAPHER_TOOLS_UTILS_H 43 #include <type_traits> 52 #include <boost/version.hpp> 53 #if BOOST_VERSION >= 105600 54 #include <boost/core/demangle.hpp> 56 #include <boost/units/detail/utility.hpp> 57 namespace boost {
namespace core {
using boost::units::detail::demangle; } }
72 namespace tomo_internal {
75 FinalAction(F f) : clean_(f) {}
76 ~FinalAction() { clean_(); }
93 inline tomo_internal::FinalAction<F>
finally(F f)
95 return tomo_internal::FinalAction<F>(f);
108 template<
typename T,
typename S1,
typename S2>
struct Concatenate;
110 template<
typename T, T... I1, T... I2>
112 :
Sequence<T, I1..., (sizeof...(I1)+I2)...> {};
114 template<
typename T, T N,
typename dummy =
void>
117 template<
typename T, T N,
typename >
119 typename GenerateSequence<T, N - N/2>::type>::type {};
121 template<
typename T, T N>
125 template<
typename T, T N>
151 template<
typename T_,
bool IsDynamic_, T_ StaticValue_ = T_()>
162 static constexpr
bool IsDynamic = IsDynamic_;
164 static constexpr T StaticValue = StaticValue_;
182 inline T
value()
const {
return StaticValue; }
191 template<
typename T_,
bool IsDynamic_, T_ StaticValue_>
193 template<
typename T_,
bool IsDynamic_, T_ StaticValue_>
200 template<
typename T_, T_ StaticValue_>
208 static constexpr
bool IsDynamic =
true;
221 inline T
value()
const {
return _dyn_value; }
232 template<
typename T_, T_ StaticValue_>
248 template<
typename T_,
bool enabled>
254 static constexpr
bool IsEnabled =
false;
257 template<
typename... Args>
261 template<
typename T_,
bool enabled>
267 template<
typename T_>
273 static constexpr
bool IsEnabled =
true;
279 template<
typename... ArgTypes>
283 template<
typename T_>
294 inline std::ostream & operator<<(std::ostream & str, const StoreIfEnabled<T, false>& )
307 inline std::ostream & operator<<(std::ostream & str, const StoreIfEnabled<T, true>& val)
320 template<
typename IntType =
int>
324 return N && !(N & (N - 1));
339 template<
typename Scalar>
345 template<
typename RealScalar>
348 typedef RealScalar type;
394 template<
typename IntType>
400 (b < 0 && a < std::numeric_limits<IntType>::min() - b) ;
408 template<
typename IntType,
typename ... IntTypes>
452 template<
typename IntType>
482 #if defined(__GNUC__) || defined(__clang__) || defined(TOMOGRAPHER_PARSED_BY_DOXGEN) 502 # define PRINTF1_ARGS_SAFE __attribute__ ((__format__ (__printf__, 1, 2))) 503 # define PRINTF2_ARGS_SAFE __attribute__ ((__format__ (__printf__, 2, 3))) 505 # define PRINTF3_ARGS_SAFE __attribute__ ((__format__ (__printf__, 3, 4))) 507 # define PRINTF4_ARGS_SAFE __attribute__ ((__format__ (__printf__, 4, 5))) 510 # define PRINTF1_ARGS_SAFE 511 # define PRINTF2_ARGS_SAFE 512 # define PRINTF3_ARGS_SAFE 513 # define PRINTF4_ARGS_SAFE 519 #if TOMOGRAPHER_PARSED_BY_DOXYGEN 528 # define TOMOGRAPHER_CXX_STACK_FORCE_REALIGN 529 #else // TOMOGRAPHER_PARSED_BY_DOXYGEN 531 #if defined(__GNUC__) || defined(__clang__) 532 # if defined(__MINGW32__) || defined(__MINGW64__) 533 # define TOMOGRAPHER_CXX_STACK_FORCE_REALIGN __attribute__((force_align_arg_pointer,noinline)) 535 # define TOMOGRAPHER_CXX_STACK_FORCE_REALIGN 539 # define TOMOGRAPHER_CXX_STACK_FORCE_REALIGN 541 # warning "You are using an unknown compiler. You may run into memory alignment problems... Good luck!" 542 # define TOMOGRAPHER_CXX_STACK_FORCE_REALIGN 545 #endif // TOMOGRAPHER_PARSED_BY_DOXYGEN 552 namespace tomo_internal {
553 template<
typename Enabledtype =
void>
struct sfinae_no {
typedef int no[1]; };
554 template<
typename EnabledType =
void>
struct sfinae_yes {
typedef int yes[2]; };
575 const int offset = max_width;
577 #if defined(__MINGW32__) || defined(__MINGW64__) 586 if (cols_s != NULL) {
608 #define TOMO_FUNCTION __PRETTY_FUNCTION__ 612 namespace tomo_internal {
614 struct extractFuncName_helper {
618 constexpr extracted(
std::size_t dp,
const conststr& s) : decl_pos(dp), extr(s) { }
620 static constexpr conststr alltofirstparen(
const conststr& s)
622 return s.substr(0, s.find(conststr(
"("), 0, s.size()));
626 return found_pos == std::string::npos ? 0 : found_pos + 1;
628 static constexpr
std::size_t pos_decl(
const conststr& s)
630 return ((s.size() > 2)
631 ? declpos_from_found_spc(s.rfind(conststr(
" "), std::string::npos))
634 static constexpr extracted allfromfirstspace(
const conststr& s)
636 return extracted(pos_decl(s),
637 s.substr_e(pos_decl(s),
640 static constexpr extracted do_extract(
const conststr& funcname)
642 return allfromfirstspace(alltofirstparen(funcname));
644 static constexpr conststr extract_choose(
const extracted& do_extracted,
645 const conststr& funcname)
647 return (do_extracted.extr.substr(0,8) == conststr(
"operator")
648 ? funcname.substr(do_extracted.decl_pos)
649 : do_extracted.extr);
651 static constexpr conststr extract(
const conststr& funcname)
653 return extract_choose(do_extract(funcname), funcname);
666 return tomo_internal::extractFuncName_helper::extract(funcname);
712 #define TOMOGRAPHER_DEFINE_MSG_EXCEPTION(ClassName, ErrPrefix) \ 713 class TOMOGRAPHER_EXPORT ClassName : public std::exception { \ 716 ClassName(std::string msg) : _msg(std::string(ErrPrefix) + std::move(msg)) { } \ 717 virtual ~ClassName() throw() { } \ 718 std::string msg() const { return _msg; } \ 719 const char * what() const throw() { return _msg.c_str(); } \ 730 #define TOMOGRAPHER_DEFINE_MSG_EXCEPTION_BASE(ClassName, ErrPrefix, BaseClass) \ 731 class TOMOGRAPHER_EXPORT ClassName : public BaseClass { \ 733 ClassName(std::string msg) : BaseClass(std::string(ErrPrefix) + std::move(msg)) { } \ 734 virtual ~ClassName() throw() { } \ 754 template<
typename ExceptionClass = std::runtime_error>
757 throw ExceptionClass(message);
776 namespace serialization {
778 template<
typename Archive,
typename... TupleArgs>
780 template<
int I, TOMOGRAPHER_ENABLED_IF_TMPL(I <
sizeof...(TupleArgs))>
783 a & std::get<I>(tuple);
784 go<I+1>(a, tuple, version);
786 template<
int I, TOMOGRAPHER_ENABLED_IF_TMPL(I >=
sizeof...(TupleArgs))>
792 template<
typename Archive,
typename... TupleArgs>
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.