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
74public:
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
131private:
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
Contains FieldIO class.
Contains the FieldMappingIO base class and the NullFieldMappingIO and MatrixFieldMappingIO subclasses...
Contains Field, WritableField and ResizableField classes.
std::map< std::string, CreateFieldMappingFnPtr > FieldMappingFuncMap
NameVec m_fieldIONames
std::vector< std::string > NameVec
FieldMappingIOFuncMap m_mappingIOs
Map of create functions for FieldMapping IO classes. The key is the class name.
std::map< std::string, CreateFieldFnPtr > FieldFuncMap
static boost::scoped_ptr< ClassFactory > ms_instance
Pointer to static instance.
NameVec m_fieldMappingIONames
std::map< std::string, CreateFieldIOFnPtr > FieldIOFuncMap
FieldMappingFuncMap m_mappings
Map of create functions for FieldMappings. The key is the class name.
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.
std::map< std::string, CreateFieldMappingIOFnPtr > FieldMappingIOFuncMap
NameVec m_fieldMappingNames
boost::intrusive_ptr< FieldIO > Ptr
Definition FieldIO.h:91
boost::intrusive_ptr< FieldMappingIO > Ptr
boost::intrusive_ptr< FieldMapping > Ptr
boost::intrusive_ptr< FieldRes > Ptr
Definition Field.h:213
#define FIELD3D_API
Definition ns.h:77
#define FIELD3D_NAMESPACE_HEADER_CLOSE
Definition ns.h:58