15 #define epicsExportSharedSymbols 18 #if defined(__GNUC__) && __GNUC__ < 3 20 #define NO_STREAM_EXCEPTIONS 33 string value = getPropertyAsString(name, defaultValue ?
"1" :
"0");
34 std::transform(value.begin(), value.end(), value.begin(), ::tolower);
36 bool isTrue = (value ==
"1") || (value ==
"true") || (value ==
"yes");
40 bool isFalse = (value ==
"0") || (value ==
"false") || (value ==
"no");
51 return castUnsafe<epics::pvData::int32>(getPropertyAsString(name,
""));
52 }
catch(std::runtime_error&) {
60 return castUnsafe<float>(getPropertyAsString(name,
""));
61 }
catch(std::runtime_error&) {
69 return castUnsafe<double>(getPropertyAsString(name,
""));
70 }
catch(std::runtime_error&) {
78 if(tryGetPropertyAsString(name, &val))
86 unsigned short dftport=0;
87 if(addr->
sa.sa_family==AF_INET)
88 dftport = ntohs(addr->
ia.sin_port);
90 std::string val(getPropertyAsString(name,
""));
92 if(val.empty())
return false;
94 memset(addr, 0,
sizeof(*addr));
95 addr->
ia.sin_family = AF_INET;
103 return tryGetPropertyAsString(name,
NULL);
106 bool ConfigurationMap::tryGetPropertyAsString(
const std::string& name, std::string* val)
const 108 properties_t::const_iterator it = properties.find(name);
109 if(it==properties.end())
116 void ConfigurationMap::addKeys(
keys_t& names)
const 118 for(properties_t::const_iterator it=properties.begin(); it!=properties.end(); ++it)
119 names.insert(it->first);
123 const ENV_PARAM * findEnvConfigParam(
const char * envVarName )
129 if ( strcmp( envVarName, (*ppParam)->name ) == 0 ) {
139 bool ConfigurationEnviron::tryGetPropertyAsString(
const std::string& name, std::string* val)
const 141 const char *env = getenv(name.c_str());
143 const ENV_PARAM *pParam = findEnvConfigParam( name.c_str() );
154 bool ConfigurationStack::tryGetPropertyAsString(
const std::string& name, std::string* val)
const 156 for(confs_t::const_reverse_iterator it = confs.rbegin(), end = confs.rend();
166 void ConfigurationStack::addKeys(
keys_t& names)
const 168 for(confs_t::const_iterator it=confs.begin(); it!=confs.end(); ++it)
177 stack->push_back(env);
184 stack->push_back(env);
192 stack->push_back(conf);
197 ConfigurationBuilder::_add(
const std::string& name,
const std::string& val)
199 if(name.find_first_of(
" \t\r\n")!=name.npos)
200 THROW_EXCEPTION2(std::invalid_argument,
"Key name may not contain whitespace");
209 if(stack->size()==0) {
211 }
else if(stack->size()==1) {
212 return stack->pop_back();
221 std::map<std::string,Configuration::shared_pointer>::iterator configsIter = _configs.find(name);
222 if(configsIter != _configs.end())
224 string msg =
"configuration with name " + name +
" already registered";
227 _configs[name] = configuration;
233 std::map<std::string,Configuration::shared_pointer>::iterator configsIter = _configs.find(name);
234 if(configsIter != _configs.end())
236 return configsIter->second;
239 _configs[name] = env;
248 Lock guard(conf_factory_mutex);
249 if(configurationProvider.get() ==
NULL)
253 configurationProvider->registerConfiguration(
"system", systemConfig);
epics::pvData::int32 getPropertyAsInteger(const std::string &name, const epics::pvData::int32 defaultValue) const
Configuration::shared_pointer build()
LIBCOM_API int epicsStdCall aToIPAddr(const char *pAddrString, unsigned short defaultPort, struct sockaddr_in *pIP)
static ConfigurationProvider::shared_pointer getProvider()
#define THROW_EXCEPTION2(TYPE, MSG)
Lookup configuration strings from the process environment.
double getPropertyAsDouble(const std::string &name, const double defaultValue) const
Configuration::shared_pointer getConfiguration(const std::string &name)
TODO only here because of the Lockable.
A lock for multithreading.
std::set< std::string > keys_t
char * pdflt
Default value.
A structure to hold a single environment parameter.
ConfigurationProvider::shared_pointer configurationProvider
virtual void addKeys(keys_t &) const
virtual ~Configuration()=0
std::string getPropertyAsString(const std::string &name, const std::string &defaultValue) const
ConfigurationBuilder & push_map()
bool getPropertyAsBoolean(const std::string &name, const bool defaultValue) const
float getPropertyAsFloat(const std::string &name, const float defaultValue) const
bool getPropertyAsAddress(const std::string &name, osiSockAddr *addr) const
ConfigurationBuilder & push_env()
#define THROW_BASE_EXCEPTION(msg)
Lookup configuration strings from an in memory store.
virtual bool tryGetPropertyAsString(const std::string &name, std::string *val) const =0
bool hasProperty(const std::string &name) const
LIBCOM_API const ENV_PARAM * env_param_list[]
ConfigurationBuilder & push_config(const Configuration::shared_pointer &)
void registerConfiguration(const std::string &name, Configuration::shared_pointer const &configuration)