Field3D
ClassFactory Class Reference

#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,
CreateFieldFnPtr
FieldFuncMap
typedef std::map< std::string,
CreateFieldIOFnPtr
FieldIOFuncMap
typedef std::map< std::string,
CreateFieldMappingFnPtr
FieldMappingFuncMap
typedef std::map< std::string,
CreateFieldMappingIOFnPtr
FieldMappingIOFuncMap
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 ClassFactoryms_instance = NULL
 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 70 of file ClassFactory.h.

Member Typedef Documentation

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

Definition at line 77 of file ClassFactory.h.

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

Definition at line 78 of file ClassFactory.h.

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

Definition at line 79 of file ClassFactory.h.

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

Definition at line 80 of file ClassFactory.h.

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

Definition at line 134 of file ClassFactory.h.

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

Definition at line 135 of file ClassFactory.h.

typedef std::map<std::string, CreateFieldIOFnPtr> ClassFactory::FieldIOFuncMap
private

Definition at line 136 of file ClassFactory.h.

typedef std::map<std::string, CreateFieldMappingFnPtr> ClassFactory::FieldMappingFuncMap
private

Definition at line 137 of file ClassFactory.h.

typedef std::map<std::string, CreateFieldMappingIOFnPtr> ClassFactory::FieldMappingIOFuncMap
private

Definition at line 138 of file ClassFactory.h.

Constructor & Destructor Documentation

ClassFactory::ClassFactory ( )

Standard constructor.

Definition at line 65 of file ClassFactory.cpp.

References PluginLoader::loadPlugins().

Member Function Documentation

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.

References Msg::print(), and Msg::SevWarning.

{
// Make sure we don't add the same class twice
bool nameExists = false;
FieldRes::Ptr instance = createFunc();
if (!instance) {
"Unsuccessful attempt at registering Field class. "
"(Creation function returned null pointer)");
return;
}
string simpleClassName = instance->className();
string dataTypeName = instance->dataTypeString();
string className = simpleClassName + "<" + dataTypeName + ">";
FieldFuncMap::const_iterator i = m_fields.find(className);
if (i != m_fields.end())
nameExists = true;
if (!nameExists) {
m_fields[className] = createFunc;
// if the simple (untemplated) class name hasn't been registered
// yet, add it to the list and print a message
if (find(m_fieldNames.begin(), m_fieldNames.end(),
className) == m_fieldNames.end()) {
m_fieldNames.push_back(className);
char *debugEnvVar = getenv("FIELD3D_DEBUG");
if (debugEnvVar) {
Msg::print("Registered Field class " + className);
}
}
}
}
FieldRes::Ptr ClassFactory::createField ( const std::string &  className) const

Instances an object by name.

Definition at line 114 of file ClassFactory.cpp.

{
FieldFuncMap::const_iterator i = m_fields.find(className);
if (i != m_fields.end())
return i->second();
else
return FieldRes::Ptr();
}
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.

References Msg::print(), and Msg::SevWarning.

Referenced by initIO().

{
// Make sure we don't add the same class twice
bool nameExists = false;
FieldIO::Ptr instance = createFunc();
if (!instance) {
"Unsuccessful attempt at registering FieldIO class. "
"(Creation function returned null pointer)");
return;
}
string className = instance->className();
FieldIOFuncMap::const_iterator i = m_fieldIOs.find(className);
if (i != m_fieldIOs.end())
nameExists = true;
if (!nameExists) {
m_fieldIOs[className] = createFunc;
// if the simple (untemplated) class name hasn't been registered
// yet, add it to the list and print a message
if (find(m_fieldIONames.begin(), m_fieldIONames.end(),
className) == m_fieldIONames.end()) {
m_fieldIONames.push_back(className);
char *debugEnvVar = getenv("FIELD3D_DEBUG");
if (debugEnvVar) {
Msg::print("Registered FieldIO class " + className);
}
}
}
}
FieldIO::Ptr ClassFactory::createFieldIO ( const std::string &  className) const

Instances an IO object by name.

Definition at line 165 of file ClassFactory.cpp.

Referenced by readField(), and writeField().

{
FieldIOFuncMap::const_iterator m = m_fieldIOs.begin();
FieldIOFuncMap::const_iterator i = m_fieldIOs.find(className);
if (i != m_fieldIOs.end())
return i->second();
else
return FieldIO::Ptr();
}
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.

References Msg::print(), and Msg::SevWarning.

{
// Make sure we don't add the same class twice
bool nameExists = false;
FieldMapping::Ptr instance = createFunc();
if (!instance) {
"Unsuccessful attempt at registering FieldMapping class. "
"(Creation function returned null pointer)");
return;
}
string className = instance->className();
FieldMappingFuncMap::const_iterator i = m_mappings.find(className);
if (i != m_mappings.end())
nameExists = true;
if (!nameExists) {
m_mappings[className] = createFunc;
// if the simple (untemplated) class name hasn't been registered
// yet, add it to the list and print a message
if (find(m_fieldMappingNames.begin(), m_fieldMappingNames.end(),
className) == m_fieldMappingNames.end()) {
m_fieldMappingNames.push_back(className);
char *debugEnvVar = getenv("FIELD3D_DEBUG");
if (debugEnvVar) {
Msg::print("Registered FieldMapping class " + className);
}
}
}
}
FieldMapping::Ptr ClassFactory::createFieldMapping ( const std::string &  className) const

Instances an object by name.

Definition at line 216 of file ClassFactory.cpp.

{
FieldMappingFuncMap::const_iterator i = m_mappings.find(className);
if (i != m_mappings.end())
return i->second();
else
}
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.

References Msg::print(), and Msg::SevWarning.

Referenced by initIO().

{
// Make sure we don't add the same class twice
bool nameExists = false;
FieldMappingIO::Ptr instance = createFunc();
if (!instance) {
"Unsuccessful attempt at registering FieldMappingIO class. "
"(Creation function returned null pointer)");
return;
}
string className = instance->className();
FieldMappingIOFuncMap::const_iterator i = m_mappingIOs.find(className);
if (i != m_mappingIOs.end())
nameExists = true;
if (!nameExists) {
m_mappingIOs[className] = createFunc;
// if the simple (untemplated) class name hasn't been registered
// yet, add it to the list and print a message
if (find(m_fieldMappingNames.begin(), m_fieldMappingNames.end(),
className) == m_fieldMappingNames.end()) {
m_fieldMappingNames.push_back(className);
char *debugEnvVar = getenv("FIELD3D_DEBUG");
if (debugEnvVar) {
Msg::print("Registered FieldMappingIO class " + className);
}
}
}
}
FieldMappingIO::Ptr ClassFactory::createFieldMappingIO ( const std::string &  className) const

Instances an IO object by name.

Definition at line 266 of file ClassFactory.cpp.

Referenced by readFieldMapping(), and writeFieldMapping().

{
FieldMappingIOFuncMap::const_iterator i = m_mappingIOs.find(className);
if (i != m_mappingIOs.end())
return i->second();
else
}
ClassFactory & ClassFactory::singleton ( )
static

}

Access point for the singleton instance.

Definition at line 278 of file ClassFactory.cpp.

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

{
return *ms_instance;
}

Member Data Documentation

FieldFuncMap ClassFactory::m_fields
private

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

Definition at line 143 of file ClassFactory.h.

NameVec ClassFactory::m_fieldNames
private

Definition at line 145 of file ClassFactory.h.

FieldIOFuncMap ClassFactory::m_fieldIOs
private

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

Definition at line 148 of file ClassFactory.h.

NameVec ClassFactory::m_fieldIONames
private

Definition at line 150 of file ClassFactory.h.

FieldMappingFuncMap ClassFactory::m_mappings
private

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

Definition at line 153 of file ClassFactory.h.

NameVec ClassFactory::m_fieldMappingNames
private

Definition at line 155 of file ClassFactory.h.

FieldMappingIOFuncMap ClassFactory::m_mappingIOs
private

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

Definition at line 159 of file ClassFactory.h.

NameVec ClassFactory::m_fieldMappingIONames
private

Definition at line 161 of file ClassFactory.h.

FIELD3D_NAMESPACE_OPEN ClassFactory * ClassFactory::ms_instance = NULL
staticprivate

Pointer to static instance.

Definition at line 164 of file ClassFactory.h.


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