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::vsettings Struct Referenceabstract

Virtual base class for storing settings. More...

#include "timemory/settings/vsettings.hpp"

+ Collaboration diagram for tim::vsettings:

Classes

struct  noparse
 

Public Types

using parser_t = argparse::argument_parser
 
using parser_func_t = std::function< void(parser_t &)>
 
using display_map_t = std::map< std::string, std::string >
 

Public Member Functions

 vsettings (std::string _name="", std::string _env_name="", std::string _descript="", std::vector< std::string > _cmdline={}, int32_t _count=-1, int32_t _max_count=-1, std::vector< std::string > _choices={})
 
virtual ~vsettings ()=default
 
 vsettings (const vsettings &)=default
 
 vsettings (vsettings &&)=default
 
vsettingsoperator= (const vsettings &)=default
 
vsettingsoperator= (vsettings &&)=default
 
virtual std::string as_string () const =0
 
virtual void reset ()=0
 
virtual void parse ()=0
 
virtual void parse (const std::string &)=0
 
virtual void add_argument (argparse::argument_parser &)=0
 
virtual std::shared_ptr< vsettingsclone ()=0
 
virtual void clone (std::shared_ptr< vsettings > rhs)
 
virtual display_map_t get_display (std::ios::fmtflags fmt={}, int _w=-1, int _p=-1)
 
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 >
std::pair< bool, Tp > get () 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)
 
virtual parser_func_t get_action (TIMEMORY_API)=0
 

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_type_index = std::type_index(typeid(void))
 
std::type_index m_value_index = std::type_index(typeid(void))
 
int32_t m_count = -1
 
int32_t m_max_count = -1
 
std::string m_name = ""
 
std::string m_env_name = ""
 
std::string m_description = ""
 
std::vector< std::string > m_cmdline = {}
 
std::vector< std::string > m_choices = {}
 

Detailed Description

Virtual base class for storing settings.

Definition at line 55 of file vsettings.hpp.


Class Documentation

◆ tim::vsettings::noparse

struct tim::vsettings::noparse

Definition at line 61 of file vsettings.hpp.

+ Collaboration diagram for tim::vsettings::noparse:

Member Typedef Documentation

◆ display_map_t

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

Definition at line 59 of file vsettings.hpp.

◆ parser_func_t

using tim::vsettings::parser_func_t = std::function<void(parser_t&)>

Definition at line 58 of file vsettings.hpp.

◆ parser_t

Constructor & Destructor Documentation

◆ vsettings() [1/3]

TIMEMORY_SETTINGS_INLINE tim::vsettings::vsettings ( std::string  _name = "",
std::string  _env_name = "",
std::string  _descript = "",
std::vector< std::string >  _cmdline = {},
int32_t  _count = -1,
int32_t  _max_count = -1,
std::vector< std::string >  _choices = {} 
)

Definition at line 44 of file vsettings.cpp.

47: m_count(_count)
48, m_max_count(_max_count)
49, m_name(std::move(_name))
50, m_env_name(std::move(_env_name))
51, m_description(std::move(_descript))
52, m_cmdline(std::move(_cmdline))
53, m_choices(std::move(_choices))
54{}
int32_t m_count
Definition: vsettings.hpp:144
int32_t m_max_count
Definition: vsettings.hpp:145
std::vector< std::string > m_choices
Definition: vsettings.hpp:150
std::string m_name
Definition: vsettings.hpp:146
std::string m_description
Definition: vsettings.hpp:148
std::string m_env_name
Definition: vsettings.hpp:147
std::vector< std::string > m_cmdline
Definition: vsettings.hpp:149

◆ ~vsettings()

virtual tim::vsettings::~vsettings ( )
virtualdefault

◆ vsettings() [2/3]

tim::vsettings::vsettings ( const vsettings )
default

◆ vsettings() [3/3]

tim::vsettings::vsettings ( vsettings &&  )
default

Member Function Documentation

◆ add_argument()

virtual void tim::vsettings::add_argument ( argparse::argument_parser )
pure virtual

Implemented in tim::tsettings< Tp, Vp >.

◆ as_string()

virtual std::string tim::vsettings::as_string ( ) const
pure virtual

Implemented in tim::tsettings< Tp, Vp >.

◆ cast() [1/2]

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

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)
inlinestatic

Definition at line 119 of file vsettings.hpp.

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

◆ clone() [1/2]

virtual std::shared_ptr< vsettings > tim::vsettings::clone ( )
pure virtual

◆ clone() [2/2]

virtual void tim::vsettings::clone ( std::shared_ptr< vsettings rhs)
virtual

Reimplemented in tim::tsettings< Tp, Vp >.

◆ get() [1/2]

template<typename Tp >
std::pair< bool, Tp > tim::vsettings::get

Definition at line 155 of file vsettings.hpp.

156{
157 auto _ref = dynamic_cast<const tsettings<Tp, Tp&>*>(this);
158 if(_ref)
159 {
160 return { true, _ref->get() };
161 }
162
163 auto _nref = dynamic_cast<const tsettings<Tp, Tp>*>(this);
164 if(_nref)
165 return { true, _nref->get() };
166
167 return { false, Tp{} };
168}

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

◆ get() [2/2]

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

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()

virtual parser_func_t tim::vsettings::get_action ( TIMEMORY_API  )
pure virtual

Implemented in tim::tsettings< Tp, Vp >.

◆ get_choices()

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

Definition at line 92 of file vsettings.hpp.

92{ return m_choices; }

References m_choices.

◆ get_command_line()

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

Definition at line 91 of file vsettings.hpp.

91{ return m_cmdline; }

References m_cmdline.

◆ get_count()

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

Definition at line 93 of file vsettings.hpp.

93{ return m_count; }

References m_count.

◆ get_debug()

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

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 report_change().

◆ get_description()

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

Definition at line 90 of file vsettings.hpp.

90{ return m_description; }

References m_description.

◆ get_display()

virtual display_map_t tim::vsettings::get_display ( std::ios::fmtflags  fmt = {},
int  _w = -1,
int  _p = -1 
)
virtual

◆ get_env_name()

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

Definition at line 89 of file vsettings.hpp.

89{ return m_env_name; }

References m_env_name.

◆ get_max_count()

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

Definition at line 94 of file vsettings.hpp.

94{ return m_max_count; }

References m_max_count.

◆ get_name()

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

Definition at line 88 of file vsettings.hpp.

88{ return m_name; }

References m_name.

◆ get_type_index()

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

Definition at line 101 of file vsettings.hpp.

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

References m_type_index.

◆ get_value_index()

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

Definition at line 102 of file vsettings.hpp.

102{ return m_value_index; }
std::type_index m_value_index
Definition: vsettings.hpp:143

References m_value_index.

◆ matches()

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

◆ operator=() [1/2]

vsettings & tim::vsettings::operator= ( const vsettings )
default

◆ operator=() [2/2]

vsettings & tim::vsettings::operator= ( vsettings &&  )
default

◆ parse() [1/2]

virtual void tim::vsettings::parse ( )
pure virtual

Implemented in tim::tsettings< Tp, Vp >.

Referenced by set().

◆ parse() [2/2]

virtual void tim::vsettings::parse ( const std::string &  )
pure virtual

Implemented in tim::tsettings< Tp, Vp >.

◆ report_change()

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

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 get_debug(), m_env_name, and m_name.

◆ reset()

virtual void tim::vsettings::reset ( )
pure virtual

Implemented in tim::tsettings< Tp, Vp >.

◆ set() [1/2]

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

Definition at line 114 of file vsettings.hpp.

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

References parse().

◆ set() [2/2]

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

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_choices()

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

Definition at line 98 of file vsettings.hpp.

98{ m_choices = v; }

References m_choices.

◆ set_command_line()

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

Definition at line 99 of file vsettings.hpp.

99{ m_cmdline = v; }

References m_cmdline.

◆ set_count()

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

Definition at line 96 of file vsettings.hpp.

96{ m_count = v; }

References m_count.

◆ set_max_count()

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

Definition at line 97 of file vsettings.hpp.

97{ m_max_count = v; }

References m_max_count.

Member Data Documentation

◆ m_choices

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

Definition at line 150 of file vsettings.hpp.

Referenced by get_choices(), set_choices(), and tim::TIMEMORY_SETTINGS_LINKAGE().

◆ m_cmdline

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

◆ m_count

int32_t tim::vsettings::m_count = -1
protected

Definition at line 144 of file vsettings.hpp.

Referenced by get_count(), set_count(), and tim::TIMEMORY_SETTINGS_LINKAGE().

◆ m_description

std::string tim::vsettings::m_description = ""
protected

Definition at line 148 of file vsettings.hpp.

Referenced by get_description(), and tim::TIMEMORY_SETTINGS_LINKAGE().

◆ m_env_name

std::string tim::vsettings::m_env_name = ""
protected

Definition at line 147 of file vsettings.hpp.

Referenced by get_env_name(), report_change(), and tim::TIMEMORY_SETTINGS_LINKAGE().

◆ m_max_count

int32_t tim::vsettings::m_max_count = -1
protected

Definition at line 145 of file vsettings.hpp.

Referenced by get_max_count(), set_max_count(), and tim::TIMEMORY_SETTINGS_LINKAGE().

◆ m_name

std::string tim::vsettings::m_name = ""
protected

Definition at line 146 of file vsettings.hpp.

Referenced by get_name(), report_change(), and tim::TIMEMORY_SETTINGS_LINKAGE().

◆ m_type_index

std::type_index tim::vsettings::m_type_index = std::type_index(typeid(void))
protected

Definition at line 142 of file vsettings.hpp.

Referenced by get_type_index().

◆ m_value_index

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

Definition at line 143 of file vsettings.hpp.

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


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