50 template <
typename...>
110 template <
typename Tag,
typename BundleT,
typename TupleT>
114 template <
typename U>
115 using remove_pointer_decay_t = std::remove_pointer_t<decay_t<U>>;
117 template <
typename... Tp>
118 friend class impl::base_bundle;
120 template <
typename... Tp>
123 template <
typename... Tp>
126 template <
typename... Tp>
129 template <
typename... Tp>
132 #if defined(TIMEMORY_USE_DEPRECATED)
133 template <
typename TupleC,
typename ListC>
136 template <
typename TupleC,
typename ListC>
140 using internal_tag = tim::variadic::impl::internal_tag;
163 template <
typename T,
typename... U>
167 template <
typename U>
170 return std::is_same<decay_t<U>,
this_type>::value;
176 template <
typename... T>
178 transient_func_t = get_initializer());
180 template <
typename... T>
182 transient_func_t = get_initializer());
184 template <
typename... T>
186 transient_func_t = get_initializer());
188 template <
typename... T>
190 transient_func_t = get_initializer());
192 template <
typename... T>
194 transient_func_t = get_initializer());
198 transient_func_t = get_initializer());
202 transient_func_t = get_initializer());
204 explicit bundle(
const captured_location_t& _loc,
bool _store =
true,
206 transient_func_t = get_initializer());
209 transient_func_t = get_initializer());
212 transient_func_t = get_initializer());
215 transient_func_t = get_initializer());
232 invoke::invoke<operation::minus, Tag>(m_data, std::forward<Op>(rhs));
233 return get_this_type();
236 template <typename Op, enable_if_t<!is_this_type<Op>()> = 0>
239 invoke::invoke<operation::plus, Tag>(m_data, std::forward<Op>(rhs));
240 return get_this_type();
243 template <typename Op, enable_if_t<!is_this_type<Op>()> = 0>
246 invoke::invoke<operation::multiply, Tag>(m_data, std::forward<Op>(rhs));
247 return get_this_type();
250 template <typename Op, enable_if_t<!is_this_type<Op>()> = 0>
253 invoke::invoke<operation::divide, Tag>(m_data, std::forward<Op>(rhs));
254 return get_this_type();
268 template <
typename Op>
271 return this_type{ lhs } *= std::forward<Op>(rhs);
274 template <
typename Op>
277 return this_type{ lhs } /= std::forward<Op>(rhs);
282 obj.print<
true,
true>(os);
295 template <
typename U>
298 using T = remove_pointer_decay_t<U>;
303 template <
typename U>
306 using T = remove_pointer_decay_t<U>;
313 template <
typename U>
320 template <
typename U>
323 using T = remove_pointer_decay_t<U>;
324 return can_stack_init<T>() || can_heap_init<T>() || can_placement_init<T>() ||
331 template <
typename U>
334 using T = remove_pointer_decay_t<U>;
335 return can_init<T>() && !can_stack_init<T>();
342 template <
typename U>
345 using T = remove_pointer_decay_t<U>;
346 return !can_stack_init<T>() && !can_heap_init<T>() &&
354 template <
typename U,
typename... Args,
typename T = remove_pointer_decay_t<U>,
358 return std::is_constructible<T, Args...>::value;
362 template <
typename U,
typename... Args,
typename T = remove_pointer_decay_t<U>,
373 template <
typename U,
typename T = remove_po
inter_decay_t<U>,
374 enable_if_t<trait::is_available<T>::value> = 0>
377 return std::is_default_constructible<T>::value;
381 template <
typename U,
typename T = remove_po
inter_decay_t<U>,
382 enable_if_t<!trait::is_available<T>::value> = 0>
390 static void init_storage();
399 template <
typename... Tp>
403 template <
typename... Tp>
407 template <
typename... Tp>
411 template <
typename... Args>
415 template <
typename... Args>
419 template <
typename... Args>
423 template <
typename... Args>
427 template <
typename... Args>
431 template <
typename... Args>
435 template <
typename... Args>
439 template <
typename... Args>
443 template <
typename... Tp,
typename... Args>
447 template <
typename... Tp,
typename... Args>
450 using bundle_type::get_prefix;
451 using bundle_type::get_scope;
452 using bundle_type::get_store;
453 using bundle_type::hash;
454 using bundle_type::key;
455 using bundle_type::laps;
456 using bundle_type::prefix;
457 using bundle_type::size;
461 static constexpr uint64_t fixed_count();
464 static constexpr uint64_t optional_count();
471 template <
typename FuncT,
typename... Args>
472 decltype(
auto)
execute(FuncT&& func, Args&&... args);
530 template <
bool PrintPrefix = true,
bool PrintLaps = true>
535 auto
get(Args&&...) const;
553 decltype(auto)
get() const;
589 enable_if_t<trait::is_available<remove_pointer_decay_t<U>>::value &&
595 enable_if_t<trait::is_available<remove_pointer_decay_t<U>>::value &&
602 enable_if_t<trait::is_available<remove_pointer_decay_t<U>>::value &&
609 enable_if_t<trait::is_available<remove_pointer_decay_t<U>>::value &&
617 Args&&... _args,
enable_if_t<is_constructible<T, Args...>(),
int> = 0)
619 T*& _obj = std::get<index_of<T*, data_type>::value>(m_data);
624 printf(
"[bundle::init]> initializing type '%s'...\n",
625 demangle<T>().c_str());
627 _obj =
new T(std::forward<Args>(_args)...);
633 static std::atomic<int> _count(0);
638 "[bundle::init]> skipping re-initialization of type"
648 template <
typename U,
typename T = remove_po
inter_decay_t<U>,
typename... Args>
651 enable_if_t<!is_constructible<T, Args...>() && is_default_constructible<T>(),
654 T*& _obj = std::get<index_of<T*, data_type>::value>(m_data);
659 fprintf(stderr,
"[bundle::init]> initializing type '%s'...\n",
660 demangle<T>().c_str());
668 static std::atomic<int> _count(0);
672 "[bundle::init]> skipping re-initialization of type "
674 demangle<T>().c_str());
681 template <
typename U,
typename T = remove_po
inter_decay_t<U>,
typename... Args>
686 static std::atomic<int> _count(0);
690 "[bundle::init]> type exists as a heap-allocated instance "
691 "and stack-allocated instance: \"%s\"...\n",
692 demangle<T>().c_str());
695 T& _obj = std::get<index_of<T, data_type>::value>(m_data);
704 template <
typename U,
typename T = remove_po
inter_decay_t<U>,
typename... Args>
707 using bundle_t =
decay_t<decltype(
708 std::get<0>(std::declval<typename bundle_type::user_bundle_types>()))>;
710 this->init<bundle_t>();
711 auto* _bundle = this->get<bundle_t>();
714 _bundle->insert(component::factory::get_opaque<T>(m_scope),
715 component::factory::get_typeids<T>());
723 template <
typename U,
typename T = remove_po
inter_decay_t<U>,
typename... Args>
726 bundle_type::has_user_bundle_v),
736 template <
typename... T,
typename... Args>
737 std::array<bool,
sizeof...(T)>
initialize(Args&&... args);
740 template <
typename... Tail>
744 template <
typename T,
typename Func,
typename... Args,
748 auto* _obj = get<T>();
749 ((*_obj).*(_func))(std::forward<Args>(_args)...);
750 return get_this_type();
754 template <
typename T,
typename Func,
typename... Args,
759 template <
typename T,
typename Func,
typename... Args,
768 TIMEMORY_INLINE
void rekey(
const string_t& _key);
770 TIMEMORY_INLINE
void rekey(uint64_t _hash);
782 template <
typename T>
783 void set_scope(T* obj, internal_tag)
const;
785 template <
typename T>
790 using bundle_type::m_config;
791 using bundle_type::m_enabled;
792 using bundle_type::m_hash;
793 using bundle_type::m_is_active;
794 using bundle_type::m_is_pushed;
795 using bundle_type::m_laps;
796 using bundle_type::m_scope;
797 using bundle_type::m_store;
801 this_type& get_this_type() {
return static_cast<this_type&
>(*this); }
802 this_type& get_this_type()
const
804 return const_cast<this_type&
>(
static_cast<const this_type&
>(*this));
807 static this_type*& get_last_instance()
809 static thread_local this_type* _instance =
nullptr;
813 static void update_last_instance(this_type* _new_instance,
814 this_type*& _old_instance = get_last_instance(),
815 bool _stop_last =
false)
817 if(_stop_last && _old_instance && _old_instance != _new_instance)
818 _old_instance->stop();
819 _old_instance = _new_instance;
824 template <
typename Archive>
825 void serialize(Archive& ar,
const unsigned int);
830 template <
typename Tag,
typename BundleT,
typename TupleT>
841 template <
typename Tag,
typename BundleT,
typename TupleT>
851 template <
typename Tag,
typename BundleT,
typename TupleT>
852 template <
typename FuncT,
typename... Args>
854 bundle<Tag, BundleT, TupleT>::
execute(FuncT&& func, Args&&... args)
857 std::forward<FuncT>(func)(std::forward<Args>(args)...));
862 template <
typename Tag,
typename BundleT,
typename TupleT>
863 template <
typename U>
865 bundle<Tag, BundleT, TupleT>::
get()
867 return tim::variadic::impl::get<U, Tag>(m_data);
872 template <
typename Tag,
typename BundleT,
typename TupleT>
873 template <
typename U>
875 bundle<Tag, BundleT, TupleT>::
get()
const
877 return tim::variadic::impl::get<U, Tag>(m_data);
882 template <
typename Tag,
typename BundleT,
typename TupleT>
883 template <
typename U>
890 return get<remove_pointer_decay_t<U>>();
895 template <
typename Tag,
typename BundleT,
typename TupleT>
896 template <
typename U>
903 return get<remove_pointer_decay_t<U>>();
908 template <
typename Tag,
typename BundleT,
typename TupleT>
909 template <
typename U>
916 return std::get<index_of<remove_pointer_decay_t<U>,
data_type>::value>(m_data);
921 template <
typename Tag,
typename BundleT,
typename TupleT>
922 template <
typename U>
929 return std::get<index_of<remove_pointer_decay_t<U>*,
data_type>::value>(m_data);
934 template <
typename Tag,
typename BundleT,
typename TupleT>
944 template <
typename Tag,
typename BundleT,
typename TupleT>
954 template <
typename Tag,
typename BundleT,
typename TupleT>
This is a variadic component wrapper where all components are optional at runtime....
This is a variadic component wrapper where all components are allocated on the stack and cannot be di...
Example: bundle<Tag, component_bundle<Foo>, mixed_wrapper_types<concat<Bar, Baz>>> will use Tag + tra...
static constexpr bool is_default_constructible()
Query at compile-time whether type supports default construction. If type is not available,...
typename TupleT::template data_type< Tag > data_type
bool init(Args &&... _args, enable_if_t< can_stack_init< T >(), int >=0)
try to re-create a stack object with provided arguments
typename TupleT::template component_type< BundleT > component_type
this_type & type_apply(Func &&, Args &&...)
ignore applying a member function because the type is not present
typename TupleT::type_list_type type_list_type
enable_if_t<!trait::is_available< T >::value||!(is_one_of< T *, data_type >::value||is_one_of< T, data_type >::value||bundle_type::has_user_bundle_v), bool > init(Args &&...)
do nothing if type not available, not one of the variadic types, and there is no user bundle availabl...
const data_type & get_data() const
this_type & operator+=(Op &&rhs)
typename TupleT::template type< BundleT > type
tim::variadic::impl::quirk_config< T, reference_type, U... > quirk_config
typename bundle_type::size_type size_type
static constexpr bool can_stack_init()
Query at compile-time whether initialization can occur on the stack.
static constexpr bool will_heap_init()
Query at compile-time whether initialization will occur on the heap. can_heap_init<T>() && !...
this_type & operator*=(Op &&rhs)
this_type & type_apply(Func &&_func, Args &&... _args)
apply a member function to a stack type that is in variadic list AND is available
this_type & stop(mpl::piecewise_select< Tp... >, Args &&...)
variant of stop() which only gets applied to Tp types
static constexpr bool will_opaque_init()
Query at compile-time whether initialization will happen with an opaque wrapper (i....
this_type & disable()
delete any optional types currently allocated
this_type & start(Args &&...)
invokes start on all the components
this_type & operator/=(Op &&rhs)
friend std::ostream & operator<<(std::ostream &os, const bundle &obj)
this_type & pop(mpl::piecewise_select< Tp... >)
selective pop
bool init(Args &&..., enable_if_t< will_opaque_init< T >(), long >=0)
if a type is not in variadic list but a tim::component::user_bundle is available, add it in there
static constexpr bool has_user_bundle()
Query at compile-time whether a user_bundle exists in the set of components. user_bundle are more res...
friend this_type operator/(const this_type &lhs, Op &&rhs)
enable_if_t< will_heap_init< T >) &&!will_opaque_init< T >), bool > init(Args &&..., enable_if_t<!is_constructible< T, Args... >() &&is_default_constructible< T >(), long >=0)
create an optional type that is in variadic list AND is available but is not constructible with provi...
this_type & push(mpl::piecewise_select< Tp... >)
selective push
this_type & record(Args &&...)
requests each component perform a measurement
bundle(bundle &&) noexcept=default
typename bundle_type::string_t string_t
friend this_type operator*(const this_type &lhs, Op &&rhs)
typename TupleT::template this_type< BundleT > this_type
typename TupleT::reference_type reference_type
this_type & reset(Args &&...)
invokes reset member function on all the components
this_type & start(mpl::lightweight, Args &&...)
variant of start() which excludes push()
static constexpr bool is_this_type()
Query whether type matches this_type.
this_type & push(mpl::piecewise_select< Tp... >, scope::config)
selective push with scope configuration
this_type & stop(mpl::lightweight, Args &&...)
variant of stop() which excludes pop()
static constexpr bool can_heap_init()
Query at compile-time whether initialization can occur on the heap.
static constexpr bool is_constructible()
Query at compile-time whether type can be constructed with the given argument types....
this_type & start(mpl::piecewise_select< Tp... >, Args &&...)
variant of start() which only gets applied to Tp types
static constexpr bool can_init()
Query at compile-time whether the specified type can be initialized.
friend this_type operator-(const this_type &lhs, const this_type &rhs)
this_type & measure(Args &&...)
requests each component record a measurment
friend this_type operator+(const this_type &lhs, const this_type &rhs)
static constexpr bool can_placement_init()
Query at compile-time whether initialization can occur via a placement new. Placement new init allows...
this_type & stop(Args &&...)
invokes stop on all the components
std::function< void(this_type &)> initializer_type
this_type & sample(Args &&...)
requests each component take a sample (if supported)
#define IF_CONSTEXPR(...)
std::shared_ptr< DataType > execute(std::shared_ptr< DataType > _data=std::make_shared< DataType >())
void serialize(std::string fname, exec_data< Counter > &obj)
void set_scope(TupleT< Tp... > &obj, Args &&... args)
void assemble(TupleT< Tp... > &obj, Args &&... args)
void mark_begin(TupleT< Tp... > &obj, Args &&... args)
void set_prefix(TupleT< Tp... > &obj, Args &&... args)
void audit(TupleT< Tp... > &obj, Args &&... args)
void store(TupleT< Tp... > &obj, Args &&... args)
void derive(TupleT< Tp... > &obj, Args &&... args)
void pop(TupleT< Tp... > &obj, Args &&... args)
void push(TupleT< Tp... > &obj, Args &&... args)
void mark_end(TupleT< Tp... > &obj, Args &&... args)
void mark(TupleT< Tp... > &obj, Args &&... args)
void print(std::ostream &os, Args &&... args)
impl::filter_false< Predicate, std::tuple< Sequence... > > type
auto execute(BundleT &&_bundle, FuncT &&_func, Args &&... _args, enable_if_t< is_invocable< FuncT, Args... >::value &&!std::is_void< std::result_of_t< FuncT(Args...)>>::value, int >)
a generic type for indicating that function call or constructor should be as lightweight as possible.
Ret invoke(string_view_t &&label, Func &&func, Args &&... args)
std::bitset< scope_count > data_type
A light-weight alternative to std::function. Pass any callback - including capturing lambdas - cheapl...
void initialize(CompList< CompTypes... > &obj, std::initializer_list< EnumT > components)
typename std::decay< T >::type decay_t
Alias template for decay.
typename std::enable_if< B, T >::type enable_if_t
Alias template for enable_if.
auto get_labeled(const auto_bundle< Tag, Types... > &_obj)
void init(Args &&... args)
tim::mpl::apply< std::string > string
hash_value_t add_hash_id(hash_map_ptr_t &_hash_map, const string_view_t &_prefix)
add an string to the given hash-map (if it doesn't already exist) and return the hash
typename impl::is_one_of< Tp, Types > is_one_of
check if type is in expansion
auto get(const auto_bundle< Tag, Types... > &_obj)
Static polymorphic base class for automatic start/stop bundlers.
Static polymorphic base class for component bundlers.
This is a variadic component wrapper which combines the features of tim::auto_tuple<T....
Declare the operations types.
The purpose of this operation class is construct an object with specific args.
a variadic type which holds zero or more quirks that are passed to the constructor of a component bun...
this data type encodes the options of storage scope. The default is hierarchical (tree) scope....
const hash_value_t & get_hash() const
trait that signifies that an implementation for the component is available. When this is set to false...
trait that designates the type is a user-bundle
typename typename typename