[asterisk-scf-commits] asterisk-scf/integration/ice.git branch "iceutil-propertyhandler" created.
Commits to the Asterisk SCF project code repositories
asterisk-scf-commits at lists.digium.com
Tue Mar 15 15:32:29 CDT 2011
branch "iceutil-propertyhandler" has been created
at 1221a61e1fe215fadb0f571f6dfb45be1e4e922b (commit)
- Log -----------------------------------------------------------------
commit 1221a61e1fe215fadb0f571f6dfb45be1e4e922b
Author: Kevin P. Fleming <kpfleming at digium.com>
Date: Tue Mar 15 15:31:50 2011 -0500
Begin moving the basic functions over to PropertiesHandler.
diff --git a/cpp/include/IceUtil/PropertiesHandler.h b/cpp/include/IceUtil/PropertiesHandler.h
new file mode 100644
index 0000000..06f1fa7
--- /dev/null
+++ b/cpp/include/IceUtil/PropertiesHandler.h
@@ -0,0 +1,88 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2010 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+
+#ifndef ICE_UTIL_PROPERTIESHANDLER_H
+#define ICE_UTIL_PROPERTIESHANDLER_H
+
+#include <IceUtil/Config.h>
+#include <IceUtil/Shared.h>
+#include <IceUtil/Handle.h>
+
+#include <string>
+#include <vector>
+#include <map>
+#include <set>
+
+namespace Ice
+{
+
+class PropertiesI;
+
+}
+
+namespace IceUtilInternal
+{
+
+class ICE_UTIL_API PropertiesHandler : public IceUtil::Shared
+{
+public:
+
+ typedef std::vector<std::string> PropertyList;
+ typedef std::map<std::string, std::string> PropertyDict;
+
+ PropertiesHandler();
+ ~PropertiesHandler();
+
+ std::string getProperty(const std::string&);
+ std::string getPropertyWithDefault(const std::string&, const std::string&);
+
+ int getPropertyAsInt(const std::string&);
+ int getPropertyAsIntWithDefault(const std::string&, int);
+
+ PropertyList getPropertyAsList(const std::string&);
+ PropertyList getPropertyAsListWithDefault(const std::string&,
+ const PropertyList&);
+
+ PropertyDict getPropertiesForPrefix(const std::string&);
+
+ void setProperty(const std::string&, const std::string&);
+
+ void load(const std::string&);
+
+ std::set<std::string> getUnusedProperties();
+
+private:
+
+ friend class Ice::PropertiesI;
+
+ struct PropertyValue
+ {
+ PropertyValue() :
+ used(false)
+ {
+ }
+
+ PropertyValue(const std::string& v, bool u) :
+ value(v),
+ used(u)
+ {
+ }
+
+ std::string value;
+ bool used;
+ };
+
+ std::map<std::string, PropertyValue> _properties;
+};
+
+typedef IceUtil::Handle<PropertiesHandler> PropertiesHandlerPtr;
+
+}
+
+#endif
diff --git a/cpp/src/Ice/PropertiesI.cpp b/cpp/src/Ice/PropertiesI.cpp
index 5abd8b6..9152590 100644
--- a/cpp/src/Ice/PropertiesI.cpp
+++ b/cpp/src/Ice/PropertiesI.cpp
@@ -28,16 +28,7 @@ Ice::PropertiesI::getProperty(const string& key)
{
IceUtil::Mutex::Lock sync(*this);
- map<string, PropertyValue>::iterator p = _properties.find(key);
- if(p != _properties.end())
- {
- p->second.used = true;
- return p->second.value;
- }
- else
- {
- return string();
- }
+ return _propertiesHandler->getProperty(key);
}
string
@@ -45,16 +36,7 @@ Ice::PropertiesI::getPropertyWithDefault(const string& key, const string& value)
{
IceUtil::Mutex::Lock sync(*this);
- map<string, PropertyValue>::iterator p = _properties.find(key);
- if(p != _properties.end())
- {
- p->second.used = true;
- return p->second.value;
- }
- else
- {
- return value;
- }
+ return _propertiesHandler->getPropertyWithDefault(key, value);
}
Int
@@ -67,22 +49,8 @@ Int
Ice::PropertiesI::getPropertyAsIntWithDefault(const string& key, Int value)
{
IceUtil::Mutex::Lock sync(*this);
-
- map<string, PropertyValue>::iterator p = _properties.find(key);
- if(p != _properties.end())
- {
- Int val = value;
- p->second.used = true;
- istringstream v(p->second.value);
- if(!(v >> value) || !v.eof())
- {
- Warning out(getProcessLogger());
- out << "numeric property " << key << " set to non-numeric value, defaulting to " << val;
- return val;
- }
- }
- return value;
+ return _propertiesHandler->getPropertyAsIntWithDefault(key, value);
}
Ice::StringSeq
@@ -95,48 +63,16 @@ Ice::StringSeq
Ice::PropertiesI::getPropertyAsListWithDefault(const string& key, const StringSeq& value)
{
IceUtil::Mutex::Lock sync(*this);
-
- map<string, PropertyValue>::iterator p = _properties.find(key);
- if(p != _properties.end())
- {
- p->second.used = true;
- StringSeq result;
- if(!IceUtilInternal::splitString(p->second.value, ", \t\r\n", result))
- {
- Warning out(getProcessLogger());
- out << "mismatched quotes in property " << key << "'s value, returning default value";
- }
- if(result.size() == 0)
- {
- result = value;
- }
- return result;
- }
- else
- {
- return value;
- }
+ return _propertiesHandler->getPropertyAsListWithDefault(key, value);
}
-
PropertyDict
Ice::PropertiesI::getPropertiesForPrefix(const string& prefix)
{
IceUtil::Mutex::Lock sync(*this);
- PropertyDict result;
- map<string, PropertyValue>::iterator p;
- for(p = _properties.begin(); p != _properties.end(); ++p)
- {
- if(prefix.empty() || p->first.compare(0, prefix.size(), prefix) == 0)
- {
- p->second.used = true;
- result[p->first] = p->second.value;
- }
- }
-
- return result;
+ return _propertiesHandler->getPropertiesForPrefix(prefix);
}
void
@@ -203,23 +139,7 @@ Ice::PropertiesI::setProperty(const string& key, const string& value)
IceUtil::Mutex::Lock sync(*this);
- //
- // Set or clear the property.
- //
- if(!value.empty())
- {
- PropertyValue pv(value, false);
- map<string, PropertyValue>::const_iterator p = _properties.find(currentKey);
- if(p != _properties.end())
- {
- pv.used = p->second.used;
- }
- _properties[currentKey] = pv;
- }
- else
- {
- _properties.erase(currentKey);
- }
+ _propertiesHandler->setProperty(key, value);
}
StringSeq
@@ -227,10 +147,11 @@ Ice::PropertiesI::getCommandLineOptions()
{
IceUtil::Mutex::Lock sync(*this);
+ const map<string, IceUtilInternal::PropertiesHandler::PropertyValue>& props = (*_propertiesHandler)._properties;
StringSeq result;
- result.reserve(_properties.size());
- map<string, PropertyValue>::const_iterator p;
- for(p = _properties.begin(); p != _properties.end(); ++p)
+ result.reserve(props.size());
+ map<string, IceUtilInternal::PropertiesHandler::PropertyValue>::const_iterator p;
+ for(p = props.begin(); p != props.end(); ++p)
{
result.push_back("--" + p->first + "=" + p->second.value);
}
@@ -414,15 +335,8 @@ set<string>
Ice::PropertiesI::getUnusedProperties()
{
IceUtil::Mutex::Lock sync(*this);
- set<string> unusedProperties;
- for(map<string, PropertyValue>::const_iterator p = _properties.begin(); p != _properties.end(); ++p)
- {
- if(!p->second.used)
- {
- unusedProperties.insert(p->first);
- }
- }
- return unusedProperties;
+
+ return _propertiesHandler->getUnusedProperties();
}
Ice::PropertiesI::PropertiesI(const PropertiesI* p) :
diff --git a/cpp/src/Ice/PropertiesI.h b/cpp/src/Ice/PropertiesI.h
index c165c4d..7e346c5 100644
--- a/cpp/src/Ice/PropertiesI.h
+++ b/cpp/src/Ice/PropertiesI.h
@@ -11,6 +11,7 @@
#define ICE_PROPERTIES_I_H
#include <IceUtil/Mutex.h>
+#include <IceUtil/PropertiesHandler.h>
#include <Ice/Properties.h>
#include <Ice/StringConverter.h>
@@ -71,6 +72,7 @@ private:
};
std::map<std::string, PropertyValue> _properties;
const StringConverterPtr _converter;
+ IceUtilInternal::PropertiesHandlerPtr _propertiesHandler;
};
diff --git a/cpp/src/IceUtil/.depend b/cpp/src/IceUtil/.depend
index 188a0b9..5a4212c 100644
--- a/cpp/src/IceUtil/.depend
+++ b/cpp/src/IceUtil/.depend
@@ -21,3 +21,4 @@ Timer$(OBJEXT): Timer.cpp $(includedir)/IceUtil/Timer.h $(includedir)/IceUtil/Sh
UUID$(OBJEXT): UUID.cpp $(includedir)/IceUtil/UUID.h $(includedir)/IceUtil/Config.h $(includedir)/IceUtil/Random.h $(includedir)/IceUtil/Exception.h
Unicode$(OBJEXT): Unicode.cpp $(includedir)/IceUtil/Unicode.h $(includedir)/IceUtil/Config.h $(includedir)/IceUtil/Exception.h ../IceUtil/ConvertUTF.h
MutexProtocol$(OBJEXT): MutexProtocol.cpp $(includedir)/IceUtil/MutexProtocol.h $(includedir)/IceUtil/Config.h
+PropertiesHandler$(OBJEXT): PropertiesHandler.cpp $(includedir)/IceUtil/PropertiesHandler.h $(includedir)/IceUtil/Config.h $(includedir)/IceUtil/Shared.h $(includedir)/IceUtil/Handle.h $(includedir)/IceUtil/Exception.h $(includedir)/IceUtil/DisableWarnings.h
diff --git a/cpp/src/IceUtil/.depend.mak b/cpp/src/IceUtil/.depend.mak
index 1b37d08..20ade2b 100644
--- a/cpp/src/IceUtil/.depend.mak
+++ b/cpp/src/IceUtil/.depend.mak
@@ -21,3 +21,4 @@ Timer$(OBJEXT): Timer.cpp "$(includedir)/IceUtil/Timer.h" "$(includedir)/IceUtil
UUID$(OBJEXT): UUID.cpp "$(includedir)/IceUtil/UUID.h" "$(includedir)/IceUtil/Config.h" "$(includedir)/IceUtil/Random.h" "$(includedir)/IceUtil/Exception.h"
Unicode$(OBJEXT): Unicode.cpp "$(includedir)/IceUtil/Unicode.h" "$(includedir)/IceUtil/Config.h" "$(includedir)/IceUtil/Exception.h" ../IceUtil/ConvertUTF.h
MutexProtocol$(OBJEXT): MutexProtocol.cpp "$(includedir)/IceUtil/MutexProtocol.h" "$(includedir)/IceUtil/Config.h"
+PropertiesHandler$(OBJEXT): PropertiesHandler.cpp "$(includedir)/IceUtil/PropertiesHandler.h" "$(includedir)/IceUtil/Config.h" "$(includedir)/IceUtil/Shared.h" "$(includedir)/IceUtil/Handle.h" "$(includedir)/IceUtil/Exception.h" "$(includedir)/IceUtil/DisableWarnings.h"
diff --git a/cpp/src/IceUtil/Makefile b/cpp/src/IceUtil/Makefile
index 903c3ed..cf69403 100644
--- a/cpp/src/IceUtil/Makefile
+++ b/cpp/src/IceUtil/Makefile
@@ -37,7 +37,8 @@ OBJS = ArgVector.o \
Timer.o \
UUID.o \
Unicode.o \
- MutexProtocol.o
+ MutexProtocol.o \
+ PropertiesHandler.o
SRCS = $(OBJS:.o=.cpp)
diff --git a/cpp/src/IceUtil/Makefile.mak b/cpp/src/IceUtil/Makefile.mak
index b384ecb..72ff0e5 100644
--- a/cpp/src/IceUtil/Makefile.mak
+++ b/cpp/src/IceUtil/Makefile.mak
@@ -36,7 +36,8 @@ OBJS = ArgVector.obj \
Timer.obj \
UUID.obj \
Unicode.obj \
- MutexProtocol.obj
+ MutexProtocol.obj \
+ PropertiesHandler.obj
SRCS = $(OBJS:.obj=.cpp)
diff --git a/cpp/src/IceUtil/PropertiesHandler.cpp b/cpp/src/IceUtil/PropertiesHandler.cpp
new file mode 100644
index 0000000..85efb95
--- /dev/null
+++ b/cpp/src/IceUtil/PropertiesHandler.cpp
@@ -0,0 +1,158 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2010 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+
+#include <IceUtil/DisableWarnings.h>
+#include <IceUtil/StringUtil.h>
+#include <IceUtil/PropertiesHandler.h>
+
+using namespace std;
+
+string
+IceUtilInternal::PropertiesHandler::getProperty(const string& key)
+{
+ map<string, PropertyValue>::iterator p = _properties.find(key);
+ if(p != _properties.end())
+ {
+ p->second.used = true;
+ return p->second.value;
+ }
+ else
+ {
+ return string();
+ }
+}
+
+string
+IceUtilInternal::PropertiesHandler::getPropertyWithDefault(const string& key, const string& value)
+{
+ map<string, PropertyValue>::iterator p = _properties.find(key);
+ if(p != _properties.end())
+ {
+ p->second.used = true;
+ return p->second.value;
+ }
+ else
+ {
+ return value;
+ }
+}
+
+int
+IceUtilInternal::PropertiesHandler::getPropertyAsInt(const string& key)
+{
+ return getPropertyAsIntWithDefault(key, 0);
+}
+
+int
+IceUtilInternal::PropertiesHandler::getPropertyAsIntWithDefault(const string& key, int value)
+{
+ map<string, PropertyValue>::iterator p = _properties.find(key);
+ if(p != _properties.end())
+ {
+ int val = value;
+ p->second.used = true;
+ istringstream v(p->second.value);
+ if(!(v >> value) || !v.eof())
+ {
+ return val;
+ }
+ }
+
+ return value;
+}
+
+vector<string>
+IceUtilInternal::PropertiesHandler::getPropertyAsList(const string& key)
+{
+ return getPropertyAsListWithDefault(key, vector<string>());
+}
+
+vector<string>
+IceUtilInternal::PropertiesHandler::getPropertyAsListWithDefault(const string& key, const vector<string>& value)
+{
+ map<string, PropertyValue>::iterator p = _properties.find(key);
+ if(p != _properties.end())
+ {
+ p->second.used = true;
+
+ vector<string> result;
+ IceUtilInternal::splitString(p->second.value, ", \t\r\n", result);
+ if(result.size() == 0)
+ {
+ result = value;
+ }
+ return result;
+ }
+ else
+ {
+ return value;
+ }
+}
+
+map<string, string>
+IceUtilInternal::PropertiesHandler::getPropertiesForPrefix(const string& prefix)
+{
+ PropertyDict result;
+ for(map<string, PropertyValue>::iterator p = _properties.begin(); p != _properties.end(); ++p)
+ {
+ if(prefix.empty() || p->first.compare(0, prefix.size(), prefix) == 0)
+ {
+ p->second.used = true;
+ result[p->first] = p->second.value;
+ }
+ }
+
+ return result;
+}
+
+void
+IceUtilInternal::PropertiesHandler::setProperty(const string& key, const string& value)
+{
+ //
+ // Trim whitespace
+ //
+ string currentKey = IceUtilInternal::trim(key);
+ if(currentKey.empty())
+ {
+ // TODO: should this throw an exception?
+ return;
+ }
+
+ //
+ // Set or clear the property.
+ //
+ if(!value.empty())
+ {
+ PropertyValue pv(value, false);
+ map<string, PropertyValue>::const_iterator p = _properties.find(currentKey);
+ if(p != _properties.end())
+ {
+ pv.used = p->second.used;
+ }
+ _properties[currentKey] = pv;
+ }
+ else
+ {
+ _properties.erase(currentKey);
+ }
+}
+
+set<string>
+IceUtilInternal::PropertiesHandler::getUnusedProperties()
+{
+ set<string> unusedProperties;
+ for(map<string, PropertyValue>::const_iterator p = _properties.begin(); p != _properties.end(); ++p)
+ {
+ if(!p->second.used)
+ {
+ unusedProperties.insert(p->first);
+ }
+ }
+ return unusedProperties;
+}
-----------------------------------------------------------------------
--
asterisk-scf/integration/ice.git
More information about the asterisk-scf-commits
mailing list