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 <boost/scoped_ptr.hpp>
48 #include <map>
49 #include <vector>
50 
51 #include "Field.h"
52 #include "FieldIO.h"
53 #include "FieldMappingIO.h"
54 
55 //----------------------------------------------------------------------------//
56 
57 #include "ns.h"
58 
60 
61 //----------------------------------------------------------------------------//
62 // ClassFactory
63 //----------------------------------------------------------------------------//
64 
69 //----------------------------------------------------------------------------//
70 
72 {
73 
74 public:
75 
76  // Typedefs ------------------------------------------------------------------
77 
78  typedef FieldRes::Ptr (*CreateFieldFnPtr) ();
79  typedef FieldIO::Ptr (*CreateFieldIOFnPtr) ();
80  typedef FieldMapping::Ptr (*CreateFieldMappingFnPtr) ();
81  typedef FieldMappingIO::Ptr (*CreateFieldMappingIOFnPtr) ();
82 
83  // Ctors, dtor ---------------------------------------------------------------
84 
86  ClassFactory();
87 
88  // Main methods --------------------------------------------------------------
89 
92 
95  void registerField(CreateFieldFnPtr createFunc);
96 
98  FieldRes::Ptr createField(const std::string &className) const;
99 
102  void registerFieldIO(CreateFieldIOFnPtr createFunc);
103 
105  FieldIO::Ptr createFieldIO(const std::string &className) const;
106 
108 
111 
114  void registerFieldMapping(CreateFieldMappingFnPtr createFunc);
115 
117  FieldMapping::Ptr createFieldMapping(const std::string &className) const;
118 
121  void registerFieldMappingIO(CreateFieldMappingIOFnPtr createFunc);
122 
124  FieldMappingIO::Ptr createFieldMappingIO(const std::string &className) const;
125 
127 
129  static ClassFactory& singleton();
130 
131 private:
132 
133  // Typedefs ------------------------------------------------------------------
134 
135  typedef std::vector<std::string> NameVec;
136  typedef std::map<std::string, CreateFieldFnPtr> FieldFuncMap;
137  typedef std::map<std::string, CreateFieldIOFnPtr> FieldIOFuncMap;
138  typedef std::map<std::string, CreateFieldMappingFnPtr> FieldMappingFuncMap;
139  typedef std::map<std::string, CreateFieldMappingIOFnPtr> FieldMappingIOFuncMap;
140 
141  // Data members --------------------------------------------------------------
142 
147 
152 
157 
163 
165  static boost::scoped_ptr<ClassFactory> ms_instance;
166 
167 };
168 
169 //----------------------------------------------------------------------------//
170 
172 
173 //----------------------------------------------------------------------------//
174 
175 #endif // Include guard
FIELD3D_NAMESPACE_HEADER_CLOSE
#define FIELD3D_NAMESPACE_HEADER_CLOSE
Definition: ns.h:58
ClassFactory
Definition: ClassFactory.h:72
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:162
FieldIO.h
Contains FieldIO class.
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
ClassFactory::FieldMappingIOFuncMap
std::map< std::string, CreateFieldMappingIOFnPtr > FieldMappingIOFuncMap
Definition: ClassFactory.h:139
ns.h
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
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:160
ClassFactory::m_fieldNames
NameVec m_fieldNames
Definition: ClassFactory.h:146
ClassFactory::FieldFuncMap
std::map< std::string, CreateFieldFnPtr > FieldFuncMap
Definition: ClassFactory.h:136
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:137
FIELD3D_NAMESPACE_OPEN
Definition: FieldMapping.cpp:74
ClassFactory::FieldMappingFuncMap
std::map< std::string, CreateFieldMappingFnPtr > FieldMappingFuncMap
Definition: ClassFactory.h:138
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
ClassFactory::NameVec
std::vector< std::string > NameVec
Definition: ClassFactory.h:135