Field3D
ClassFactory Class Reference

#include <ClassFactory.h>

List of all members.

Public Types

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

Public Member Functions

 ClassFactory ()
 Standard constructor.
 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.
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
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.
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 ()
 }
static ClassFactorysingleton ()
 }

Detailed Description

Definition at line 70 of file ClassFactory.h.


Member Typedef Documentation

Definition at line 77 of file ClassFactory.h.

Definition at line 78 of file ClassFactory.h.

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

Definition at line 135 of file ClassFactory.h.

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

Definition at line 136 of file ClassFactory.h.

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

Definition at line 137 of file ClassFactory.h.

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

Definition at line 138 of file ClassFactory.h.

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

Definition at line 139 of file ClassFactory.h.

Definition at line 77 of file ClassFactory.h.

Definition at line 78 of file ClassFactory.h.

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

Definition at line 135 of file ClassFactory.h.

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

Definition at line 136 of file ClassFactory.h.

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

Definition at line 137 of file ClassFactory.h.

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

Definition at line 138 of file ClassFactory.h.

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

Definition at line 139 of file ClassFactory.h.


Constructor & Destructor Documentation

ClassFactory::ClassFactory ( )

Standard constructor.

Definition at line 65 of file ClassFactory.cpp.

References PluginLoader::loadPlugins().

ClassFactory::ClassFactory ( )

Standard constructor.


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) {
    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(),
             simpleClassName) == m_fieldNames.end()) {
      m_fieldNames.push_back(simpleClassName);
      char *debugEnvVar = getenv("FIELD3D_DEBUG");
      if (debugEnvVar) {
        Msg::print("Registered Field class " + simpleClassName);
      }
    }

  } 

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

Instances an object by name.

Definition at line 115 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 126 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) {
    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);
      }
    }

  } 

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

Instances an IO object by name.

Definition at line 167 of file ClassFactory.cpp.

Referenced by readField(), and writeField().

{
  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 178 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) {
    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);
      }
    }
  } 
}
FieldMapping::Ptr ClassFactory::createFieldMapping ( const std::string &  className) const

Instances an object by name.

Definition at line 217 of file ClassFactory.cpp.

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

Registers an IO class with the class pool.

Parameters:
createFuncPointer to creation function

Definition at line 228 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) {
    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);
      }
    }
  } 
}
FieldMappingIO::Ptr ClassFactory::createFieldMappingIO ( const std::string &  className) const

Instances an IO object by name.

Definition at line 267 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
    return FieldMappingIO::Ptr();
}
ClassFactory & ClassFactory::singleton ( ) [static]

}

Access point for the singleton instance.

Definition at line 279 of file ClassFactory.cpp.

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

{ 
  if (!ms_instance)
    ms_instance = new ClassFactory;
  return *ms_instance;
}
void ClassFactory::registerField ( CreateFieldFnPtr  createFunc)

Registers a class with the class pool.

Parameters:
createFuncPointer to creation function
FieldRes::Ptr ClassFactory::createField ( const std::string &  className) const

Instances an object by name.

void ClassFactory::registerFieldIO ( CreateFieldIOFnPtr  createFunc)

Registers an IO class with the class pool.

Parameters:
createFuncPointer to creation function
FieldIO::Ptr ClassFactory::createFieldIO ( const std::string &  className) const

Instances an IO object by name.

void ClassFactory::registerFieldMapping ( CreateFieldMappingFnPtr  createFunc)

Registers a class with the class pool.

Parameters:
createFuncPointer to creation function
FieldMapping::Ptr ClassFactory::createFieldMapping ( const std::string &  className) const

Instances an object by name.

void ClassFactory::registerFieldMappingIO ( CreateFieldMappingIOFnPtr  createFunc)

Registers an IO class with the class pool.

Parameters:
createFuncPointer to creation function
FieldMappingIO::Ptr ClassFactory::createFieldMappingIO ( const std::string &  className) const

Instances an IO object by name.

static ClassFactory& ClassFactory::singleton ( ) [static]

}

Access point for the singleton instance.


Member Data Documentation

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

Definition at line 144 of file ClassFactory.h.

Definition at line 146 of file ClassFactory.h.

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

Definition at line 149 of file ClassFactory.h.

Definition at line 151 of file ClassFactory.h.

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

Definition at line 154 of file ClassFactory.h.

Definition at line 156 of file ClassFactory.h.

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

Definition at line 160 of file ClassFactory.h.

Definition at line 162 of file ClassFactory.h.

FIELD3D_NAMESPACE_OPEN ClassFactory * ClassFactory::ms_instance = NULL [static, private]

Pointer to static instance.

Definition at line 166 of file ClassFactory.h.


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