Field3D
ClassFactory.h
Go to the documentation of this file.
1 //----------------------------------------------------------------------------//
2 
3 /*
4  * Copyright (c) 2009 Sony Pictures Imageworks Inc
5  *
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * Redistributions in binary form must reproduce the above copyright
15  * notice, this list of conditions and the following disclaimer in the
16  * documentation and/or other materials provided with the
17  * distribution. Neither the name of Sony Pictures Imageworks nor the
18  * names of its contributors may be used to endorse or promote
19  * products derived from this software without specific prior written
20  * permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
29  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
31  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
33  * OF THE POSSIBILITY OF SUCH DAMAGE.
34  */
35 
36 //----------------------------------------------------------------------------//
37 
42 //----------------------------------------------------------------------------//
43 
44 #ifndef _INCLUDED_Field3D_ClassFactory_H_
45 #define _INCLUDED_Field3D_ClassFactory_H_
46 
47 #include <map>
48 #include <vector>
49 
50 #include "Field.h"
51 #include "FieldIO.h"
52 #include "FieldMappingIO.h"
53 
54 //----------------------------------------------------------------------------//
55 
56 #include "ns.h"
57 
59 
60 //----------------------------------------------------------------------------//
61 // ClassFactory
62 //----------------------------------------------------------------------------//
63 
68 //----------------------------------------------------------------------------//
69 
71 {
72 
73 public:
74 
75  // Typedefs ------------------------------------------------------------------
76 
77  typedef FieldRes::Ptr (*CreateFieldFnPtr) ();
78  typedef FieldIO::Ptr (*CreateFieldIOFnPtr) ();
79  typedef FieldMapping::Ptr (*CreateFieldMappingFnPtr) ();
80  typedef FieldMappingIO::Ptr (*CreateFieldMappingIOFnPtr) ();
81 
82  // Ctors, dtor ---------------------------------------------------------------
83 
85  ClassFactory();
86 
87  // Main methods --------------------------------------------------------------
88 
91 
94  void registerField(CreateFieldFnPtr createFunc);
95 
97  FieldRes::Ptr createField(const std::string &className) const;
98 
101  void registerFieldIO(CreateFieldIOFnPtr createFunc);
102 
104  FieldIO::Ptr createFieldIO(const std::string &className) const;
105 
107 
110 
113  void registerFieldMapping(CreateFieldMappingFnPtr createFunc);
114 
116  FieldMapping::Ptr createFieldMapping(const std::string &className) const;
117 
120  void registerFieldMappingIO(CreateFieldMappingIOFnPtr createFunc);
121 
123  FieldMappingIO::Ptr createFieldMappingIO(const std::string &className) const;
124 
126 
128  static ClassFactory& singleton();
129 
130 private:
131 
132  // Typedefs ------------------------------------------------------------------
133 
134  typedef std::vector<std::string> NameVec;
135  typedef std::map<std::string, CreateFieldFnPtr> FieldFuncMap;
136  typedef std::map<std::string, CreateFieldIOFnPtr> FieldIOFuncMap;
137  typedef std::map<std::string, CreateFieldMappingFnPtr> FieldMappingFuncMap;
138  typedef std::map<std::string, CreateFieldMappingIOFnPtr> FieldMappingIOFuncMap;
139 
140  // Data members --------------------------------------------------------------
141 
146 
151 
156 
162 
165 
166 };
167 
168 //----------------------------------------------------------------------------//
169 
171 
172 //----------------------------------------------------------------------------//
173 
174 #endif // Include guard
FIELD3D_NAMESPACE_HEADER_CLOSE
#define FIELD3D_NAMESPACE_HEADER_CLOSE
Definition: ns.h:58
ClassFactory
Definition: ClassFactory.h:70
FieldMappingIO.h
Contains the FieldMappingIO base class and the NullFieldMappingIO and MatrixFieldMappingIO subclasses...
FieldMappingIO::Ptr
boost::intrusive_ptr< FieldMappingIO > Ptr
Definition: FieldMappingIO.h:71
FieldMapping::Ptr
boost::intrusive_ptr< FieldMapping > Ptr
Definition: FieldMapping.h:92
ClassFactory::m_fieldMappingIONames
NameVec m_fieldMappingIONames
Definition: ClassFactory.h:161
FieldIO.h
Contains FieldIO class.
ClassFactory::m_fieldIONames
NameVec m_fieldIONames
Definition: ClassFactory.h:150
ClassFactory::m_fieldIOs
FieldIOFuncMap m_fieldIOs
Map of create functions for FieldIO classes. The key is the class name.
Definition: ClassFactory.h:148
ClassFactory::m_mappings
FieldMappingFuncMap m_mappings
Map of create functions for FieldMappings. The key is the class name.
Definition: ClassFactory.h:153
ClassFactory::FieldMappingIOFuncMap
std::map< std::string, CreateFieldMappingIOFnPtr > FieldMappingIOFuncMap
Definition: ClassFactory.h:138
ns.h
FieldRes::Ptr
boost::intrusive_ptr< FieldRes > Ptr
Definition: Field.h:213
ClassFactory::ms_instance
static ClassFactory * ms_instance
Pointer to static instance.
Definition: ClassFactory.h:164
Field.h
Contains Field, WritableField and ResizableField classes.
ClassFactory::m_mappingIOs
FieldMappingIOFuncMap m_mappingIOs
Map of create functions for FieldMapping IO classes. The key is the class name.
Definition: ClassFactory.h:159
ClassFactory::m_fieldNames
NameVec m_fieldNames
Definition: ClassFactory.h:145
ClassFactory::FieldFuncMap
std::map< std::string, CreateFieldFnPtr > FieldFuncMap
Definition: ClassFactory.h:135
FieldIO::Ptr
boost::intrusive_ptr< FieldIO > Ptr
Definition: FieldIO.h:91
FIELD3D_API
#define FIELD3D_API
Definition: ns.h:77
ClassFactory::FieldIOFuncMap
std::map< std::string, CreateFieldIOFnPtr > FieldIOFuncMap
Definition: ClassFactory.h:136
FIELD3D_NAMESPACE_OPEN
Definition: FieldMapping.cpp:74
ClassFactory::FieldMappingFuncMap
std::map< std::string, CreateFieldMappingFnPtr > FieldMappingFuncMap
Definition: ClassFactory.h:137
ClassFactory::m_fieldMappingNames
NameVec m_fieldMappingNames
Definition: ClassFactory.h:155
ClassFactory::m_fields
FieldFuncMap m_fields
Map of create functions for Fields. The key is the class name.
Definition: ClassFactory.h:143
ClassFactory::NameVec
std::vector< std::string > NameVec
Definition: ClassFactory.h:134