28 #ifndef TOMOGRAPHER_TOOLS_FMT_H 29 #define TOMOGRAPHER_TOOLS_FMT_H 73 const char * what()
const throw() {
95 char * buffer =
new char[size];
98 int nsize =
vsnprintf(buffer, size, fmt, ap1);
107 buffer =
new char[size];
108 nsize =
vsnprintf(buffer, size, fmt, vl);
146 #define streamstr(tokens) \ 147 dynamic_cast<std::ostringstream&>( \ 148 std::ostringstream().seekp(0) << tokens \ 158 #define streamcstr(tokens) streamstr(tokens).c_str() 166 namespace tomo_internal {
169 template<
typename T>
static auto test_has_stream_op(
int)
170 ->
typename sfinae_yes<decltype(*((std::ostream*)(NULL)) << *((T*)(NULL)))>::yes&;
171 template<
typename T>
static auto test_has_stream_op(
long)
172 ->
typename sfinae_no<>::no&;
197 static constexpr
bool value = (
sizeof(tomo_internal::test_has_stream_op<T>(0))
198 ==
sizeof(
typename tomo_internal::sfinae_yes<>::yes));
202 namespace tomo_internal {
204 template<
typename T_>
205 struct StreamIfPossibleWrapper
212 StreamIfPossibleWrapper(
218 : obj(obj_), before(before_), after(after_), alternative(alternative_)
236 void stream_into(OStream&& stream)
const 238 stream << alternative;
242 void stream_into(OStream&& stream)
const 244 stream << before << obj << after;
249 std::ostream & operator<<(std::ostream & stream, const StreamIfPossibleWrapper<T>& wobj)
251 wobj.stream_into(stream);
256 std::ostream&& operator<<(std::ostream&& stream, const StreamIfPossibleWrapper<T>& wobj)
258 wobj.stream_into(stream);
265 #ifndef TOMOGRAPHER_PARSED_BY_DOXYGEN 278 inline tomo_internal::StreamIfPossibleWrapper<T>
283 return tomo_internal::StreamIfPossibleWrapper<T>(obj,
std::move(before),
371 double dt_f =
std::modf(seconds, &dt_i_d);
372 int dt_i = (int)(dt_i_d+0.5);
374 return fmts(
"%d:%02d:%02d.%03d", dt_i/3600, (dt_i/60)%60, dt_i%60, (
int)(dt_f*1000+0.5));
386 template<
typename Rep,
typename Period>
392 double seconds = (double)dt.
count() * Duration::period::num / Duration::period::den ;
420 inline int columns()
const {
return _columns; }
430 if ((
int)x.
size() > columns()) {
433 const int r = columns() - (int)x.
size();
434 const int rleft = r/2;
435 const int rright = r - rleft;
447 if ((
int)x.
size() > columns()) {
450 const int r = columns() - (int)x.
size();
462 if ((
int)x.
size() > columns()) {
465 const int r = columns() - (int)x.
size();
Base namespace for the Tomographer project.
Some C++ utilities, with a tad of C++11 tricks.
VarValueDecoder< T >::RetType value(const Var &var)
Access the value of the given variable, as a C++ type.