OFFIS DCMTK  Version 3.6.0
factory.h
Go to the documentation of this file.
1 // Module: Log4CPLUS
2 // File: factory.h
3 // Created: 2/2002
4 // Author: Tad E. Smith
5 //
6 //
7 // Copyright 2002-2009 Tad E. Smith
8 //
9 // Licensed under the Apache License, Version 2.0 (the "License");
10 // you may not use this file except in compliance with the License.
11 // You may obtain a copy of the License at
12 //
13 // http://www.apache.org/licenses/LICENSE-2.0
14 //
15 // Unless required by applicable law or agreed to in writing, software
16 // distributed under the License is distributed on an "AS IS" BASIS,
17 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 // See the License for the specific language governing permissions and
19 // limitations under the License.
20 
23 #ifndef LOG4CPLUS_SPI_FACTORY_HEADER_
24 #define LOG4CPLUS_SPI_FACTORY_HEADER_
25 
26 #include "dcmtk/oflog/config.h"
27 #include "dcmtk/oflog/appender.h"
28 #include "dcmtk/oflog/layout.h"
29 #include "dcmtk/oflog/tstring.h"
32 #include "dcmtk/oflog/spi/filter.h"
33 #include "dcmtk/oflog/spi/objreg.h"
34 //#include <map>
35 //#include <memory>
36 //#include <vector>
37 
38 
39 namespace log4cplus {
40  namespace spi {
41 
45  class LOG4CPLUS_EXPORT BaseFactory {
46  public:
47  virtual ~BaseFactory() = 0;
48 
52  virtual log4cplus::tstring getTypeName() = 0;
53  };
54 
55 
60  class LOG4CPLUS_EXPORT AppenderFactory : public BaseFactory {
61  public:
62  typedef Appender ProductType;
64 
66  virtual ~AppenderFactory() = 0;
67 
71  virtual SharedAppenderPtr createObject(const log4cplus::helpers::Properties& props, log4cplus::tstring& error) = 0;
72  };
73 
74 
75 
80  class LOG4CPLUS_EXPORT LayoutFactory : public BaseFactory {
81  public:
82  typedef Layout ProductType;
84 
85  LayoutFactory();
86  virtual ~LayoutFactory() = 0;
87 
91  virtual OFauto_ptr<Layout> createObject(const log4cplus::helpers::Properties& props, log4cplus::tstring& error) = 0;
92  };
93 
94 
95 
100  class LOG4CPLUS_EXPORT FilterFactory : public BaseFactory {
101  public:
102  typedef Filter ProductType;
103  typedef FilterPtr ProductPtr;
104 
105  FilterFactory();
106  virtual ~FilterFactory() = 0;
107 
111  virtual FilterPtr createObject(const log4cplus::helpers::Properties& props, log4cplus::tstring& error) = 0;
112  };
113 
114 
115 
125  template<class T>
126  class LOG4CPLUS_EXPORT FactoryRegistry : private ObjectRegistryBase {
127  public:
128  typedef T product_type;
129 
130  virtual ~FactoryRegistry() {
131  clear();
132  }
133 
134  // public methods
139  bool put(OFauto_ptr<T> object) {
140  bool putValResult = putVal(object->getTypeName(), object.get());
141  object.release();
142  return putValResult;
143  }
144 
149  T* get(const log4cplus::tstring& name) const {
150  return OFstatic_cast(T*, getVal(name));
151  }
152 
153  protected:
154  virtual void deleteObject(void *object) const {
155  delete OFstatic_cast(T*, object);
156  }
157  };
158 
159 
160  typedef FactoryRegistry<AppenderFactory> AppenderFactoryRegistry;
161  typedef FactoryRegistry<LayoutFactory> LayoutFactoryRegistry;
162  typedef FactoryRegistry<FilterFactory> FilterFactoryRegistry;
163 
164 
168  LOG4CPLUS_EXPORT AppenderFactoryRegistry& getAppenderFactoryRegistry();
169 
173  LOG4CPLUS_EXPORT LayoutFactoryRegistry& getLayoutFactoryRegistry();
174 
178  LOG4CPLUS_EXPORT FilterFactoryRegistry& getFilterFactoryRegistry();
179 
180  }
181 }
182 
183 
184 #endif // LOG4CPLUS_SPI_FACTORY_HEADER_
185 


Generated on Thu Dec 20 2012 for OFFIS DCMTK Version 3.6.0 by Doxygen 1.8.2