27 #ifndef TOMOGRAPHER_TOOLS_FMT_H 28 #define TOMOGRAPHER_TOOLS_FMT_H 72 const char * what()
const throw() {
94 char * buffer =
new char[size];
97 int nsize =
vsnprintf(buffer, size, fmt, ap1);
106 buffer =
new char[size];
107 nsize =
vsnprintf(buffer, size, fmt, vl);
145 #define streamstr(tokens) \ 146 dynamic_cast<std::ostringstream&>( \ 147 std::ostringstream().seekp(0) << tokens \ 157 #define streamcstr(tokens) streamstr(tokens).c_str() 165 namespace tomo_internal {
168 template<
typename T>
static auto test_has_stream_op(
int)
169 ->
typename sfinae_yes<decltype(*((std::ostream*)(NULL)) << *((T*)(NULL)))>::yes&;
170 template<
typename T>
static auto test_has_stream_op(
long)
171 ->
typename sfinae_no<>::no&;
196 static constexpr
bool value = (
sizeof(tomo_internal::test_has_stream_op<T>(0))
197 ==
sizeof(
typename tomo_internal::sfinae_yes<>::yes));
201 namespace tomo_internal {
203 template<
typename T_>
204 struct StreamIfPossibleWrapper
211 StreamIfPossibleWrapper(
217 : obj(obj_), before(before_), after(after_), alternative(alternative_)
235 void stream_into(OStream&& stream)
const 237 stream << alternative;
241 void stream_into(OStream&& stream)
const 243 stream << before << obj << after;
248 std::ostream & operator<<(std::ostream & stream, const StreamIfPossibleWrapper<T>& wobj)
250 wobj.stream_into(stream);
255 std::ostream&& operator<<(std::ostream&& stream, const StreamIfPossibleWrapper<T>& wobj)
257 wobj.stream_into(stream);
264 #ifndef TOMOGRAPHER_PARSED_BY_DOXYGEN 277 inline tomo_internal::StreamIfPossibleWrapper<T>
282 return tomo_internal::StreamIfPossibleWrapper<T>(obj,
std::move(before),
370 double dt_f =
std::modf(seconds, &dt_i_d);
371 int dt_i = (int)(dt_i_d+0.5);
373 return fmts(
"%d:%02d:%02d.%03d", dt_i/3600, (dt_i/60)%60, dt_i%60, (
int)(dt_f*1000+0.5));
385 template<
typename Rep,
typename Period>
391 double seconds = (double)dt.
count() * Duration::period::num / Duration::period::den ;
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.