Field3D

#include <ClassFactory.h>

Public Types

typedef FieldRes::Ptr(* CreateFieldFnPtr) ()
 
typedef FieldIO::Ptr(* CreateFieldIOFnPtr) ()
 
typedef FieldMapping::Ptr(* CreateFieldMappingFnPtr) ()
 
typedef FieldMappingIO::Ptr(* CreateFieldMappingIOFnPtr) ()
 

Public Member Functions

 ClassFactory ()
 Standard constructor.
 
Field class
void registerField (CreateFieldFnPtr createFunc)
 Registers a class with the class pool.
 
FieldRes::Ptr createField (const std::string &className) const
 Instances an object by name.
 
void registerFieldIO (CreateFieldIOFnPtr createFunc)
 Registers an IO class with the class pool.
 
FieldIO::Ptr createFieldIO (const std::string &className) const
 Instances an IO object by name.
 

FieldMapping class

}

typedef std::vector< std::string > NameVec
 
typedef std::map< std::string, CreateFieldFnPtrFieldFuncMap
 
typedef std::map< std::string, CreateFieldIOFnPtrFieldIOFuncMap
 
typedef std::map< std::string, CreateFieldMappingFnPtrFieldMappingFuncMap
 
typedef std::map< std::string, CreateFieldMappingIOFnPtrFieldMappingIOFuncMap
 
FieldFuncMap m_fields
 Map of create functions for Fields. The key is the class name.
 
NameVec m_fieldNames
 
FieldIOFuncMap m_fieldIOs
 Map of create functions for FieldIO classes. The key is the class name.
 
NameVec m_fieldIONames
 
FieldMappingFuncMap m_mappings
 Map of create functions for FieldMappings. The key is the class name.
 
NameVec m_fieldMappingNames
 
FieldMappingIOFuncMap m_mappingIOs
 Map of create functions for FieldMapping IO classes.
The key is the class name.
 
NameVec m_fieldMappingIONames
 
static boost::scoped_ptr< ClassFactoryms_instance
 Pointer to static instance.
 
void registerFieldMapping (CreateFieldMappingFnPtr createFunc)
 Registers a class with the class pool.
 
FieldMapping::Ptr createFieldMapping (const std::string &className) const
 Instances an object by name.
 
void registerFieldMappingIO (CreateFieldMappingIOFnPtr createFunc)
 Registers an IO class with the class pool.
 
FieldMappingIO::Ptr createFieldMappingIO (const std::string &className) const
 Instances an IO object by name.
 
static ClassFactorysingleton ()
 }
 

Detailed Description

Definition at line 71 of file ClassFactory.h.

Member Typedef Documentation

◆ CreateFieldFnPtr

typedef FieldRes::Ptr(* ClassFactory::CreateFieldFnPtr) ()

Definition at line 78 of file ClassFactory.h.

◆ CreateFieldIOFnPtr

typedef FieldIO::Ptr(* ClassFactory::CreateFieldIOFnPtr) ()

Definition at line 79 of file ClassFactory.h.

◆ CreateFieldMappingFnPtr

typedef FieldMapping::Ptr(* ClassFactory::CreateFieldMappingFnPtr) ()

Definition at line 80 of file ClassFactory.h.

◆ CreateFieldMappingIOFnPtr

typedef FieldMappingIO::Ptr(* ClassFactory::CreateFieldMappingIOFnPtr) ()

Definition at line 81 of file ClassFactory.h.

◆ NameVec

typedef std::vector<std::string> ClassFactory::NameVec
private

Definition at line 135 of file ClassFactory.h.

◆ FieldFuncMap

typedef std::map<std::string, CreateFieldFnPtr> ClassFactory::FieldFuncMap
private

Definition at line 136 of file ClassFactory.h.

◆ FieldIOFuncMap

Definition at line 137 of file ClassFactory.h.

◆ FieldMappingFuncMap

Definition at line 138 of file ClassFactory.h.

◆ FieldMappingIOFuncMap

Definition at line 139 of file ClassFactory.h.

Constructor & Destructor Documentation

◆ ClassFactory()

ClassFactory::ClassFactory ( )

Standard constructor.

Definition at line 65 of file ClassFactory.cpp.

66{
68}
static void loadPlugins()
Checks all paths in $FIELD3D_DSO_PATH and loads the plugins it finds.

References PluginLoader::loadPlugins().

Member Function Documentation

◆ registerField()

void ClassFactory::registerField ( CreateFieldFnPtr createFunc)

Registers a class with the class pool.

Parameters
createFuncPointer to creation function

Definition at line 72 of file ClassFactory.cpp.

73{
74 // Make sure we don't add the same class twice
75
76 bool nameExists = false;
77
79
80 if (!instance) {
82 "Unsuccessful attempt at registering Field class. "
83 "(Creation function returned null pointer)");
84 return;
85 }
86
87 string simpleClassName = instance->className();
88 string dataTypeName = instance->dataTypeString();
89 string className = simpleClassName + "<" + dataTypeName + ">";
90
91 FieldFuncMap::const_iterator i = m_fields.find(className);
92 if (i != m_fields.end())
93 nameExists = true;
94
95 if (!nameExists) {
96 m_fields[className] = createFunc;
97 // if the simple (untemplated) class name hasn't been registered
98 // yet, add it to the list and print a message
99 if (find(m_fieldNames.begin(), m_fieldNames.end(),
100 className) == m_fieldNames.end()) {
101 m_fieldNames.push_back(className);
102 char *debugEnvVar = getenv("FIELD3D_DEBUG");
103 if (debugEnvVar) {
104 Msg::print("Registered Field class " + className);
105 }
106 }
107 }
108
109}
#define FIELD3D_MTX_T
Definition StdMathLib.h:99
FieldFuncMap m_fields
Map of create functions for Fields. The key is the class name.
NameVec m_fieldNames
boost::intrusive_ptr< FieldRes > Ptr
Definition Field.h:213
@ SevWarning
Definition Log.h:68
FIELD3D_API void print(Severity severity, const std::string &message)
Sends the string to the assigned output, prefixing the message with the severity.
Definition Log.cpp:70

References FIELD3D_MTX_T, m_fieldNames, m_fields, Msg::print(), and Msg::SevWarning.

◆ createField()

FieldRes::Ptr ClassFactory::createField ( const std::string & className) const

Instances an object by name.

Definition at line 114 of file ClassFactory.cpp.

115{
116 FieldFuncMap::const_iterator i = m_fields.find(className);
117 if (i != m_fields.end())
118 return i->second();
119 else
120 return FieldRes::Ptr();
121}

References FIELD3D_MTX_T, and m_fields.

◆ registerFieldIO()

void ClassFactory::registerFieldIO ( CreateFieldIOFnPtr createFunc)

Registers an IO class with the class pool.

Parameters
createFuncPointer to creation function

Definition at line 125 of file ClassFactory.cpp.

126{
127 // Make sure we don't add the same class twice
128
129 bool nameExists = false;
130
132
133 if (!instance) {
135 "Unsuccessful attempt at registering FieldIO class. "
136 "(Creation function returned null pointer)");
137 return;
138 }
139
140 string className = instance->className();
141
142 FieldIOFuncMap::const_iterator i = m_fieldIOs.find(className);
143 if (i != m_fieldIOs.end())
144 nameExists = true;
145
146 if (!nameExists) {
147 m_fieldIOs[className] = createFunc;
148 // if the simple (untemplated) class name hasn't been registered
149 // yet, add it to the list and print a message
150 if (find(m_fieldIONames.begin(), m_fieldIONames.end(),
151 className) == m_fieldIONames.end()) {
152 m_fieldIONames.push_back(className);
153 char *debugEnvVar = getenv("FIELD3D_DEBUG");
154 if (debugEnvVar) {
155 Msg::print("Registered FieldIO class " + className);
156 }
157 }
158 }
159
160}
NameVec m_fieldIONames
FieldIOFuncMap m_fieldIOs
Map of create functions for FieldIO classes. The key is the class name.
boost::intrusive_ptr< FieldIO > Ptr
Definition FieldIO.h:91

References FIELD3D_MTX_T, m_fieldIONames, m_fieldIOs, Msg::print(), and Msg::SevWarning.

◆ createFieldIO()

FieldIO::Ptr ClassFactory::createFieldIO ( const std::string & className) const

Instances an IO object by name.

Definition at line 165 of file ClassFactory.cpp.

166{
167// FieldIOFuncMap::const_iterator m = m_fieldIOs.begin();
168 FieldIOFuncMap::const_iterator i = m_fieldIOs.find(className);
169 if (i != m_fieldIOs.end())
170 return i->second();
171 else
172 return FieldIO::Ptr();
173}

References FIELD3D_MTX_T, and m_fieldIOs.

◆ registerFieldMapping()

void ClassFactory::registerFieldMapping ( CreateFieldMappingFnPtr createFunc)

Registers a class with the class pool.

Parameters
createFuncPointer to creation function

Definition at line 177 of file ClassFactory.cpp.

178{
179 // Make sure we don't add the same class twice
180
181 bool nameExists = false;
182
184
185 if (!instance) {
187 "Unsuccessful attempt at registering FieldMapping class. "
188 "(Creation function returned null pointer)");
189 return;
190 }
191
192 string className = instance->className();
193
194 FieldMappingFuncMap::const_iterator i = m_mappings.find(className);
195 if (i != m_mappings.end())
196 nameExists = true;
197
198 if (!nameExists) {
199 m_mappings[className] = createFunc;
200 // if the simple (untemplated) class name hasn't been registered
201 // yet, add it to the list and print a message
203 className) == m_fieldMappingNames.end()) {
204 m_fieldMappingNames.push_back(className);
205 char *debugEnvVar = getenv("FIELD3D_DEBUG");
206 if (debugEnvVar) {
207 Msg::print("Registered FieldMapping class " + className);
208 }
209 }
210 }
211}
FieldMappingFuncMap m_mappings
Map of create functions for FieldMappings. The key is the class name.
NameVec m_fieldMappingNames
boost::intrusive_ptr< FieldMapping > Ptr

References FIELD3D_MTX_T, m_fieldMappingNames, m_mappings, Msg::print(), and Msg::SevWarning.

◆ createFieldMapping()

FieldMapping::Ptr ClassFactory::createFieldMapping ( const std::string & className) const

Instances an object by name.

Definition at line 216 of file ClassFactory.cpp.

217{
218 FieldMappingFuncMap::const_iterator i = m_mappings.find(className);
219 if (i != m_mappings.end())
220 return i->second();
221 else
222 return FieldMapping::Ptr();
223}

References FIELD3D_MTX_T, and m_mappings.

◆ registerFieldMappingIO()

void ClassFactory::registerFieldMappingIO ( CreateFieldMappingIOFnPtr createFunc)

Registers an IO class with the class pool.

Parameters
createFuncPointer to creation function

Definition at line 227 of file ClassFactory.cpp.

228{
229 // Make sure we don't add the same class twice
230
231 bool nameExists = false;
232
234
235 if (!instance) {
237 "Unsuccessful attempt at registering FieldMappingIO class. "
238 "(Creation function returned null pointer)");
239 return;
240 }
241
242 string className = instance->className();
243
244 FieldMappingIOFuncMap::const_iterator i = m_mappingIOs.find(className);
245 if (i != m_mappingIOs.end())
246 nameExists = true;
247
248 if (!nameExists) {
249 m_mappingIOs[className] = createFunc;
250 // if the simple (untemplated) class name hasn't been registered
251 // yet, add it to the list and print a message
253 className) == m_fieldMappingNames.end()) {
254 m_fieldMappingNames.push_back(className);
255 char *debugEnvVar = getenv("FIELD3D_DEBUG");
256 if (debugEnvVar) {
257 Msg::print("Registered FieldMappingIO class " + className);
258 }
259 }
260 }
261}
FieldMappingIOFuncMap m_mappingIOs
Map of create functions for FieldMapping IO classes. The key is the class name.
boost::intrusive_ptr< FieldMappingIO > Ptr

References FIELD3D_MTX_T, m_fieldMappingNames, m_mappingIOs, Msg::print(), and Msg::SevWarning.

◆ createFieldMappingIO()

FieldMappingIO::Ptr ClassFactory::createFieldMappingIO ( const std::string & className) const

Instances an IO object by name.

Definition at line 266 of file ClassFactory.cpp.

267{
268 FieldMappingIOFuncMap::const_iterator i = m_mappingIOs.find(className);
269 if (i != m_mappingIOs.end())
270 return i->second();
271 else
272 return FieldMappingIO::Ptr();
273}

References FIELD3D_MTX_T, and m_mappingIOs.

◆ singleton()

ClassFactory & ClassFactory::singleton ( )
static

}

Access point for the singleton instance.

Definition at line 278 of file ClassFactory.cpp.

279{
280 if (ms_instance.get() == NULL) {
281 ms_instance.reset(new ClassFactory);
282 }
283 return *ms_instance;
284}
static boost::scoped_ptr< ClassFactory > ms_instance
Pointer to static instance.

References FIELD3D_MTX_T, and ms_instance.

Referenced by initIO(), PluginLoader::loadPlugins(), readField(), readFieldMapping(), writeField(), writeFieldMapping(), and Field3DOutputFile::writeMapping().

Member Data Documentation

◆ m_fields

FieldFuncMap ClassFactory::m_fields
private

Map of create functions for Fields. The key is the class name.

Definition at line 144 of file ClassFactory.h.

Referenced by createField(), and registerField().

◆ m_fieldNames

NameVec ClassFactory::m_fieldNames
private

Definition at line 146 of file ClassFactory.h.

Referenced by registerField().

◆ m_fieldIOs

FieldIOFuncMap ClassFactory::m_fieldIOs
private

Map of create functions for FieldIO classes. The key is the class name.

Definition at line 149 of file ClassFactory.h.

Referenced by createFieldIO(), and registerFieldIO().

◆ m_fieldIONames

NameVec ClassFactory::m_fieldIONames
private

Definition at line 151 of file ClassFactory.h.

Referenced by registerFieldIO().

◆ m_mappings

FieldMappingFuncMap ClassFactory::m_mappings
private

Map of create functions for FieldMappings. The key is the class name.

Definition at line 154 of file ClassFactory.h.

Referenced by createFieldMapping(), and registerFieldMapping().

◆ m_fieldMappingNames

NameVec ClassFactory::m_fieldMappingNames
private

Definition at line 156 of file ClassFactory.h.

Referenced by registerFieldMapping(), and registerFieldMappingIO().

◆ m_mappingIOs

FieldMappingIOFuncMap ClassFactory::m_mappingIOs
private

Map of create functions for FieldMapping IO classes.
The key is the class name.

Definition at line 160 of file ClassFactory.h.

Referenced by createFieldMappingIO(), and registerFieldMappingIO().

◆ m_fieldMappingIONames

NameVec ClassFactory::m_fieldMappingIONames
private

Definition at line 162 of file ClassFactory.h.

◆ ms_instance

FIELD3D_NAMESPACE_OPEN boost::scoped_ptr< ClassFactory > ClassFactory::ms_instance
staticprivate

Pointer to static instance.

Definition at line 165 of file ClassFactory.h.

Referenced by singleton().


The documentation for this class was generated from the following files: