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. More...
 
Field class
void registerField (CreateFieldFnPtr createFunc)
 Registers a class with the class pool. More...
 
FieldRes::Ptr createField (const std::string &className) const
 Instances an object by name. More...
 
void registerFieldIO (CreateFieldIOFnPtr createFunc)
 Registers an IO class with the class pool. More...
 
FieldIO::Ptr createFieldIO (const std::string &className) const
 Instances an IO object by name. More...
 

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. More...
 
NameVec m_fieldNames
 
FieldIOFuncMap m_fieldIOs
 Map of create functions for FieldIO classes. The key is the class name. More...
 
NameVec m_fieldIONames
 
FieldMappingFuncMap m_mappings
 Map of create functions for FieldMappings. The key is the class name. More...
 
NameVec m_fieldMappingNames
 
FieldMappingIOFuncMap m_mappingIOs
 Map of create functions for FieldMapping IO classes.
The key is the class name. More...
 
NameVec m_fieldMappingIONames
 
static boost::scoped_ptr< ClassFactoryms_instance
 Pointer to static instance. More...
 
void registerFieldMapping (CreateFieldMappingFnPtr createFunc)
 Registers a class with the class pool. More...
 
FieldMapping::Ptr createFieldMapping (const std::string &className) const
 Instances an object by name. More...
 
void registerFieldMappingIO (CreateFieldMappingIOFnPtr createFunc)
 Registers an IO class with the class pool. More...
 
FieldMappingIO::Ptr createFieldMappingIO (const std::string &className) const
 Instances an IO object by name. More...
 
static ClassFactorysingleton ()
 } More...
 

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.

66 {
68 }

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 
78  FieldRes::Ptr instance = createFunc();
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 }

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

◆ 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 
131  FieldIO::Ptr instance = createFunc();
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 }

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

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 }

Referenced by readField(), and writeField().

◆ 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 
183  FieldMapping::Ptr instance = createFunc();
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
202  if (find(m_fieldMappingNames.begin(), m_fieldMappingNames.end(),
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 }

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

◆ 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 
233  FieldMappingIO::Ptr instance = createFunc();
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
252  if (find(m_fieldMappingNames.begin(), m_fieldMappingNames.end(),
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 }

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

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 }

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.

279 {
280  if (ms_instance.get() == NULL) {
281  ms_instance.reset(new ClassFactory);
282  }
283  return *ms_instance;
284 }

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.

◆ m_fieldNames

NameVec ClassFactory::m_fieldNames
private

Definition at line 146 of file ClassFactory.h.

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

◆ m_fieldIONames

NameVec ClassFactory::m_fieldIONames
private

Definition at line 151 of file ClassFactory.h.

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

◆ m_fieldMappingNames

NameVec ClassFactory::m_fieldMappingNames
private

Definition at line 156 of file ClassFactory.h.

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

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


The documentation for this class was generated from the following files:
Msg::SevWarning
@ SevWarning
Definition: Log.h:68
ClassFactory
Definition: ClassFactory.h:72
PluginLoader::loadPlugins
static void loadPlugins()
Checks all paths in $FIELD3D_DSO_PATH and loads the plugins it finds.
Definition: PluginLoader.cpp:252
FieldMappingIO::Ptr
boost::intrusive_ptr< FieldMappingIO > Ptr
Definition: FieldMappingIO.h:71
FieldMapping::Ptr
boost::intrusive_ptr< FieldMapping > Ptr
Definition: FieldMapping.h:92
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
ClassFactory::m_mappings
FieldMappingFuncMap m_mappings
Map of create functions for FieldMappings. The key is the class name.
Definition: ClassFactory.h:154
FieldRes::Ptr
boost::intrusive_ptr< FieldRes > Ptr
Definition: Field.h:213
ClassFactory::ms_instance
static boost::scoped_ptr< ClassFactory > ms_instance
Pointer to static instance.
Definition: ClassFactory.h:165
ClassFactory::m_mappingIOs
FieldMappingIOFuncMap m_mappingIOs
Map of create functions for FieldMapping IO classes. The key is the class name.
Definition: ClassFactory.h:160
ClassFactory::m_fieldNames
NameVec m_fieldNames
Definition: ClassFactory.h:146
FieldIO::Ptr
boost::intrusive_ptr< FieldIO > Ptr
Definition: FieldIO.h:91
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
ClassFactory::m_fieldMappingNames
NameVec m_fieldMappingNames
Definition: ClassFactory.h:156
ClassFactory::m_fields
FieldFuncMap m_fields
Map of create functions for Fields. The key is the class name.
Definition: ClassFactory.h:144