ClassFactory Class Reference
Classes and functions used to implement this library » Field classes under-the-hood

`#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 boost::scoped_ptr< ClassFactory > | ms_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 ClassFactory & | singleton ()
| }

## 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

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

private

Definition at line 137 of file ClassFactory.h.

## FieldMappingFuncMap

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

private

Definition at line 138 of file ClassFactory.h.

## FieldMappingIOFuncMap

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

private

Definition at line 139 of file ClassFactory.h.

## Constructor & Destructor Documentation

## ClassFactory()

ClassFactory::ClassFactory | ( |  | ) |

Standard constructor.

Definition at line 65 of file ClassFactory.cpp.

{
PluginLoader::loadPlugins();
}
PluginLoader::loadPlugins
static void loadPlugins()
Checks all paths in $FIELD3D_DSO_PATH and loads the plugins it finds.
Definition PluginLoader.cpp:252

References PluginLoader::loadPlugins().

Referenced by singleton().

## Member Function Documentation

## registerField()

void ClassFactory::registerField | ( | CreateFieldFnPtr | createFunc | ) |

Registers a class with the class pool.

Parameters

  createFunc | Pointer to creation function

Definition at line 72 of file ClassFactory.cpp.

{
// Make sure we don't add the same class twice
bool nameExists = false;
FieldRes::Ptr instance = createFunc();
if (!instance) {
Msg::print(Msg::SevWarning,
"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);
}
}
}
}
ClassFactory::m_fields
FieldFuncMap m_fields
Map of create functions for Fields. The key is the class name.
Definition ClassFactory.h:144
ClassFactory::m_fieldNames
NameVec m_fieldNames
Definition ClassFactory.h:146
FieldRes::Ptr
boost::intrusive_ptr< FieldRes > Ptr
Definition Field.h:213
Msg::SevWarning
@ SevWarning
Definition Log.h:68
Msg::print
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 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.

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

References m_fields.

## registerFieldIO()

void ClassFactory::registerFieldIO | ( | CreateFieldIOFnPtr | createFunc | ) |

Registers an IO class with the class pool.

Parameters

  createFunc | Pointer to creation function

Definition at line 125 of file ClassFactory.cpp.

{
// Make sure we don't add the same class twice
bool nameExists = false;
FieldIO::Ptr instance = createFunc();
if (!instance) {
Msg::print(Msg::SevWarning,
"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);
}
}
}
}
ClassFactory::m_fieldIONames
NameVec m_fieldIONames
Definition ClassFactory.h:151
ClassFactory::m_fieldIOs
FieldIOFuncMap m_fieldIOs
Map of create functions for FieldIO classes. The key is the class name.
Definition ClassFactory.h:149
FieldIO::Ptr
boost::intrusive_ptr< FieldIO > Ptr
Definition FieldIO.h:91

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

Referenced by initIO().

## createFieldIO()

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

Instances an IO object by name.

Definition at line 165 of file ClassFactory.cpp.

{
// 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();
}

References m_fieldIOs.

Referenced by readField(), and writeField().

## registerFieldMapping()

void ClassFactory::registerFieldMapping | ( | CreateFieldMappingFnPtr | createFunc | ) |

Registers a class with the class pool.

Parameters

  createFunc | Pointer to creation function

Definition at line 177 of file ClassFactory.cpp.

{
// Make sure we don't add the same class twice
bool nameExists = false;
FieldMapping::Ptr instance = createFunc();
if (!instance) {
Msg::print(Msg::SevWarning,
"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);
}
}
}
}
ClassFactory::m_mappings
FieldMappingFuncMap m_mappings
Map of create functions for FieldMappings. The key is the class name.
Definition ClassFactory.h:154
ClassFactory::m_fieldMappingNames
NameVec m_fieldMappingNames
Definition ClassFactory.h:156
FieldMapping::Ptr
boost::intrusive_ptr< FieldMapping > Ptr
Definition FieldMapping.h:92

References 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.

{
FieldMappingFuncMap::const_iterator i = m_mappings.find(className);
if (i != m_mappings.end())
return i->second();
else
return FieldMapping::Ptr();
}

References m_mappings.

## registerFieldMappingIO()

void ClassFactory::registerFieldMappingIO | ( | CreateFieldMappingIOFnPtr | createFunc | ) |

Registers an IO class with the class pool.

Parameters

  createFunc | Pointer to creation function

Definition at line 227 of file ClassFactory.cpp.

{
// Make sure we don't add the same class twice
bool nameExists = false;
FieldMappingIO::Ptr instance = createFunc();
if (!instance) {
Msg::print(Msg::SevWarning,
"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);
}
}
}
}
ClassFactory::m_mappingIOs
FieldMappingIOFuncMap m_mappingIOs
Map of create functions for FieldMapping IO classes. The key is the class name.
Definition ClassFactory.h:160
FieldMappingIO::Ptr
boost::intrusive_ptr< FieldMappingIO > Ptr
Definition FieldMappingIO.h:71

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

Referenced by initIO().

## createFieldMappingIO()

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

Instances an IO object by name.

Definition at line 266 of file ClassFactory.cpp.

{
FieldMappingIOFuncMap::const_iterator i = m_mappingIOs.find(className);
if (i != m_mappingIOs.end())
return i->second();
else
return FieldMappingIO::Ptr();
}

References m_mappingIOs.

Referenced by readFieldMapping(), writeFieldMapping(), and Field3DOutputFile::writeMapping().

## singleton()

ClassFactory & ClassFactory::singleton | ( |  | ) |

static

}

Access point for the singleton instance.

Definition at line 278 of file ClassFactory.cpp.

{
if (ms_instance.get() == NULL) {
ms_instance.reset(new ClassFactory);
}
return *ms_instance;
}
ClassFactory::ClassFactory
ClassFactory()
Standard constructor.
Definition ClassFactory.cpp:65
ClassFactory::ms_instance
static boost::scoped_ptr< ClassFactory > ms_instance
Pointer to static instance.
Definition ClassFactory.h:165

References ClassFactory(), 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

static private

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:

- export/ClassFactory.h
- src/ClassFactory.cpp