Atlas-C++
Factory.h
1 // This file may be redistributed and modified only under the terms of
2 // the GNU Lesser General Public License (See COPYING for details).
3 // Copyright (C) 2000 Michael Day
4 
5 // $Id$
6 
7 #ifndef ATLAS_FACTORY_H
8 #define ATLAS_FACTORY_H
9 
10 #include <string>
11 #include <list>
12 #include <algorithm>
13 
14 namespace Atlas {
15 
33 template <typename T>
34 class Factory
35 {
36  public:
37 
38  Factory(const std::string& name, const typename T::Metrics& metrics)
39  : m_name(name), m_metrics(metrics)
40  {
41  factories()->push_back(this);
42  }
43 
44  virtual ~Factory()
45  {
46  std::list<Factory*>::iterator i;
47  i = std::find(factories()->begin(), factories()->end(), this);
48  factories()->erase(i);
49  }
50 
51  virtual T* New(const typename T::Parameters&) = 0;
52  virtual void Delete(T*) = 0;
53 
54  std::string getName()
55  {
56  return m_name;
57  }
58 
59  typename T::Metrics getMetrics()
60  {
61  return m_metrics;
62  }
63 
64  static std::list<Factory*> * factories()
65  {
66  static std::list<Factory*> * m_factories = nullptr;
67  if (m_factories == nullptr) {
68  m_factories = new std::list<Factory*>;
69  getFactories();
70  }
71  return m_factories;
72  }
73 
74  protected:
75 
76  std::string m_name;
77  typename T::Metrics m_metrics;
78 
79  private:
80 
81  static void getFactories();
82 };
83 
84 } // Atlas namespace
85 
86 #endif
Class factory.
Definition: Factory.h:34
The Atlas namespace.
Definition: Bridge.h:20

Copyright 2000-2004 the respective authors.

This document can be licensed under the terms of the GNU Free Documentation License or the GNU General Public License and may be freely distributed under the terms given by one of these licenses.