Orfeo Toolbox
3.16
Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
OTB
Utilities
ITK
Code
Numerics
FEM
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>
66
class
FEMObjectFactory
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
;
83
typedef
typename
COF_Array::value_type
COF_Array_value_type
;
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;
104
Instance
().
m_MutexLock
.
Lock
();
105
Instance
().
cofs_
.push_back(
COF_Array_value_type
(f,str) );
106
clid =
static_cast<
int
>
(
Instance
().
cofs_
.size()-1 );
107
Instance
().
m_MutexLock
.
Unlock
();
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
141
COF_Array
cofs_
;
142
147
mutable
SimpleFastMutexLock
m_MutexLock
;
148
153
FEMObjectFactory
();
154
158
FEMObjectFactory
(
const
FEMObjectFactory
&);
159
163
~FEMObjectFactory
();
164
168
inline
static
FEMObjectFactory
&
Instance
();
169
174
static
void
CleanUP
();
175
179
static
FEMObjectFactory
*
obj
;
180
181
private
:
187
class
Dummy
{};
188
193
friend
class
Dummy
;
194
195
};
196
197
198
template
<
class
T>
199
FEMObjectFactory<T>
*
FEMObjectFactory<T>::obj
= 0;
200
201
template
<
class
T>
202
FEMObjectFactory<T>::FEMObjectFactory
() {}
203
204
template
<
class
T>
205
FEMObjectFactory<T>::FEMObjectFactory
(
const
FEMObjectFactory<T>
&) {}
206
207
template
<
class
T>
208
FEMObjectFactory<T>::~FEMObjectFactory
() {}
209
210
extern
"C"
211
{
212
typedef
void(*
c_void_cast
)();
213
}
214
template
<
class
T>
215
FEMObjectFactory<T>
&
FEMObjectFactory<T>::Instance
()
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