diff options
| -rw-r--r-- | project2/cgi/cgiOutputOptions.cpp | 2 | ||||
| -rw-r--r-- | project2/cgi/cgiRouter.cpp | 5 | ||||
| -rw-r--r-- | project2/cgi/testCgi.cpp | 1 | ||||
| -rw-r--r-- | project2/common/instanceStore.h | 90 | ||||
| -rw-r--r-- | project2/common/instanceStore.impl.h | 113 | ||||
| -rw-r--r-- | project2/common/logger.cpp | 4 | ||||
| -rw-r--r-- | project2/common/options.cpp | 3 | ||||
| -rw-r--r-- | project2/common/optionsSource.cpp | 4 | ||||
| -rw-r--r-- | project2/common/presenter.cpp | 3 | ||||
| -rw-r--r-- | project2/common/scriptLoader.cpp | 3 | ||||
| -rw-r--r-- | project2/common/scripts.cpp | 1 | ||||
| -rw-r--r-- | project2/common/sessionContainer.cpp | 3 | ||||
| -rw-r--r-- | project2/common/sourceObject.cpp | 4 | ||||
| -rw-r--r-- | project2/common/transform.cpp | 4 | ||||
| -rw-r--r-- | project2/common/variables.cpp | 3 | ||||
| -rw-r--r-- | project2/compression/decompressStream.cpp | 3 | ||||
| -rw-r--r-- | project2/daemon/lib/daemon.cpp | 3 | ||||
| -rw-r--r-- | project2/files/fsRows.cpp | 3 | ||||
| -rw-r--r-- | project2/sql/connectionLoader.cpp | 5 | ||||
| -rw-r--r-- | project2/xml/xmlDocumentCache.cpp | 2 | ||||
| -rw-r--r-- | project2/xml/xmlPresenter.cpp | 3 | 
21 files changed, 185 insertions, 77 deletions
| diff --git a/project2/cgi/cgiOutputOptions.cpp b/project2/cgi/cgiOutputOptions.cpp index 55e1de4..de3d291 100644 --- a/project2/cgi/cgiOutputOptions.cpp +++ b/project2/cgi/cgiOutputOptions.cpp @@ -1,5 +1,6 @@  #include "cgiOutputOptions.h"  #include "scripts.h" +#include "instanceStore.impl.h"  bool OutputOptions::core;  bool OutputOptions::session; @@ -36,4 +37,5 @@ OutputOptionsLoader::create(ScriptNodePtr e) const {  }  DECLARE_CUSTOM_COMPONENT_LOADER("outputoptions", OutputOptions, OutputOptionsLoader, OutputOptionsLoader) +INSTANTIATESTORE(std::string, OutputOptionsLoader); diff --git a/project2/cgi/cgiRouter.cpp b/project2/cgi/cgiRouter.cpp new file mode 100644 index 0000000..dc77c40 --- /dev/null +++ b/project2/cgi/cgiRouter.cpp @@ -0,0 +1,5 @@ +#include "cgiRouter.h" +#include "instanceStore.impl.h" + +INSTANTIATESTORE(std::string, RouterLoader); + diff --git a/project2/cgi/testCgi.cpp b/project2/cgi/testCgi.cpp index 58b823f..80c3f01 100644 --- a/project2/cgi/testCgi.cpp +++ b/project2/cgi/testCgi.cpp @@ -1,5 +1,6 @@  #include <iostream>  #include <boost/bind.hpp> +#include <boost/foreach.hpp>  #include <map>  #include "options.h"  #include "safeMapFind.h" diff --git a/project2/common/instanceStore.h b/project2/common/instanceStore.h index 36f4e73..5557b43 100644 --- a/project2/common/instanceStore.h +++ b/project2/common/instanceStore.h @@ -12,75 +12,12 @@  template <class Type, class StoreType>  class InstanceStore {  	public: -		static const StoreType & GetAll() -		{ -			return *getInstances(); -		} - -		static void Add(const typename StoreType::value_type & p) -		{ -			getInstances()->insert(p); -		} - -		template <typename EraseByType> -		static void Remove(const EraseByType & p) -		{ -			getInstances()->erase(p); -			prune(); -		} - -		static void OnEach(const boost::function<void(typename StoreType::value_type &)> & func, bool ContinueOnError = false) -		{ -			BOOST_FOREACH(const auto & l, GetAll()) { -				if (ContinueOnError) { -					try { -						func(l.get()); -					} -					catch (...) { -					} -				} -				else { -					func(l.get()); -				} -			} -			prune(); -		} +		static const StoreType & GetAll(); +		static void Add(const typename StoreType::value_type & p); -		static void OnAll(const boost::function<void(Type *)> & func, bool ContinueOnError = false) -		{ -			BOOST_FOREACH(const auto & l, GetAll()) { -				if (ContinueOnError) { -					try { -						func(l.get()); -					} -					catch (...) { -					} -				} -				else { -					func(l.get()); -				} -			} -			prune(); -		} - -	private: -		static void prune() -		{ -			auto & ps = getInstances(); -			if (ps->empty()) { -				delete ps; -				ps = NULL; -			} -		} - -		static StoreType * & getInstances() -		{ -			static StoreType * instances = NULL; -			if (!instances) { -				instances = new StoreType(); -			} -			return instances; -		} +	protected: +		static void prune(); +		static StoreType * & getInstances();  };  /// Keyed collection of instances @@ -88,25 +25,28 @@ template <class Type, class KeyType>  class InstanceMap : public InstanceStore<Type, std::map<KeyType, boost::shared_ptr<Type>>> {  	public:  		typedef std::map<KeyType, boost::shared_ptr<Type>> Store; +		typedef InstanceStore<Type, std::map<KeyType, boost::shared_ptr<Type>>> IStore;  		typedef typename Store::value_type Value; -		static void Add(const KeyType & k, Type * p) { -			InstanceStore<Type, Store>::Add(Value(k, boost::shared_ptr<Type>(p))); -		} -		 -		static void Add(const KeyType & k, const boost::shared_ptr<Type> & p) { -			InstanceStore<Type, Store>::Add(Value(k, p)); -		} +		static void Add(const KeyType & k, Type * p); +		static void Add(const KeyType & k, const boost::shared_ptr<Type> & p); +		static void Remove(const KeyType &);  		template <class E> static boost::shared_ptr<Type> Get(const KeyType & n)   		{  			return safeMapLookup<E>(InstanceStore<Type, Store>::GetAll(), n);  		} + +		static void OnEach(const boost::function<void(const Value &)> & func, bool ContinueOnError = false);  };  /// Anonymous collection of instances  template <class Type>  class InstanceSet : public InstanceStore<Type, std::set<boost::shared_ptr<Type>>> { +	public: +		typedef InstanceStore<Type, std::set<boost::shared_ptr<Type>>> IStore; +		static void OnAll(const boost::function<void(Type *)> & func, bool ContinueOnError = false); +		static void Remove(const boost::shared_ptr<Type> &);  };  #endif diff --git a/project2/common/instanceStore.impl.h b/project2/common/instanceStore.impl.h new file mode 100644 index 0000000..f626d47 --- /dev/null +++ b/project2/common/instanceStore.impl.h @@ -0,0 +1,113 @@ +#include "instanceStore.h" +#include <boost/foreach.hpp> + +template <class Type, class StoreType> +const StoreType & +InstanceStore<Type, StoreType>::GetAll() +{ +	return *getInstances(); +} + +template <class Type, class StoreType> +void +InstanceStore<Type, StoreType>::Add(const typename StoreType::value_type & p) +{ +	getInstances()->insert(p); +} + +template <class Type, class StoreType> +void +InstanceStore<Type, StoreType>::prune() +{ +	auto & ps = getInstances(); +	if (ps->empty()) { +		delete ps; +		ps = NULL; +	} +} + +template <class Type, class StoreType> +StoreType * & +InstanceStore<Type, StoreType>::getInstances() +{ +	static StoreType * instances = NULL; +	if (!instances) { +		instances = new StoreType(); +	} +	return instances; +} + +template <class Type, class KeyType> +void +InstanceMap<Type, KeyType>::Add(const KeyType & k, Type * p) +{ +	IStore::Add(Value(k, boost::shared_ptr<Type>(p))); +} + +template <class Type, class KeyType> +void +InstanceMap<Type, KeyType>::Add(const KeyType & k, const boost::shared_ptr<Type> & p) +{ +	IStore::Add(Value(k, p)); +} + +template <class Type, class KeyType> +void +InstanceMap<Type, KeyType>::Remove(const KeyType & k) +{ +	IStore::getInstances()->erase(k); +	IStore::prune(); +} + +template <class Type, class KeyType> +void +InstanceMap<Type, KeyType>::OnEach(const boost::function<void(const Value &)> & func, bool ContinueOnError) +{ +	BOOST_FOREACH(const auto & l, IStore::GetAll()) { +		if (ContinueOnError) { +			try { +				func(l); +			} +			catch (...) { +			} +		} +		else { +			func(l); +		} +	} +	IStore::prune(); +} + +template <class Type> +void +InstanceSet<Type>::OnAll(const boost::function<void(Type *)> & func, bool ContinueOnError) +{ +	BOOST_FOREACH(const auto & l, IStore::GetAll()) { +		if (ContinueOnError) { +			try { +				func(l.get()); +			} +			catch (...) { +			} +		} +		else { +			func(l.get()); +		} +	} +	IStore::prune(); +} + +template <class Type> +void +InstanceSet<Type>::Remove(const boost::shared_ptr<Type> & p) +{ +	IStore::getInstances()->erase(p); +	IStore::prune(); +} + +#define INSTANTIATESTORE(K, T) \ +template class InstanceStore<T, std::map<K, boost::shared_ptr<T>>>; \ +template class InstanceMap<T, K>; \ +template class InstanceStore<T, std::set<boost::shared_ptr<T>>>; \ +template class InstanceSet<T> + diff --git a/project2/common/logger.cpp b/project2/common/logger.cpp index 781b44a..a9c797a 100644 --- a/project2/common/logger.cpp +++ b/project2/common/logger.cpp @@ -3,7 +3,7 @@  #include "logger.h"  #include <boost/foreach.hpp> - +#include "instanceStore.impl.h"  Log Logger::log; @@ -97,3 +97,5 @@ LogDriverBase::~LogDriverBase()  {  } +INSTANTIATESTORE(std::string, LogDriverLoader); + diff --git a/project2/common/options.cpp b/project2/common/options.cpp index fd93576..3000069 100644 --- a/project2/common/options.cpp +++ b/project2/common/options.cpp @@ -1,6 +1,7 @@  #include <pch.hpp>  #include "options.h"  #include <boost/foreach.hpp> +#include "instanceStore.impl.h"  class NamedOption : public Options::Option {  	public: @@ -169,3 +170,5 @@ Options::InstanceTarget::assign(const VariableType & value) const  	assigner(value);  } +INSTANTIATESTORE(std::string, Options); + diff --git a/project2/common/optionsSource.cpp b/project2/common/optionsSource.cpp index 0f24f9e..58c9b1f 100644 --- a/project2/common/optionsSource.cpp +++ b/project2/common/optionsSource.cpp @@ -1,5 +1,7 @@  #include "optionsSource.h"  #include "logger.h" +#include <boost/foreach.hpp> +#include "instanceStore.impl.h"  class DefaultConfigConsumer : public ConfigConsumer {  	public: @@ -41,3 +43,5 @@ OptionsSource::loadSources(const Options::CurrentPlatform & platform)  	}  } +INSTANTIATESTORE(std::string, OptionsSource); + diff --git a/project2/common/presenter.cpp b/project2/common/presenter.cpp index 4e12307..35f5f2c 100644 --- a/project2/common/presenter.cpp +++ b/project2/common/presenter.cpp @@ -1,6 +1,7 @@  #include <pch.hpp>  #include "presenter.h"  #include "dataSource.h" +#include "instanceStore.impl.h"  #include <boost/foreach.hpp>  NameValuePairPresenter::NameValuePairPresenter() @@ -120,3 +121,5 @@ MultiRowSetPresenter::finalizeContent() const  {  } +INSTANTIATESTORE(std::string, PresenterLoader); + diff --git a/project2/common/scriptLoader.cpp b/project2/common/scriptLoader.cpp index fe8799b..93ed639 100644 --- a/project2/common/scriptLoader.cpp +++ b/project2/common/scriptLoader.cpp @@ -7,6 +7,7 @@  #include <boost/foreach.hpp>  #include <boost/function.hpp>  #include <boost/function_equal.hpp> +#include "instanceStore.impl.h"  unsigned int LoaderBase::depth = 0;  std::set<SourceObject *> LoaderBase::loadedObjects; @@ -137,3 +138,5 @@ LoaderBase::collectAll(const CommonObjects * co, bool childrenOnly, ScriptNodePt  	}  } +INSTANTIATESTORE(std::string, ScriptReaderLoader); + diff --git a/project2/common/scripts.cpp b/project2/common/scripts.cpp index a4a036d..a7a6c23 100644 --- a/project2/common/scripts.cpp +++ b/project2/common/scripts.cpp @@ -2,6 +2,7 @@  #include "variables/fixed.h"  #include <boost/filesystem/convenience.hpp>  #include <boost/tuple/tuple_comparison.hpp> +#include <boost/foreach.hpp>  ScriptReader::ScriptCache ScriptReader::scriptCache; diff --git a/project2/common/sessionContainer.cpp b/project2/common/sessionContainer.cpp index 41c3f98..ae82dd9 100644 --- a/project2/common/sessionContainer.cpp +++ b/project2/common/sessionContainer.cpp @@ -1,5 +1,6 @@  #include <pch.hpp>  #include "sessionContainer.h" +#include "instanceStore.impl.h"  SessionContainer::SessionContainer()  { @@ -27,3 +28,5 @@ SessionContainer::GetSession(const boost::uuids::uuid & id) const  	return s;  } +INSTANTIATESTORE(std::string, SessionContainerLoader); + diff --git a/project2/common/sourceObject.cpp b/project2/common/sourceObject.cpp index b451919..a76bdec 100644 --- a/project2/common/sourceObject.cpp +++ b/project2/common/sourceObject.cpp @@ -1,4 +1,5 @@  #include <pch.hpp> +#include "instanceStore.impl.h"  #include "sourceObject.h"  #include "exceptions.h"  #include "safeMapFind.h" @@ -54,3 +55,6 @@ SourceObject::findComponent(const std::string & name) const  	return safeMapLookup<ComponentNotFound>(script->namedComponents, name);  } +INSTANTIATESTORE(std::string, ComponentLoader); +INSTANTIATESTORE(std::string, ElementLoader); + diff --git a/project2/common/transform.cpp b/project2/common/transform.cpp index d392110..5f64de7 100644 --- a/project2/common/transform.cpp +++ b/project2/common/transform.cpp @@ -4,6 +4,7 @@  #include "ostreamWrapper.h"  #include "scriptStorage.h"  #include <boost/foreach.hpp> +#include "instanceStore.impl.h"  class TransformTargetStorer : public Storer {  	public: @@ -106,3 +107,6 @@ class TransformStaticContentToStdStream : public TransformImpl<StaticContent, os  };  DECLARE_TRANSFORM(TransformStaticContentToStdStream); +INSTANTIATESTORE(std::string, TransformLoader); +INSTANTIATESTORE(std::string, TransformTargetLoader); + diff --git a/project2/common/variables.cpp b/project2/common/variables.cpp index 42a596e..29e694a 100644 --- a/project2/common/variables.cpp +++ b/project2/common/variables.cpp @@ -13,6 +13,7 @@  #include <boost/algorithm/string/predicate.hpp>  #include <boost/function.hpp>  #include <boost/bind.hpp> +#include "instanceStore.impl.h"  VariableImplDyn::VariableImplDyn(ScriptNodePtr e)  { @@ -124,3 +125,5 @@ Variable::makeParent(const Glib::ustring & name, bool attr, unsigned int dep)  	return Variable(new VariableParent(name, attr, dep));  } +INSTANTIATESTORE(std::string, VariableLoader); + diff --git a/project2/compression/decompressStream.cpp b/project2/compression/decompressStream.cpp index ad2e01d..c1d52ab 100644 --- a/project2/compression/decompressStream.cpp +++ b/project2/compression/decompressStream.cpp @@ -4,6 +4,7 @@  #include "scripts.h"  #include "variables.h"  #include "scriptStorage.h" +#include "instanceStore.impl.h"  class DecompressStream : public Stream {  	public: @@ -28,3 +29,5 @@ class DecompressStream : public Stream {  };  DECLARE_LOADER("decompstream", DecompressStream); +INSTANTIATESTORE(std::string, DecompressorLoader); + diff --git a/project2/daemon/lib/daemon.cpp b/project2/daemon/lib/daemon.cpp index 1a70fc1..2f1760f 100644 --- a/project2/daemon/lib/daemon.cpp +++ b/project2/daemon/lib/daemon.cpp @@ -1,4 +1,5 @@  #include "daemon.h" +#include "instanceStore.impl.h"  Daemon::Daemon()  { @@ -8,3 +9,5 @@ Daemon::~Daemon()  {  } +INSTANTIATESTORE(std::string, DaemonLoader); + diff --git a/project2/files/fsRows.cpp b/project2/files/fsRows.cpp index aca1626..657973f 100644 --- a/project2/files/fsRows.cpp +++ b/project2/files/fsRows.cpp @@ -14,6 +14,7 @@  #include <grp.h>  #include <stdio.h>  #include <boost/date_time/posix_time/posix_time.hpp> +#include "instanceStore.impl.h"  typedef boost::filesystem::directory_iterator DirEnt; @@ -236,3 +237,5 @@ FsRows::SearchState::fileType() const  	throw NotSupported(__PRETTY_FUNCTION__);  } +INSTANTIATESTORE(std::string, FsRows::SpecBaseLoader); + diff --git a/project2/sql/connectionLoader.cpp b/project2/sql/connectionLoader.cpp new file mode 100644 index 0000000..671fafc --- /dev/null +++ b/project2/sql/connectionLoader.cpp @@ -0,0 +1,5 @@ +#include "connectionLoader.h" +#include "instanceStore.impl.h" + +INSTANTIATESTORE(std::string, ConnectionLoader); + diff --git a/project2/xml/xmlDocumentCache.cpp b/project2/xml/xmlDocumentCache.cpp index cbfaf74..52165fb 100644 --- a/project2/xml/xmlDocumentCache.cpp +++ b/project2/xml/xmlDocumentCache.cpp @@ -116,5 +116,5 @@ class XmlDocumentCacheClearer : public ComponentLoader {  			Logger()->messagef(LOG_DEBUG, "%s: Cleared XML document cache", __PRETTY_FUNCTION__);  		}  }; -DECLARE_CUSTOM_COMPONENT_LOADER("XmlDocumentCacheClearer", XmlDocumentCacheClearer, XmlDocumentCacheClearer, XmlDocumentCacheClearer); +DECLARE_COMPONENT("XmlDocumentCacheClearer", XmlDocumentCacheClearer); diff --git a/project2/xml/xmlPresenter.cpp b/project2/xml/xmlPresenter.cpp index d0281f7..cf31f21 100644 --- a/project2/xml/xmlPresenter.cpp +++ b/project2/xml/xmlPresenter.cpp @@ -8,6 +8,7 @@  #include <boost/date_time/posix_time/time_formatters.hpp>  #include <boost/date_time/gregorian/formatters.hpp>  #include <boost/foreach.hpp> +#include "instanceStore.impl.h"  DECLARE_OPTIONS(XmlPresenter, "XML Presenter options")  ("presenter.xml.typeid.null", Options::value(&typeidNull, false), @@ -268,3 +269,5 @@ XmlDocMutator::XmlDocMutator(ScriptNodePtr)  {  } +INSTANTIATESTORE(std::string, XmlDocMutatorLoader); + | 
