C++ Policies

template<typename T, bool WithThreads = true>
struct instance_tracker

Inherit from this policy to add reference counting support. Useful if you want to turn a global setting on/off when the number of components taking measurements has hit zero (e.g. all instances of component have called stop). Simply provides member functions and data values, increment/decrement is not automatically performed. In general, call instance_tracker::start or instance_tracker::stop inside of the components constructor if a component collects data and is using storage because instance(s) will be in the call-graph and thus, the instance count will always be > 0. Set the second template parameter to true if thread-local instance tracking is desired.

struct foo
: public base<foo, void>
, private policy::instance_tracker<foo, false>
{
    using value_type         = void;
    using instance_tracker_t = policy::instance_tracker<foo, false>;

    void start()
    {
        auto cnt = instance_tracker_t::start();
        if(cnt == 0)
            // start something
    }

    void stop()
    {
        auto cnt = instance_tracker_t::stop();
        if(cnt == 0)
            // stop something
    }
};

template<typename CompT, typename Tp>
struct record_statistics

Specification of how to accumulate statistics. This will not be used unless tim::trait::statistics has been assigned a type and tim::trait::record_statistics is true. Set tim::trait::permissive_statistics to allow implicit conversions, e.g. int -> size_t.

template <typename CompT, typename Tp>
struct record_statistics
{
    using type            = Tp;
    using component_type  = CompT;
    using statistics_type = statistics<type>;

    static void apply(statistics_type& stats, const component_type& obj)
    {
        // example:
        //      typeid(stats) is tim::statistics<double>
        //      obj.get() returns a double precision value
        stats += obj.get();
    }
};

template<typename Archive, typename Api>
struct input_archive

Provides a static get() function which returns a shared pointer to an instance of the given archive format for input. Can also provides static functions for any global configuration options, if necessary.

template<typename Archive, typename Api>
struct output_archive

Provides a static get() function which return a shared pointer to an instance of the given archive format for output. Can also provide static functions for any global configuration options for the archive format. For example, the (pretty) JSON output archive supports specification of the precision, indentation length, and the indentation character.