40#if defined(TIMEMORY_PYBIND11_SOURCE)
41# include "pybind11/cast.h"
42# include "pybind11/pybind11.h"
43# include "pybind11/stl.h"
53#include <unordered_map>
146template <
typename InpT,
typename Tag>
162 template <
typename LhsT,
typename RhsT,
typename HashT = std::hash<LhsT>>
174 template <
typename... Args>
179 template <
typename... Args>
180 std::pair<iterator, bool>
emplace(Args&&... args)
182 return { base_type::emplace(
base_type::end(), std::forward<Args>(args)...),
189 for(
auto itr = base_type::begin(); itr !=
base_type::end(); ++itr)
200 for(
auto itr = base_type::begin(); itr !=
base_type::end(); ++itr)
213 template <
typename T,
typename U =
int>
214 using enable_if_acceptable_t =
217 using value_ptr_t = std::shared_ptr<value_type>;
218 using secondary_map_t = vector_map<std::string, this_type>;
219 using secondary_ptr_t = std::shared_ptr<secondary_map_t>;
271 using base_type::get_value;
281 template <
typename T>
282 void store(T&& val, enable_if_acceptable_t<T, int> = 0);
285 template <
typename T>
290 template <
typename FuncT,
typename T>
291 auto store(FuncT&& f, T&& val, enable_if_acceptable_t<T, int> = 0)
292 ->
decltype(std::declval<handler_type>().store(*
this, std::forward<FuncT>(f),
293 std::forward<T>(val)),
299 template <
typename FuncT,
typename T>
300 auto store(
handler_type&&, FuncT&& f, T&& val, enable_if_acceptable_t<T, int> = 0)
301 ->
decltype(std::declval<handler_type>().store(*
this, std::forward<FuncT>(f),
302 std::forward<T>(val)),
314 template <
typename T>
315 void mark_begin(T&& val, enable_if_acceptable_t<T, int> = 0);
318 template <
typename T>
323 template <
typename FuncT,
typename T>
324 void mark_begin(FuncT&& f, T&& val, enable_if_acceptable_t<T, int> = 0);
329 template <
typename FuncT,
typename T>
331 enable_if_acceptable_t<T, int> = 0);
344 template <
typename T>
345 void mark_end(T&& val, enable_if_acceptable_t<T, int> = 0);
348 template <
typename T>
353 template <
typename FuncT,
typename T>
354 void mark_end(FuncT&& f, T&& val, enable_if_acceptable_t<T, int> = 0);
359 template <
typename FuncT,
typename T>
371 template <
typename T>
373 enable_if_acceptable_t<T, int> = 0);
376 template <
typename T>
378 enable_if_acceptable_t<T, int> = 0);
382 template <
typename FuncT,
typename T>
384 enable_if_acceptable_t<T, int> = 0);
389 template <
typename FuncT,
typename T>
391 T&& val, enable_if_acceptable_t<T, int> = 0);
405 using base_type::value;
415 auto get_secondary_map()
418 m_secondary = std::make_shared<secondary_map_t>();
422 void allocate_temporary()
const
425 m_last = std::make_shared<value_type>();
428 value_type& get_temporary() {
return (allocate_temporary(), *m_last); }
429 const value_type& get_temporary()
const {
return (allocate_temporary(), *m_last); }
432 mutable value_ptr_t m_last{
nullptr };
433 secondary_ptr_t m_secondary{
nullptr };
464template <
typename InpT,
typename Tag>
471 return TIMEMORY_JOIN(
"_",
typeid(Tag).name(),
typeid(InpT).name());
476template <
typename InpT,
typename Tag>
488 meta_desc += meta_extra_desc;
492 std::stringstream ss;
493 ss <<
"Data tracker for data of type " << demangle<InpT>() <<
" for "
500template <
typename InpT,
typename Tag>
507 if(!get_is_running())
511template <
typename InpT,
typename Tag>
518 if(!get_is_running())
522template <
typename InpT,
typename Tag>
523template <
typename FuncT,
typename T>
526 ->
decltype(std::declval<handler_type>().store(*
this, std::forward<FuncT>(f),
527 std::forward<T>(val)),
532 if(!get_is_running())
536template <
typename InpT,
typename Tag>
537template <
typename FuncT,
typename T>
540 enable_if_acceptable_t<T, int>)
541 ->
decltype(std::declval<handler_type>().store(*
this, std::forward<FuncT>(f),
542 std::forward<T>(val)),
547 if(!get_is_running())
551template <
typename InpT,
typename Tag>
556 handler_type::begin(get_temporary(),
560template <
typename InpT,
typename Tag>
566 if(!get_is_running())
570template <
typename InpT,
typename Tag>
574 enable_if_acceptable_t<T, int>)
576 handler_type::begin(get_temporary(),
580template <
typename InpT,
typename Tag>
586 if(!get_is_running())
590template <
typename InpT,
typename Tag>
591template <
typename FuncT,
typename T>
595 handler_type::begin(get_temporary(), std::forward<FuncT>(f),
599template <
typename InpT,
typename Tag>
600template <
typename FuncT,
typename T>
606 if(!get_is_running())
610template <
typename InpT,
typename Tag>
611template <
typename FuncT,
typename T>
614 enable_if_acceptable_t<T, int>)
616 handler_type::begin(get_temporary(), std::forward<FuncT>(f),
620template <
typename InpT,
typename Tag>
621template <
typename FuncT,
typename T>
624 enable_if_acceptable_t<T, int>)
628 if(!get_is_running())
632template <
typename InpT,
typename Tag>
636 enable_if_acceptable_t<T, int>)
641 _tmp.store(std::forward<T>(val));
644 auto& _map = *get_secondary_map();
645 _map.emplace(_key, std::move(_tmp));
646 return &(_map[_key]);
649template <
typename InpT,
typename Tag>
653 enable_if_acceptable_t<T, int>)
658 _tmp.store(std::forward<handler_type>(h), std::forward<T>(val));
661 auto& _map = *get_secondary_map();
664 _map.emplace(_key, std::move(_tmp));
665 return &(_map[_key]);
668template <
typename InpT,
typename Tag>
669template <
typename FuncT,
typename T>
672 enable_if_acceptable_t<T, int>)
677 _tmp.store(std::forward<FuncT>(f), std::forward<T>(val));
680 auto& _map = *get_secondary_map();
683 _map.emplace(_key, std::move(_tmp));
684 return &(_map[_key]);
687template <
typename InpT,
typename Tag>
688template <
typename FuncT,
typename T>
691 FuncT&& f, T&& val, enable_if_acceptable_t<T, int>)
696 _tmp.store(std::forward<handler_type>(h), std::forward<FuncT>(f),
697 std::forward<T>(val));
700 auto& _map = *get_secondary_map();
703 _map.emplace(_key, std::move(_tmp));
704 return &(_map[_key]);
typename base_type::const_iterator const_iterator
std::pair< iterator, bool > emplace(Args &&... args)
typename base_type::iterator iterator
iterator find(const key_type &_key)
vector_map(Args &&... args)
std::vector< value_type > base_type
std::pair< LhsT, RhsT > value_type
mapped_type & operator[](const key_type &_key)
const_iterator find(const key_type &_key) const
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)
auto divide(Tp &_lhs, Up _rhs, type_list<>,...) -> decltype(_lhs/=_rhs, void())
tim::mpl::apply< std::string > string
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
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, FuncT &&f, T &&val, enable_if_acceptable_t< T, int >=0)
overload which uses a lambda to bypass the default behavior of how the handler updates the values and...
data::handler< InpT, Tag > handler_type
static std::string & description()
a reference is returned here so that it can be easily updated
static auto & get_unit()
this returns a reference so that it can be easily modified
void set_last(value_type &&_v)
value_type get_last() const
void set_value(const value_type &v)
set the current value
auto get_secondary() const
map of the secondary entries. When TIMEMORY_ADD_SECONDARY is enabled contents of this map will be add...
void store(T &&val, enable_if_acceptable_t< T, int >=0)
store some data. Uses tim::data::handler for the type.
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
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 set_value(value_type &&v)
set the current value via move
void set_last(value_type &_v)
this_type * add_secondary(const std::string &_key, FuncT &&f, T &&val, enable_if_acceptable_t< T, int >=0)
overload which uses a lambda to bypass the default behavior of how the handler updates the values
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,...)