40 #if defined(TIMEMORY_PYBIND11_SOURCE)
41 # include "pybind11/cast.h"
42 # include "pybind11/pybind11.h"
43 # include "pybind11/stl.h"
52 #include <type_traits>
53 #include <unordered_map>
146 template <
typename InpT,
typename Tag>
163 template <
typename T,
typename U =
int>
164 using enable_if_acceptable_t =
167 template <
typename FuncT,
typename T,
typename U =
int>
168 using enable_if_acceptable_and_func_t =
170 std::is_function<FuncT>::value,
173 using value_ptr_t = std::shared_ptr<value_type>;
174 using secondary_map_t = std::unordered_map<std::string, this_type>;
175 using secondary_ptr_t = std::shared_ptr<secondary_map_t>;
221 return (m_secondary) ? *m_secondary : secondary_map_t{};
230 using base_type::get_value;
240 template <
typename T>
241 void store(T&& val, enable_if_acceptable_t<T, int> = 0);
244 template <
typename T>
249 template <
typename FuncT,
typename T>
250 auto store(FuncT&& f, T&& val, enable_if_acceptable_t<T, int> = 0)
251 -> decltype(std::declval<handler_type>().
store(*
this, std::forward<FuncT>(f),
252 std::forward<T>(val)),
258 template <
typename FuncT,
typename T>
259 auto store(
handler_type&&, FuncT&& f, T&& val, enable_if_acceptable_t<T, int> = 0)
260 -> decltype(std::declval<handler_type>().
store(*
this, std::forward<FuncT>(f),
261 std::forward<T>(val)),
273 template <
typename T>
274 void mark_begin(T&& val, enable_if_acceptable_t<T, int> = 0);
277 template <
typename T>
282 template <
typename FuncT,
typename T>
283 void mark_begin(FuncT&& f, T&& val, enable_if_acceptable_t<T, int> = 0);
288 template <
typename FuncT,
typename T>
290 enable_if_acceptable_t<T, int> = 0);
303 template <
typename T>
304 void mark_end(T&& val, enable_if_acceptable_t<T, int> = 0);
307 template <
typename T>
312 template <
typename FuncT,
typename T>
313 void mark_end(FuncT&& f, T&& val, enable_if_acceptable_t<T, int> = 0);
318 template <
typename FuncT,
typename T>
330 template <
typename T>
332 enable_if_acceptable_t<T, int> = 0);
335 template <
typename T>
337 enable_if_acceptable_t<T, int> = 0);
341 template <
typename FuncT,
typename T>
343 enable_if_acceptable_and_func_t<FuncT, T, int> = 0);
348 template <
typename FuncT,
typename T>
350 T&& val, enable_if_acceptable_and_func_t<FuncT, T, int> = 0);
364 using base_type::value;
370 auto get_secondary_map()
373 m_secondary = std::make_shared<secondary_map_t>();
377 void allocate_temporary()
const
380 const_cast<this_type*
>(
this)->m_last = std::make_shared<value_type>();
383 value_type& get_temporary() {
return (allocate_temporary(), *m_last); }
384 const value_type& get_temporary()
const {
return (allocate_temporary(), *m_last); }
387 value_ptr_t m_last{
nullptr };
388 secondary_ptr_t m_secondary{
nullptr };
393 template <
typename T>
418 template <
typename InpT,
typename Tag>
425 return TIMEMORY_JOIN(
"_",
typeid(Tag).name(),
typeid(InpT).name());
430 template <
typename InpT,
typename Tag>
442 meta_desc += meta_extra_desc;
446 std::stringstream ss;
447 ss <<
"Data tracker for data of type " << demangle<InpT>() <<
" for "
454 template <
typename InpT,
typename Tag>
455 template <
typename T>
460 if(!get_is_running())
464 template <
typename InpT,
typename Tag>
465 template <
typename T>
470 if(!get_is_running())
474 template <
typename InpT,
typename Tag>
475 template <
typename FuncT,
typename T>
478 -> decltype(std::declval<handler_type>().
store(*
this, std::forward<FuncT>(f),
479 std::forward<T>(val)),
484 if(!get_is_running())
488 template <
typename InpT,
typename Tag>
489 template <
typename FuncT,
typename T>
492 enable_if_acceptable_t<T, int>)
493 -> decltype(std::declval<handler_type>().
store(*
this, std::forward<FuncT>(f),
494 std::forward<T>(val)),
499 if(!get_is_running())
503 template <
typename InpT,
typename Tag>
504 template <
typename T>
508 handler_type::begin(get_temporary(),
512 template <
typename InpT,
typename Tag>
513 template <
typename T>
518 if(!get_is_running())
522 template <
typename InpT,
typename Tag>
523 template <
typename T>
526 enable_if_acceptable_t<T, int>)
528 handler_type::begin(get_temporary(),
532 template <
typename InpT,
typename Tag>
533 template <
typename T>
538 if(!get_is_running())
542 template <
typename InpT,
typename Tag>
543 template <
typename FuncT,
typename T>
547 handler_type::begin(get_temporary(), std::forward<FuncT>(f),
551 template <
typename InpT,
typename Tag>
552 template <
typename FuncT,
typename T>
556 handler_type::end(*
this, std::forward<FuncT>(f),
558 if(!get_is_running())
562 template <
typename InpT,
typename Tag>
563 template <
typename FuncT,
typename T>
566 enable_if_acceptable_t<T, int>)
568 handler_type::begin(get_temporary(), std::forward<FuncT>(f),
572 template <
typename InpT,
typename Tag>
573 template <
typename FuncT,
typename T>
576 enable_if_acceptable_t<T, int>)
578 handler_type::end(*
this, std::forward<FuncT>(f),
580 if(!get_is_running())
584 template <
typename InpT,
typename Tag>
585 template <
typename T>
588 enable_if_acceptable_t<T, int>)
592 _tmp.
store(std::forward<T>(val));
594 auto& _map = *get_secondary_map();
595 _map.insert({ _key, _tmp });
596 return &(_map[_key]);
599 template <
typename InpT,
typename Tag>
600 template <
typename T>
603 enable_if_acceptable_t<T, int>)
607 _tmp.
store(std::forward<handler_type>(h), std::forward<T>(val));
609 auto& _map = *get_secondary_map();
610 _map.insert({ _key, _tmp });
611 return &(_map[_key]);
614 template <
typename InpT,
typename Tag>
615 template <
typename FuncT,
typename T>
618 enable_if_acceptable_and_func_t<FuncT, T, int>)
622 _tmp.
store(std::forward<FuncT>(f), std::forward<T>(val));
624 auto& _map = *get_secondary_map();
625 _map.insert({ _key, _tmp });
626 return &(_map[_key]);
629 template <
typename InpT,
typename Tag>
630 template <
typename FuncT,
typename T>
634 enable_if_acceptable_and_func_t<FuncT, T, int>)
638 _tmp.
store(std::forward<handler_type>(h), std::forward<FuncT>(f),
639 std::forward<T>(val));
641 auto& _map = *get_secondary_map();
642 _map.insert({ _key, _tmp });
643 return &(_map[_key]);
typename T::handler_type data_handler_t
an alias for getting the handle_type of a data tracker
typename std::enable_if< B, T >::type enable_if_t
void store(TupleT< Tp... > &obj, Args &&... args)
Tp & divide(Tp &, const Up &)
tim::mpl::apply< std::string > string
The declaration for the types for settings without definitions.
auto get_iterator() const
bool get_depth_change() const
static int64_t get_unit()
bool get_is_on_stack() const
bool get_is_transient() const
bool get_is_running() const
This component is provided to facilitate data tracking. The first template parameter is the type of d...
auto get() const
get the data in the final form after unit conversion
static auto & get_unit()
this returns a reference so that it can be easily modified
this_type * add_secondary(const std::string &_key, T &&val, enable_if_acceptable_t< T, int >=0)
add a secondary value to the current node in the call-graph. When TIMEMORY_ADD_SECONDARY is enabled c...
void mark_begin(T &&val, enable_if_acceptable_t< T, int >=0)
The combination of mark_begin(...) and mark_end(...) can be used to store some initial data which may...
auto get_display() const
get the data in a form suitable for display
static std::string & label()
a reference is returned here so that it can be easily updated
void mark_end(T &&val, enable_if_acceptable_t< T, int >=0)
The combination of mark_begin(...) and mark_end(...) can be used to store some initial data which may...
this_type * add_secondary(const std::string &_key, handler_type &&h, T &&val, enable_if_acceptable_t< T, int >=0)
overload which takes a handler to ensure proper overload resolution
data::handler< InpT, Tag > handler_type
this_type * add_secondary(const std::string &_key, handler_type &&h, FuncT &&f, T &&val, enable_if_acceptable_and_func_t< FuncT, T, int >=0)
overload which uses a lambda to bypass the default behavior of how the handler updates the values and...
static std::string & description()
a reference is returned here so that it can be easily updated
void set_value(const value_type &v)
set the current value
this_type * add_secondary(const std::string &_key, FuncT &&f, T &&val, enable_if_acceptable_and_func_t< FuncT, T, int >=0)
overload which uses a lambda to bypass the default behavior of how the handler updates the values
auto get_secondary() const
map of the secondary entries. When TIMEMORY_ADD_SECONDARY is enabled contents of this map will be add...
data_tracker< InpT, Tag > this_type
void store(T &&val, enable_if_acceptable_t< T, int >=0)
store some data. Uses tim::data::handler for the type.
void set_value(value_type &&v)
set the current value via move
static decltype(auto) get_display(const T &obj)
this function is returns the current value in a form suitable for display. It may be necessary to spe...
static decltype(auto) get(const T &obj)
this function is returns the current value
Struct for performing math operations on complex data structures without using globally overload oper...
This operation class is similar to pointer_operator but can handle non-pointer types.
This operation attempts to call a member function which the component provides to internally store wh...
This operation attempts to call a member function which the component provides to internally store wh...
#define TIMEMORY_JOIN(delim,...)