This commit is contained in:
Matej Sekoranja
2011-01-31 22:10:42 +01:00
3 changed files with 26 additions and 10 deletions

View File

@@ -58,7 +58,7 @@ string Properties::getProperty(const string key)
else
{
string errMsg = "Property not found in the map: " + key;
throw BaseException(errMsg.c_str(), __FILE__, __LINE__);
THROW_BASE_EXCEPTION(errMsg.c_str());
}
}
@@ -84,7 +84,7 @@ void Properties::load()
}
catch (ifstream::failure& e) {
string errMsg = "Error opening file: " + string(_fileName.c_str());
throw BaseException(errMsg.c_str(), __FILE__, __LINE__);
THROW_BASE_EXCEPTION(errMsg.c_str());
}
string line;
@@ -116,7 +116,7 @@ void Properties::load()
if(pos == string::npos) //bad value (= not found)
{
string errMsg = "Bad property line found: " + line;
throw BaseException(errMsg.c_str(), __FILE__, __LINE__);
THROW_BASE_EXCEPTION(errMsg.c_str());
}
key = line.substr(0,pos);
@@ -134,7 +134,7 @@ void Properties::load()
return; //end of file
}
string errMsg = "Error reading file: " + _fileName;
throw BaseException(errMsg.c_str(), __FILE__, __LINE__);
THROW_BASE_EXCEPTION(errMsg.c_str());
}
_infile->close();
}
@@ -153,7 +153,7 @@ void Properties::store()
}
catch (ofstream::failure& e) {
string errMsg = "Error opening file: " + string(_fileName.c_str());
throw BaseException(errMsg.c_str(), __FILE__, __LINE__);
THROW_BASE_EXCEPTION(errMsg.c_str());
}
@@ -169,7 +169,7 @@ void Properties::store()
catch (ofstream::failure& e) {
_outfile->close();
string errMsg = "Error writing to file: " + string(_fileName.c_str());
throw BaseException(errMsg.c_str(), __FILE__, __LINE__);
THROW_BASE_EXCEPTION(errMsg.c_str());
}
}
_outfile->close();
@@ -272,6 +272,10 @@ ConfigurationProviderImpl::ConfigurationProviderImpl()
ConfigurationProviderImpl::~ConfigurationProviderImpl()
{
for(_configsIter = _configs.begin(); _configsIter != _configs.end(); _configsIter++)
{
delete _configsIter->second;
}
_configs.clear();
}
@@ -282,7 +286,7 @@ void ConfigurationProviderImpl::registerConfiguration(const string name, const C
if(_configsIter != _configs.end())
{
string msg = "configuration with name " + name + " already registered";
throw BaseException(msg.c_str(), __FILE__, __LINE__);
THROW_BASE_EXCEPTION(msg.c_str());
}
_configs[name] = configuration;
}
@@ -306,6 +310,8 @@ ConfigurationProviderImpl* ConfigurationFactory::getProvider()
if(_configurationProvider == NULL)
{
_configurationProvider = new ConfigurationProviderImpl();
// default
_configurationProvider->registerConfiguration("system", new SystemConfigurationImpl());
}
return _configurationProvider;
}

View File

@@ -72,6 +72,10 @@ private:
class Configuration : private epics::pvData::NoDefaultMethods
{
public:
/*
* Destructor.
*/
virtual ~Configuration() {};
/*
* Get the environment variable specified by name or return default value
* if it does not exist.
@@ -128,7 +132,7 @@ class SystemConfigurationImpl: public Configuration
{
public:
SystemConfigurationImpl();
virtual ~SystemConfigurationImpl();
~SystemConfigurationImpl();
bool getPropertyAsBoolean(const std::string name, const bool defaultValue);
epics::pvData::int32 getPropertyAsInteger(const std::string name, const epics::pvData::int32 defaultValue);
float getPropertyAsFloat(const std::string name, const float defaultValue);
@@ -148,6 +152,10 @@ private:
class ConfigurationProvider : private epics::pvData::NoDefaultMethods
{
public:
/*
* Destructor.
*/
virtual ~ConfigurationProvider() {};
/*
* Return configuration specified by name.
*
@@ -169,7 +177,10 @@ class ConfigurationProviderImpl: public ConfigurationProvider
{
public:
ConfigurationProviderImpl();
virtual ~ConfigurationProviderImpl();
/*
* Destructor. Note: Registered configurations will be deleted!!
*/
~ConfigurationProviderImpl();
Configuration* getConfiguration(const std::string name);
void registerConfiguration(const std::string name, const Configuration* configuration);
private:

View File

@@ -67,7 +67,6 @@ int main(int argc, char *argv[])
doubleProperty = configuration->getPropertyAsDouble("dobuleProperty1", -3);
assert(doubleProperty == 42);
if(configuration) delete configuration;
if(configProvider) delete configProvider;
getShowConstructDestruct()->constuctDestructTotals(stdout);
return 0;