From 2f45816ec2367e0a3cc2e9dfbbe8728f6e2d8408 Mon Sep 17 00:00:00 2001 From: cantor Date: Mon, 20 Feb 2006 08:15:50 +0000 Subject: [PATCH] Add static mgmt of interfaces. git-svn-id: https://svn.middleware.georgetown.edu/cpp-xmltooling/trunk@17 de75baf8-a10c-0410-a50a-987c0e22f00f --- xmltooling/XMLObjectBuilder.h | 61 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/xmltooling/XMLObjectBuilder.h b/xmltooling/XMLObjectBuilder.h index 50842b7..cd746f2 100644 --- a/xmltooling/XMLObjectBuilder.h +++ b/xmltooling/XMLObjectBuilder.h @@ -23,8 +23,15 @@ #if !defined(__xmltooling_xmlobjbuilder_h__) #define __xmltooling_xmlobjbuilder_h__ +#include +#include #include +#if defined (_MSC_VER) + #pragma warning( push ) + #pragma warning( disable : 4250 4251 ) +#endif + namespace xmltooling { /** @@ -33,7 +40,7 @@ namespace xmltooling { */ class XMLTOOL_API XMLObjectBuilder { - MAKE_NON_COPYABLE(XMLObjectBuilder); + MAKE_NONCOPYABLE(XMLObjectBuilder); public: virtual ~XMLObjectBuilder() {} @@ -51,8 +58,60 @@ namespace xmltooling { * needed to build an object. */ virtual void resetState()=0; + + /** + * Retrieves an XMLObjectBuilder using the key it was registered with. + * + * @param key the key used to register the builder + * @return the builder + */ + static XMLObjectBuilder* getBuilder(const QName& key) { + std::map::const_iterator i=m_map.find(key); + return (i==m_map.end()) ? NULL : i->second; + } + + /** + * Gets an immutable list of all the builders currently registered. + * + * @return list of all the builders currently registered + */ + static const std::map& getBuilders() { + return m_map; + } + + /** + * Registers a new builder for the given key. + * + * @param builderKey the key used to retrieve this builder later + * @param builder the builder + */ + static void registerBuilder(const QName& builderKey, XMLObjectBuilder* builder) { + m_map[builderKey]=builder; + } + + /** + * Deregisters a builder. + * + * @param builderKey the key for the builder to be deregistered + */ + static void deregisterBuilder(const QName& builderKey) { + delete getBuilder(builderKey); + m_map.erase(builderKey); + } + + /** + * Unregisters and destroys all registered builders. + */ + static void destroyBuilders(); + + private: + static std::map m_map; }; }; +#if defined (_MSC_VER) + #pragma warning( pop ) +#endif + #endif /* __xmltooling_xmlobjbuilder_h__ */ -- 2.1.4