Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
PTL::EnvSettings Class Reference

#include <Utility.hh>

Public Types

typedef std::mutex mutex_t
 
typedef std::string string_t
 
typedef std::multimap< string_t, string_tenv_map_t
 
typedef std::pair< string_t, string_tenv_pair_t
 

Public Member Functions

template<typename Tp >
void insert (const std::string &env_id, Tp val)
 
template<typename Tp >
void insert (const std::string &env_id, EnvChoice< Tp > choice)
 
const env_map_tget () const
 
mutex_tmutex () const
 

Static Public Member Functions

static EnvSettingsGetInstance ()
 

Friends

std::ostream & operator<< (std::ostream &os, const EnvSettings &env)
 

Detailed Description

Definition at line 59 of file Utility.hh.

Member Typedef Documentation

◆ env_map_t

Definition at line 64 of file Utility.hh.

◆ env_pair_t

Definition at line 65 of file Utility.hh.

◆ mutex_t

typedef std::mutex PTL::EnvSettings::mutex_t

Definition at line 62 of file Utility.hh.

◆ string_t

typedef std::string PTL::EnvSettings::string_t

Definition at line 63 of file Utility.hh.

Member Function Documentation

◆ get()

const env_map_t & PTL::EnvSettings::get ( ) const
inline

Definition at line 119 of file Utility.hh.

119{ return m_env; }

◆ GetInstance()

static EnvSettings * PTL::EnvSettings::GetInstance ( )
inlinestatic

Definition at line 68 of file Utility.hh.

69 {
70 static EnvSettings* _instance = new EnvSettings();
71 return _instance;
72 }

Referenced by PTL::GetEnv(), and PTL::PrintEnv().

◆ insert() [1/2]

template<typename Tp >
void PTL::EnvSettings::insert ( const std::string &  env_id,
EnvChoice< Tp >  choice 
)
inline

Definition at line 95 of file Utility.hh.

96 {
97 Tp& val = std::get<0>(choice);
98 std::string& str_val = std::get<1>(choice);
99 std::string& descript = std::get<2>(choice);
100
101 std::stringstream ss, ss_long;
102 ss << std::boolalpha << val;
103 ss_long << std::boolalpha << std::setw(8) << std::left << val << " # (\""
104 << str_val << "\") " << descript;
105 m_mutex.lock();
106 if(m_env.find(env_id) != m_env.end())
107 {
108 for(const auto& itr : m_env)
109 if(itr.first == env_id && itr.second == ss.str())
110 {
111 m_mutex.unlock();
112 return;
113 }
114 }
115 m_env.insert(env_pair_t(env_id, ss_long.str()));
116 m_mutex.unlock();
117 }
std::pair< string_t, string_t > env_pair_t
Definition: Utility.hh:65

◆ insert() [2/2]

template<typename Tp >
void PTL::EnvSettings::insert ( const std::string &  env_id,
Tp  val 
)
inline

Definition at line 76 of file Utility.hh.

77 {
78 std::stringstream ss;
79 ss << std::boolalpha << val;
80 m_mutex.lock();
81 if(m_env.find(env_id) != m_env.end())
82 {
83 for(const auto& itr : m_env)
84 if(itr.first == env_id && itr.second == ss.str())
85 {
86 m_mutex.unlock();
87 return;
88 }
89 }
90 m_env.insert(env_pair_t(env_id, ss.str()));
91 m_mutex.unlock();
92 }

Referenced by PTL::GetEnv().

◆ mutex()

mutex_t & PTL::EnvSettings::mutex ( ) const
inline

Definition at line 120 of file Utility.hh.

120{ return m_mutex; }

Friends And Related Function Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream &  os,
const EnvSettings env 
)
friend

Definition at line 122 of file Utility.hh.

123 {
124 std::stringstream filler;
125 filler.fill('#');
126 filler << std::setw(90) << "";
127 std::stringstream ss;
128 ss << filler.str() << "\n# Environment settings:\n";
129 env.mutex().lock();
130 for(const auto& itr : env.get())
131 {
132 ss << "# " << std::setw(35) << std::right << itr.first << "\t = \t"
133 << std::left << itr.second << "\n";
134 }
135 env.mutex().unlock();
136 ss << filler.str();
137 os << ss.str() << std::endl;
138 return os;
139 }

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