Orfeo Toolbox  3.16
itkFEMObjectFactory.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkFEMObjectFactory.h,v $
5  Language: C++
6  Date: $Date: 2009-04-05 10:56:50 $
7  Version: $Revision: 1.21 $
8 
9  Copyright (c) Insight Software Consortium. All rights reserved.
10  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11 
12  This software is distributed WITHOUT ANY WARRANTY; without even
13  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14  PURPOSE. See the above copyright notices for more information.
15 
16 =========================================================================*/
17 #ifndef __itkFEMObjectFactory_h
18 #define __itkFEMObjectFactory_h
19 
20 #include "itkFastMutexLock.h"
21 #include <string>
22 #include <vector>
23 #include <cstdlib>
24 #include <stdlib.h>
25 
26 namespace itk {
27 namespace fem {
28 
65 template<class T>
67 {
68 
72  typedef typename T::Pointer (*COF)();
73 
77  typedef std::string StrClassName;
78 
82  typedef std::vector<std::pair<COF,StrClassName> > COF_Array;
84 
85 public:
86 
90  static typename T::Pointer Create(int id)
91  {
92  return (Instance().cofs_[id].first)();
93  }
94 
101  static int Register(COF f, const char *str)
102  {
103  int clid=-1;
105  Instance().cofs_.push_back( COF_Array_value_type(f,str) );
106  clid = static_cast<int>( Instance().cofs_.size()-1 );
108  return clid;
109  }
110 
114  static StrClassName ID2ClassName(int id)
115  {
116  return Instance().cofs_[id].second;
117  }
118 
125  static int ClassName2ID(StrClassName str)
126  {
127  int j=0;
128  for(typename COF_Array::const_iterator i=Instance().cofs_.begin(); i != Instance().cofs_.end(); i++)
129  {
130  if (i->second==str) return j;
131  j++;
132  }
133  return -1;
134  }
135 
136 private:
137 
142 
148 
154 
159 
164 
168  inline static FEMObjectFactory& Instance();
169 
174  static void CleanUP();
175 
180 
181 private:
187  class Dummy {};
188 
193  friend class Dummy;
194 
195 };
196 
197 
198 template<class T>
200 
201 template<class T>
203 
204 template<class T>
206 
207 template<class T>
209 
210 extern "C"
211 {
212  typedef void(*c_void_cast)();
213 }
214 template<class T>
216 {
217  if (!obj)
218  {
222  obj=new FEMObjectFactory;
223 
228  atexit(reinterpret_cast<c_void_cast>(&CleanUP));
229 
230  }
231 
235  return *obj;
236 }
237 
238 template<class T>
239 void FEMObjectFactory<T>::CleanUP() { delete obj; }
240 
241 }} // end namespace itk::fem
242 
243 #endif // #ifndef __itkFEMFEMObjectFactory_h

Generated at Sat Feb 2 2013 23:36:47 for Orfeo Toolbox with doxygen 1.8.1.1