libUTL++
Factory.h
1 #pragma once
2 
4 
5 #include <libutl/Object.h>
6 
8 
9 UTL_NS_BEGIN;
10 
12 // Factory /////////////////////////////////////////////////////////////////////////////////////////
14 
22 
24 class Factory : public Object
25 {
28 
29 public:
35  virtual Object* make(const Object* arg = nullptr) const = 0;
36 };
37 
39 // TFactory ////////////////////////////////////////////////////////////////////////////////////////
41 
49 
51 template <class T>
52 class TFactory : public Factory
53 {
56 
57 public:
63  virtual Object*
64  make(const Object* arg = nullptr) const
65  {
66  ASSERTD(arg == nullptr);
67  return new T();
68  }
69 
76  T*
77  makeT(const Object* arg = nullptr) const
78  {
79  return utl::cast<T>(make(arg));
80  }
81 };
82 
84 
85 UTL_NS_END;
86 
88 
#define UTL_CLASS_IMPL_TPL(className, T)
Implementation of standard UTL++ functionality for a template class.
Definition: macros.h:906
#define UTL_CLASS_DEFID
Default init() and deInit() (which are merely place-holders).
Definition: macros.h:532
Template version of Factory.
Definition: Factory.h:52
#define UTL_CLASS_DECL_ABC(DC, BC)
Declaration of standard UTL++ functionality for an abstract base class (ABC).
Definition: macros.h:650
#define UTL_CLASS_DECL_TPL(DC, T, BC)
Declaration of standard UTL++ functionality for a template class with one parameter.
Definition: macros.h:713
T * makeT(const Object *arg=nullptr) const
Make a new object.
Definition: Factory.h:77
virtual Object * make(const Object *arg=nullptr) const
Make a new object.
Definition: Factory.h:64
Root of UTL++ class hierarchy.
Definition: Object.h:52
Object creation abstraction.
Definition: Factory.h:24
#define ASSERTD
Do an assertion in DEBUG mode only.