diff options
-rw-r--r-- | libadhocutil/factory.h | 25 | ||||
-rw-r--r-- | libadhocutil/scopeExit.h | 2 |
2 files changed, 26 insertions, 1 deletions
diff --git a/libadhocutil/factory.h b/libadhocutil/factory.h index 28fce62..f1998a7 100644 --- a/libadhocutil/factory.h +++ b/libadhocutil/factory.h @@ -5,24 +5,47 @@ #include "visibility.h" namespace AdHoc { + /** + * Base class for factories creating instances of Base. + */ template <typename Base, typename ... Params> class DLL_PUBLIC Factory { public: virtual ~Factory() = 0; - virtual Base * create(const Params & ...) const = 0; + /** + * Create a new instance of Base, overridden in a subclass to construct a new specific class. + * @param p The parameters passed to Impl constructor. + */ + virtual Base * create(const Params & ... p) const = 0; + /** + * A factory for a concrete implementation of Base + */ template <typename Impl, typename _ = Factory<Base, Params...>> class DLL_PUBLIC For : public _ { public: + /** + * Create a new instance of Base implemented in Impl. + * @param p The parameters passed to Impl constructor. + */ Base * create(const Params & ... p) const override { return new Impl(p...); } }; + /** + * Helper to get the factory for a specific implementation. + * @param name The name of the implementation. + */ static const Factory * get(const std::string & name); + /** + * Helper to create a new instance from a specific factory. + * @param name The name of the implementation. + * @param p The parameters to pass to the constructor. + */ static Base * create(const std::string & name, const Params & ... p); }; } diff --git a/libadhocutil/scopeExit.h b/libadhocutil/scopeExit.h index 17618a4..73c2ca2 100644 --- a/libadhocutil/scopeExit.h +++ b/libadhocutil/scopeExit.h @@ -26,7 +26,9 @@ class DLL_PUBLIC ScopeExit { ScopeExit(const Event & pre, const Event & success = Event(), const Event & failure = Event(), const Event & post = Event()); ~ScopeExit(); + /// Copying construction is disabled ScopeExit(const ScopeExit &) = delete; + /// Assignment is disabled void operator=(const ScopeExit &) = delete; /// @cond |