From 36a3a590ffa4133f7f2d980a57d48ef95c680b71 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Fri, 11 Sep 2009 02:15:13 +0200 Subject: Extended StorageManager --- src/Common/StorageBackend.h | 4 ++++ src/Common/StorageManager.cpp | 16 ++++++++++++++++ src/Common/StorageManager.h | 3 +++ src/Common/XmlData.h | 19 +++++++++++++++++++ 4 files changed, 42 insertions(+) (limited to 'src/Common') diff --git a/src/Common/StorageBackend.h b/src/Common/StorageBackend.h index 027109e..1d53570 100644 --- a/src/Common/StorageBackend.h +++ b/src/Common/StorageBackend.h @@ -24,6 +24,7 @@ #include #include +#include namespace Mad { namespace Common { @@ -34,6 +35,9 @@ class StorageBackend { protected: friend class StorageManager; + virtual std::set listTypes() throw (Core::Exception) = 0; + virtual std::set list(const std::string &type) throw (Core::Exception) = 0; + virtual void store(const std::string &type, const std::string &name, const XmlData *data) throw (Core::Exception) = 0; virtual boost::shared_ptr load(const std::string &type, const std::string &name) throw (Core::Exception) = 0; diff --git a/src/Common/StorageManager.cpp b/src/Common/StorageManager.cpp index a1610fe..ac83476 100644 --- a/src/Common/StorageManager.cpp +++ b/src/Common/StorageManager.cpp @@ -36,6 +36,22 @@ void StorageManager::unsetBackend(boost::shared_ptr oldBackend) backend.reset(); } +std::set StorageManager::listTypes() throw (Core::Exception) { + boost::shared_lock lock(mutex); + if(!backend) + throw Core::Exception(Core::Exception::NOT_IMPLEMENTED); + + return backend->listTypes(); +} + +std::set StorageManager::list(const std::string &type) throw (Core::Exception) { + boost::shared_lock lock(mutex); + if(!backend) + throw Core::Exception(Core::Exception::NOT_IMPLEMENTED); + + return backend->list(type); +} + void StorageManager::store(const std::string &type, const std::string &name, const XmlData *data) throw (Core::Exception) { boost::shared_lock lock(mutex); if(!backend) diff --git a/src/Common/StorageManager.h b/src/Common/StorageManager.h index c81c707..98533fb 100644 --- a/src/Common/StorageManager.h +++ b/src/Common/StorageManager.h @@ -51,6 +51,9 @@ class MAD_COMMON_EXPORT StorageManager { void setBackend(boost::shared_ptr newBackend); void unsetBackend(boost::shared_ptr oldBackend); + std::set listTypes() throw (Core::Exception); + std::set list(const std::string &type) throw (Core::Exception); + void store(const std::string &type, const std::string &name, const XmlData *data) throw (Core::Exception); boost::shared_ptr load(const std::string &type, const std::string &name) throw (Core::Exception); }; diff --git a/src/Common/XmlData.h b/src/Common/XmlData.h index 51e5327..b7e8ec1 100644 --- a/src/Common/XmlData.h +++ b/src/Common/XmlData.h @@ -26,6 +26,7 @@ #include #include +#include #include #include #include @@ -283,6 +284,24 @@ class MAD_COMMON_EXPORT XmlData { return; } + + std::set getChildren() const { + std::set childNames; + + for(std::map::const_iterator it = elements.begin(); it != elements.end(); ++it) + childNames.insert(it->first); + + return childNames; + } + + std::set getLists() const { + std::set listNames; + + for(std::map::const_iterator it = lists.begin(); it != lists.end(); ++it) + listNames.insert(it->first); + + return listNames; + } }; class MAD_COMMON_EXPORT List : private boost::noncopyable { -- cgit v1.2.3