timemory 3.3.0
Modular C++ Toolkit for Performance Analysis and Logging. Profiling API and Tools for C, C++, CUDA, Fortran, and Python. The C++ template API is essentially a framework to creating tools: it is designed to provide a unifying interface for recording various performance measurements alongside data logging and interfaces to other tools.
tim::tsettings< Tp, Vp > Struct Template Referencefinal

Implements a specific setting. More...

#include "timemory/settings/tsettings.hpp"

+ Collaboration diagram for tim::tsettings< Tp, Vp >:

Public Types

using type = Tp
 
using value_type = Vp
 
using base_type = vsettings
 
using parser_t = base_type::parser_t
 
using parser_func_t = base_type::parser_func_t
 
using vpointer_t = std::shared_ptr< vsettings >
 
using display_map_t = std::map< std::string, std::string >
 

Public Member Functions

template<typename Up = Vp, enable_if_t<!std::is_reference< Up >::value > = 0>
 tsettings ()
 
template<typename... Args>
 tsettings (Vp, Args &&...)
 
template<typename... Args>
 tsettings (noparse, Vp, Args &&...)
 
 ~tsettings () override=default
 
 tsettings (const tsettings &)=default
 
 tsettings (tsettings &&) noexcept=default
 
tsettingsoperator= (const tsettings &)=default
 
tsettingsoperator= (tsettings &&) noexcept=default
 
Tp & get ()
 
const Tp & get () const
 
Tp get_value (const std::string &val) const
 
std::string as_string () const override
 
void set (Tp)
 
void reset () final
 
void parse () final
 
void parse (const std::string &v) final
 
void clone (std::shared_ptr< vsettings > rhs) final
 
void add_argument (argparse::argument_parser &p) final
 
vpointer_t clone () final
 
parser_func_t get_action (TIMEMORY_API) override
 
display_map_t get_display (std::ios::fmtflags fmt={}, int _w=-1, int _p=-1) override
 
template<typename Archive , typename Up = Vp>
void save (Archive &ar, const unsigned int, enable_if_t<!std::is_reference< Up >::value, int >=0) const
 
template<typename Archive >
void load (Archive &ar, const unsigned int)
 
template<typename... Args>
 tsettings (Vp _value, Args &&... _args)
 
template<typename... Args>
 tsettings (noparse, Vp _value, Args &&... _args)
 
const auto & get_name () const
 
const auto & get_env_name () const
 
const auto & get_description () const
 
const auto & get_command_line () const
 
const auto & get_choices () const
 
const auto & get_count () const
 
const auto & get_max_count () const
 
void set_count (int32_t v)
 
void set_max_count (int32_t v)
 
void set_choices (const std::vector< std::string > &v)
 
void set_command_line (const std::vector< std::string > &v)
 
auto get_type_index () const
 
auto get_value_index () const
 
virtual bool matches (const std::string &, bool exact=true) const
 
template<typename Tp >
bool get (Tp &_val) const
 
template<typename Tp , enable_if_t< std::is_fundamental< decay_t< Tp > >::value > = 0>
bool set (const Tp &_val)
 
void set (const std::string &_val)
 

Static Public Member Functions

template<typename Tp >
static auto cast (std::shared_ptr< vsettings > &_val)
 
template<typename Tp >
static auto cast (const std::shared_ptr< vsettings > &_val)
 

Protected Member Functions

template<typename Tp >
void report_change (Tp _old, const Tp &_new)
 

Static Protected Member Functions

static int get_debug ()
 

Protected Attributes

std::type_index m_value_index = std::type_index(typeid(void))
 
std::vector< std::string > m_cmdline = {}
 
std::vector< std::string > m_choices = {}
 

Detailed Description

template<typename Tp, typename Vp>
struct tim::tsettings< Tp, Vp >

Implements a specific setting.

Definition at line 55 of file tsettings.hpp.

Member Typedef Documentation

◆ base_type

template<typename Tp , typename Vp >
using tim::tsettings< Tp, Vp >::base_type = vsettings

Definition at line 79 of file tsettings.hpp.

◆ display_map_t

using tim::vsettings::display_map_t = std::map<std::string, std::string>
inherited

Definition at line 59 of file vsettings.hpp.

◆ parser_func_t

Definition at line 81 of file tsettings.hpp.

◆ parser_t

template<typename Tp , typename Vp >
using tim::tsettings< Tp, Vp >::parser_t = base_type::parser_t

Definition at line 80 of file tsettings.hpp.

◆ type

template<typename Tp , typename Vp >
using tim::tsettings< Tp, Vp >::type = Tp

Definition at line 77 of file tsettings.hpp.

◆ value_type

template<typename Tp , typename Vp >
using tim::tsettings< Tp, Vp >::value_type = Vp

Definition at line 78 of file tsettings.hpp.

◆ vpointer_t

template<typename Tp , typename Vp >
using tim::tsettings< Tp, Vp >::vpointer_t = std::shared_ptr<vsettings>

Definition at line 82 of file tsettings.hpp.

Constructor & Destructor Documentation

◆ tsettings() [1/7]

template<typename Tp , typename Vp >
template<typename Up , enable_if_t<!std::is_reference< Up >::value, int > >
tim::tsettings< Tp, Vp >::tsettings

Definition at line 166 of file tsettings.hpp.

167: base_type{}
168, m_value{ Tp{} }
169, m_init{ Tp{} }
170{
171 this->parse();
172}
void parse() final
Definition: tsettings.hpp:246
vsettings base_type
Definition: tsettings.hpp:79

References tim::tsettings< Tp, Vp >::parse().

◆ tsettings() [2/7]

template<typename Tp , typename Vp >
template<typename... Args>
tim::tsettings< Tp, Vp >::tsettings ( Vp  ,
Args &&  ... 
)

◆ tsettings() [3/7]

template<typename Tp , typename Vp >
template<typename... Args>
tim::tsettings< Tp, Vp >::tsettings ( noparse  ,
Vp  ,
Args &&  ... 
)

◆ ~tsettings()

template<typename Tp , typename Vp >
tim::tsettings< Tp, Vp >::~tsettings ( )
overridedefault

◆ tsettings() [4/7]

template<typename Tp , typename Vp >
tim::tsettings< Tp, Vp >::tsettings ( const tsettings< Tp, Vp > &  )
default

◆ tsettings() [5/7]

template<typename Tp , typename Vp >
tim::tsettings< Tp, Vp >::tsettings ( tsettings< Tp, Vp > &&  )
defaultnoexcept

◆ tsettings() [6/7]

template<typename Tp , typename Vp >
template<typename... Args>
tim::tsettings< Tp, Vp >::tsettings ( Vp  _value,
Args &&...  _args 
)

Definition at line 176 of file tsettings.hpp.

177: base_type{ std::forward<Args>(_args)... }
178, m_value{ _value } // NOLINT
179, m_init{ _value } // NOLINT
180{
181 this->parse();
182 m_type_index = std::type_index(typeid(type));
183 m_value_index = std::type_index(typeid(value_type));
184}
std::array< char *, 4 > _args
std::type_index m_value_index
Definition: vsettings.hpp:143

References tim::vsettings::m_value_index, and tim::tsettings< Tp, Vp >::parse().

◆ tsettings() [7/7]

template<typename Tp , typename Vp >
template<typename... Args>
tim::tsettings< Tp, Vp >::tsettings ( noparse  ,
Vp  _value,
Args &&...  _args 
)

Definition at line 188 of file tsettings.hpp.

189: base_type{ std::forward<Args>(_args)... }
190, m_value{ _value } // NOLINT
191, m_init{ _value } // NOLINT
192{
193 m_type_index = std::type_index(typeid(type));
194 m_value_index = std::type_index(typeid(value_type));
195}

References tim::vsettings::m_value_index.

Member Function Documentation

◆ add_argument()

template<typename Tp , typename Vp >
void tim::tsettings< Tp, Vp >::add_argument ( argparse::argument_parser p)
finalvirtual

Implements tim::vsettings.

Definition at line 265 of file tsettings.hpp.

266{
267 if(!m_cmdline.empty())
268 {
269 if(std::is_same<Tp, bool>::value)
270 m_max_count = 1;
271 p.add_argument(m_cmdline, m_description)
272 .action(get_action(TIMEMORY_API{}))
273 .count(m_count)
274 .max_count(m_max_count)
275 .choices(m_choices);
276 }
277}
parser_func_t get_action(TIMEMORY_API) override
Definition: tsettings.hpp:307
std::vector< std::string > m_choices
Definition: vsettings.hpp:150
std::vector< std::string > m_cmdline
Definition: vsettings.hpp:149

References tim::argparse::argument_parser::argument::action(), tim::argparse::argument_parser::add_argument(), tim::argparse::argument_parser::argument::choices(), tim::argparse::argument_parser::argument::count(), tim::argparse::argument_parser::argument::max_count(), and TIMEMORY_API.

◆ as_string()

template<typename Tp , typename Vp >
std::string tim::tsettings< Tp, Vp >::as_string
overridevirtual

Implements tim::vsettings.

Definition at line 229 of file tsettings.hpp.

230{
231 std::stringstream ss;
232 ss << std::boolalpha;
233 ss << m_value;
234 return ss.str();
235}

◆ cast() [1/2]

template<typename Tp >
static auto tim::vsettings::cast ( const std::shared_ptr< vsettings > &  _val)
inlinestaticinherited

Definition at line 125 of file vsettings.hpp.

126 {
127 return static_cast<const tsettings<decay_t<Tp>, Tp>*>(_val.get());
128 }

◆ cast() [2/2]

template<typename Tp >
static auto tim::vsettings::cast ( std::shared_ptr< vsettings > &  _val)
inlinestaticinherited

Definition at line 119 of file vsettings.hpp.

120 {
121 return static_cast<tsettings<decay_t<Tp>, Tp>*>(_val.get());
122 }

◆ clone() [1/2]

template<typename Tp , typename Vp >
std::shared_ptr< vsettings > tim::tsettings< Tp, Vp >::clone
finalvirtual

Implements tim::vsettings.

Definition at line 296 of file tsettings.hpp.

297{
298 using Up = decay_t<Tp>;
299 return std::make_shared<tsettings<Up>>(
300 noparse{}, Up{ m_value }, std::string{ m_name }, std::string{ m_env_name },
301 std::string{ m_description }, std::vector<std::string>{ m_cmdline },
302 int32_t{ m_count }, int32_t{ m_max_count },
303 std::vector<std::string>{ m_choices });
304}
tim::mpl::apply< std::string > string
Definition: macros.hpp:53

◆ clone() [2/2]

template<typename Tp , typename Vp >
void tim::tsettings< Tp, Vp >::clone ( std::shared_ptr< vsettings rhs)
finalvirtual

Reimplemented from tim::vsettings.

Definition at line 281 of file tsettings.hpp.

282{
283 vsettings::clone(rhs);
284 if(dynamic_cast<tsettings<Tp>*>(rhs.get()))
285 {
286 set(dynamic_cast<tsettings<Tp>*>(rhs.get())->get());
287 }
288 else if(dynamic_cast<tsettings<Tp, Tp&>*>(rhs.get()))
289 {
290 set(dynamic_cast<tsettings<Tp, Tp&>*>(rhs.get())->get());
291 }
292}
void set(Tp)
Definition: tsettings.hpp:220
virtual std::shared_ptr< vsettings > clone()=0

References tim::vsettings::clone(), and tim::tsettings< Tp, Vp >::get().

◆ get() [1/3]

template<typename Tp , typename Vp >
Tp & tim::tsettings< Tp, Vp >::get

Definition at line 199 of file tsettings.hpp.

200{
201 return m_value;
202}

Referenced by tim::tsettings< Tp, Vp >::clone(), tim::vsettings::get(), and tim::settings::get().

◆ get() [2/3]

template<typename Tp , typename Vp >
const Tp & tim::tsettings< Tp, Vp >::get

Definition at line 206 of file tsettings.hpp.

207{
208 return m_value;
209}

◆ get() [3/3]

template<typename Tp >
bool tim::vsettings::get ( Tp &  _val) const
inherited

Definition at line 172 of file vsettings.hpp.

173{
174 auto&& _ret = this->get<Tp>();
175 if(_ret.first)
176 _val = _ret.second;
177 return _ret.first;
178}
const hash_alias_ptr_t hash_value_t std::string *& _ret
Definition: definition.hpp:300

◆ get_action()

template<typename Tp , typename Vp >
tsettings< Tp, Vp >::parser_func_t tim::tsettings< Tp, Vp >::get_action ( TIMEMORY_API  )
overridevirtual

Implements tim::vsettings.

Definition at line 307 of file tsettings.hpp.

308{
309 return get_action<Tp>();
310}

◆ get_choices()

const auto & tim::vsettings::get_choices ( ) const
inlineinherited

Definition at line 92 of file vsettings.hpp.

92{ return m_choices; }

References tim::vsettings::m_choices.

◆ get_command_line()

const auto & tim::vsettings::get_command_line ( ) const
inlineinherited

Definition at line 91 of file vsettings.hpp.

91{ return m_cmdline; }

References tim::vsettings::m_cmdline.

◆ get_count()

const auto & tim::vsettings::get_count ( ) const
inlineinherited

Definition at line 93 of file vsettings.hpp.

93{ return m_count; }
int32_t m_count
Definition: vsettings.hpp:144

References tim::vsettings::m_count.

◆ get_debug()

static int tim::vsettings::get_debug ( )
inlinestaticprotectedinherited

Definition at line 131 of file vsettings.hpp.

132 {
133 static bool _bool_val = get_env("TIMEMORY_DEBUG_SETTINGS", false);
134 static int _int_val = get_env("TIMEMORY_DEBUG_SETTINGS", 0);
135 return (_bool_val) ? _int_val : 0;
136 }
Tp get_env(const std::string &env_id, Tp _default, bool _store)

References tim::get_env().

Referenced by tim::vsettings::report_change().

◆ get_description()

const auto & tim::vsettings::get_description ( ) const
inlineinherited

Definition at line 90 of file vsettings.hpp.

90{ return m_description; }
std::string m_description
Definition: vsettings.hpp:148

References tim::vsettings::m_description.

◆ get_display()

template<typename Tp , typename Vp >
tsettings< Tp, Vp >::display_map_t tim::tsettings< Tp, Vp >::get_display ( std::ios::fmtflags  fmt = {},
int  _w = -1,
int  _p = -1 
)
overridevirtual

Reimplemented from tim::vsettings.

Definition at line 314 of file tsettings.hpp.

315{
316 auto _data = vsettings::get_display(fmt, _w, _p);
317 auto _as_str = [&](auto _val) {
318 std::stringstream _ss;
319 _ss.setf(fmt);
320 if(_w > -1)
321 _ss << std::setw(_w);
322 if(_p > -1)
323 _ss << std::setprecision(_p);
324 _ss << std::boolalpha << _val;
325 return _ss.str();
326 };
327 _data["value"] = _as_str(m_value);
328 _data["type"] = _as_str(demangle<Tp>());
329 return _data;
330}
virtual display_map_t get_display(std::ios::fmtflags fmt={}, int _w=-1, int _p=-1)

References tim::vsettings::get_display().

◆ get_env_name()

const auto & tim::vsettings::get_env_name ( ) const
inlineinherited

Definition at line 89 of file vsettings.hpp.

89{ return m_env_name; }
std::string m_env_name
Definition: vsettings.hpp:147

References tim::vsettings::m_env_name.

◆ get_max_count()

const auto & tim::vsettings::get_max_count ( ) const
inlineinherited

Definition at line 94 of file vsettings.hpp.

94{ return m_max_count; }
int32_t m_max_count
Definition: vsettings.hpp:145

References tim::vsettings::m_max_count.

◆ get_name()

const auto & tim::vsettings::get_name ( ) const
inlineinherited

Definition at line 88 of file vsettings.hpp.

88{ return m_name; }
std::string m_name
Definition: vsettings.hpp:146

References tim::vsettings::m_name.

◆ get_type_index()

auto tim::vsettings::get_type_index ( ) const
inlineinherited

Definition at line 101 of file vsettings.hpp.

101{ return m_type_index; }
std::type_index m_type_index
Definition: vsettings.hpp:142

References tim::vsettings::m_type_index.

◆ get_value()

template<typename Tp , typename Vp >
Tp tim::tsettings< Tp, Vp >::get_value ( const std::string &  val) const

Definition at line 213 of file tsettings.hpp.

214{
215 return get_value<Tp>(val);
216}

◆ get_value_index()

auto tim::vsettings::get_value_index ( ) const
inlineinherited

Definition at line 102 of file vsettings.hpp.

102{ return m_value_index; }

References tim::vsettings::m_value_index.

◆ load()

template<typename Tp , typename Vp >
template<typename Archive >
void tim::tsettings< Tp, Vp >::load ( Archive &  ar,
const unsigned int   
)

Definition at line 354 of file tsettings.hpp.

355{
356 try
357 {
358 std::string _dtype{};
359 ar(cereal::make_nvp("name", m_name));
360 ar(cereal::make_nvp("environ", m_env_name));
361 ar(cereal::make_nvp("description", m_description));
362 ar(cereal::make_nvp("count", m_count));
363 ar(cereal::make_nvp("max_count", m_max_count));
364 ar(cereal::make_nvp("cmdline", m_cmdline));
365 ar(cereal::make_nvp("data_type", _dtype));
366 ar(cereal::make_nvp("initial", m_init));
367 } catch(...)
368 {}
369 ar(cereal::make_nvp("value", m_value));
370}

◆ matches()

virtual bool tim::vsettings::matches ( const std::string &  ,
bool  exact = true 
) const
virtualinherited

◆ operator=() [1/2]

template<typename Tp , typename Vp >
tsettings & tim::tsettings< Tp, Vp >::operator= ( const tsettings< Tp, Vp > &  )
default

◆ operator=() [2/2]

template<typename Tp , typename Vp >
tsettings & tim::tsettings< Tp, Vp >::operator= ( tsettings< Tp, Vp > &&  )
defaultnoexcept

◆ parse() [1/2]

template<typename Tp , typename Vp >
void tim::tsettings< Tp, Vp >::parse
finalvirtual

Implements tim::vsettings.

Definition at line 246 of file tsettings.hpp.

247{
248 if(!m_env_name.empty())
249 {
250 char* c_env_val = std::getenv(m_env_name.c_str());
251 if(c_env_val)
252 parse(std::string{ c_env_val });
253 }
254}

Referenced by tim::tsettings< Tp, Vp >::tsettings().

◆ parse() [2/2]

template<typename Tp , typename Vp >
void tim::tsettings< Tp, Vp >::parse ( const std::string &  v)
finalvirtual

Implements tim::vsettings.

Definition at line 258 of file tsettings.hpp.

259{
260 set(std::move(get_value<decay_t<Tp>>(v)));
261}
Tp get_value(const std::string &val) const
Definition: tsettings.hpp:213

◆ report_change()

template<typename Tp >
void tim::vsettings::report_change ( Tp  _old,
const Tp &  _new 
)
protectedinherited

Definition at line 203 of file vsettings.hpp.

204{
205 if(get_debug() < 1)
206 return;
207
208 if(_old != _new)
209 {
210 std::ostringstream oss;
211 oss << std::boolalpha;
212 oss << "[timemory::settings] " << m_name << " (env: " << m_env_name
213 << ") changed: " << _old << " --> " << _new << "\n";
214 if(get_debug() > 1)
215 {
216 print_demangled_backtrace<6, 3>(oss);
217 }
218 std::cerr << oss.str() << std::flush;
219 }
220}
static int get_debug()
Definition: vsettings.hpp:131

References tim::vsettings::get_debug(), tim::vsettings::m_env_name, and tim::vsettings::m_name.

◆ reset()

template<typename Tp , typename Vp >
void tim::tsettings< Tp, Vp >::reset
finalvirtual

Implements tim::vsettings.

Definition at line 239 of file tsettings.hpp.

240{
241 set(m_init);
242}

◆ save()

template<typename Tp , typename Vp >
template<typename Archive , typename Up >
void tim::tsettings< Tp, Vp >::save ( Archive &  ar,
const unsigned int  ,
enable_if_t<!std::is_reference< Up >::value, int >  = 0 
) const

Definition at line 335 of file tsettings.hpp.

337{
338 std::string _dtype =
339 (std::is_same<Tp, std::string>::value) ? "string" : demangle<Tp>();
340 ar(cereal::make_nvp("name", m_name));
341 ar(cereal::make_nvp("environ", m_env_name));
342 ar(cereal::make_nvp("description", m_description));
343 ar(cereal::make_nvp("count", m_count));
344 ar(cereal::make_nvp("max_count", m_max_count));
345 ar(cereal::make_nvp("cmdline", m_cmdline));
346 ar(cereal::make_nvp("data_type", _dtype));
347 ar(cereal::make_nvp("initial", m_init));
348 ar(cereal::make_nvp("value", m_value));
349}

◆ set() [1/3]

void tim::vsettings::set ( const std::string &  _val)
inlineinherited

Definition at line 114 of file vsettings.hpp.

114{ parse(_val); }
virtual void parse()=0

References tim::vsettings::parse().

◆ set() [2/3]

template<typename Tp , enable_if_t< std::is_fundamental< decay_t< Tp > >::value > >
bool tim::vsettings::set ( const Tp &  _val)
inherited

Definition at line 182 of file vsettings.hpp.

183{
184 auto _ref = dynamic_cast<tsettings<Tp, Tp&>*>(this);
185 if(_ref)
186 {
187 _ref->set(_val);
188 return true;
189 }
190
191 auto _nref = dynamic_cast<tsettings<Tp, Tp>*>(this);
192 if(_nref)
193 {
194 _nref->set(_val);
195 return true;
196 }
197
198 return false;
199}

References tim::tsettings< Tp, Vp >::set().

◆ set() [3/3]

template<typename Tp , typename Vp >
void tim::tsettings< Tp, Vp >::set ( Tp  _value)

Definition at line 220 of file tsettings.hpp.

221{
222 auto _old = m_value;
223 m_value = std::move(_value);
224 report_change(std::move(_old), m_value);
225}
void report_change(Tp _old, const Tp &_new)
Definition: vsettings.hpp:203

Referenced by tim::vsettings::set(), and tim::settings::set().

◆ set_choices()

void tim::vsettings::set_choices ( const std::vector< std::string > &  v)
inlineinherited

Definition at line 98 of file vsettings.hpp.

98{ m_choices = v; }

References tim::vsettings::m_choices.

◆ set_command_line()

void tim::vsettings::set_command_line ( const std::vector< std::string > &  v)
inlineinherited

Definition at line 99 of file vsettings.hpp.

99{ m_cmdline = v; }

References tim::vsettings::m_cmdline.

◆ set_count()

void tim::vsettings::set_count ( int32_t  v)
inlineinherited

Definition at line 96 of file vsettings.hpp.

96{ m_count = v; }

References tim::vsettings::m_count.

◆ set_max_count()

void tim::vsettings::set_max_count ( int32_t  v)
inlineinherited

Definition at line 97 of file vsettings.hpp.

97{ m_max_count = v; }

References tim::vsettings::m_max_count.

Member Data Documentation

◆ m_choices

std::vector<std::string> tim::vsettings::m_choices = {}
protectedinherited

◆ m_cmdline

std::vector<std::string> tim::vsettings::m_cmdline = {}
protectedinherited

◆ m_value_index

std::type_index tim::vsettings::m_value_index = std::type_index(typeid(void))
protectedinherited

The documentation for this struct was generated from the following file: