remove deprecated Properties

This commit is contained in:
Michael Davidsaver
2017-05-30 17:33:04 +02:00
parent dd78b467f8
commit 0fbbcc2d9f
3 changed files with 1 additions and 185 deletions

View File

@@ -26,121 +26,6 @@ namespace pvAccess {
using namespace epics::pvData;
using namespace std;
Properties::Properties() {}
Properties::Properties(const string &fileName) : _fileName(fileName) {}
const std::string &Properties::getProperty(const string &key) const
{
_properties_t::const_iterator propertiesIterator = _properties.find(key);
if(propertiesIterator != _properties.end()) {
return propertiesIterator->second;
} else {
THROW_BASE_EXCEPTION(string("Property not found in the map: ") + key);
}
}
const std::string &Properties::getProperty(const string &key, const string &defaultValue) const
{
_properties_t::const_iterator propertiesIterator = _properties.find(key);
if(propertiesIterator != _properties.end()) {
return propertiesIterator->second;
} else {
return defaultValue;
}
}
void Properties::load()
{
load(_fileName);
}
void Properties::load(const string &fileName)
{
ifstream strm(fileName.c_str());
load(strm);
}
namespace {
string trim(const string& in)
{
size_t A = in.find_first_not_of(" \t\r"),
B = in.find_last_not_of(" \t\r");
if(A==B)
return string();
else
return in.substr(A, B-A+1);
}
}
void Properties::load(std::istream& strm)
{
_properties_t newmap;
std::string line;
unsigned lineno = 0;
while(getline(strm, line).good()) {
lineno++;
size_t idx = line.find_first_not_of(" \t\r");
if(idx==line.npos || line[idx]=='#')
continue;
idx = line.find_first_of('=');
if(idx==line.npos) {
ostringstream msg;
msg<<"Malformed line "<<lineno<<" expected '='";
throw runtime_error(msg.str());
}
string key(trim(line.substr(0, idx))),
value(trim(line.substr(idx+1)));
if(key.empty()) {
ostringstream msg;
msg<<"Malformed line "<<lineno<<" expected name before '='";
throw runtime_error(msg.str());
}
newmap[key] = value;
}
if(strm.bad()) {
ostringstream msg;
msg<<"Malformed line "<<lineno<<" I/O error";
throw runtime_error(msg.str());
}
_properties.swap(newmap);
}
void Properties::store() const
{
store(_fileName);
}
void Properties::store(const std::string& fname) const
{
ofstream strm(fname.c_str());
store(strm);
}
void Properties::store(std::ostream& strm) const
{
for(_properties_t::const_iterator it=_properties.begin(), end=_properties.end();
it!=end && strm.good(); ++it)
{
strm << it->first << " = " << it->second << "\n";
}
}
void Properties::list()
{
for (std::map<std::string,std::string>::iterator propertiesIterator = _properties.begin() ;
propertiesIterator != _properties.end();
propertiesIterator++ )
{
cout << "Key:" << propertiesIterator->first << ",Value: " << propertiesIterator->second << endl;
}
}
bool Configuration::getPropertyAsBoolean(const std::string &name, const bool defaultValue) const
{
string value = getPropertyAsString(name, defaultValue ? "1" : "0");

View File

@@ -36,44 +36,6 @@ union osiSockAddr; // defined in osiSock;
namespace epics {
namespace pvAccess {
class epicsShareClass Properties
{
public:
Properties() EPICS_DEPRECATED;
Properties(const std::string &fileName) EPICS_DEPRECATED;
inline void setProperty(const std::string &key,const std::string &value)
{
_properties[key] = value;
}
const std::string& getProperty(const std::string &key) const;
const std::string& getProperty(const std::string &key, const std::string &defaultValue) const;
inline bool hasProperty(const std::string &key) const
{
return _properties.find(key) != _properties.end();
}
void store() const;
void store(const std::string &fileName) const;
void store(std::ostream& strm) const;
void load();
void load(const std::string &fileName);
void load(std::istream& strm);
void list();
inline size_t size() const {
return _properties.size();
}
private:
typedef std::map<std::string,std::string> _properties_t;
_properties_t _properties;
std::string _fileName;
public:
inline const _properties_t& map() const {
return _properties;
}
};
class ConfigurationStack;
/**

View File

@@ -54,36 +54,6 @@ void showEscaped(const char *msg, const std::string& s)
testDiag("%s: '%s", msg, &chars[0]);
}
static
void testProp()
{
Properties plist;
{
std::istringstream input(indata);
plist.load(input);
testOk1(!input.bad());
testOk1(input.eof());
}
testOk1(plist.size()==3);
testOk1(plist.getProperty("hello")=="world");
testOk1(plist.getProperty("this")=="is a test");
testOk1(!plist.hasProperty("foobar"));
{
std::ostringstream output;
plist.store(output);
std::string expect(expectdata), actual(output.str());
testOk1(!output.bad());
testOk(expect.size()==actual.size(), "%u == %u", (unsigned)expect.size(), (unsigned)actual.size());
testOk1(actual==expectdata);
showEscaped("actual", actual);
showEscaped("expect", expect);
}
}
static void showEnv(const char *name)
{
testDiag("%s = \"%s\"", name, getenv(name));
@@ -201,8 +171,7 @@ void testConfig()
MAIN(configurationTest)
{
testPlan(49);
testProp();
testPlan(40);
testBuilder();
testConfig();
return testDone();