ClassFactory.h
Go to the documentation of this file.
//----------------------------------------------------------------------------//
/*
* Copyright (c) 2009 Sony Pictures Imageworks Inc
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the
* distribution. Neither the name of Sony Pictures Imageworks nor the
* names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
//----------------------------------------------------------------------------//
//----------------------------------------------------------------------------//
#ifndef _INCLUDED_Field3D_ClassFactory_H_
#define _INCLUDED_Field3D_ClassFactory_H_
#include <boost/scoped_ptr.hpp>
#include <map>
#include <vector>
#include "Field.h"
#include "FieldIO.h"
#include "FieldMappingIO.h"
//----------------------------------------------------------------------------//
#include "ns.h"
FIELD3D_NAMESPACE_OPEN
//----------------------------------------------------------------------------//
// ClassFactory
//----------------------------------------------------------------------------//
//----------------------------------------------------------------------------//
class FIELD3D_API ClassFactory
{
public:
// Typedefs ------------------------------------------------------------------
typedef FieldRes::Ptr (*CreateFieldFnPtr) ();
typedef FieldIO::Ptr (*CreateFieldIOFnPtr) ();
typedef FieldMapping::Ptr (*CreateFieldMappingFnPtr) ();
typedef FieldMappingIO::Ptr (*CreateFieldMappingIOFnPtr) ();
// Ctors, dtor ---------------------------------------------------------------
ClassFactory();
// Main methods --------------------------------------------------------------
void registerField(CreateFieldFnPtr createFunc);
FieldRes::Ptr createField(const std::string &className) const;
void registerFieldIO(CreateFieldIOFnPtr createFunc);
FieldIO::Ptr createFieldIO(const std::string &className) const;
void registerFieldMapping(CreateFieldMappingFnPtr createFunc);
FieldMapping::Ptr createFieldMapping(const std::string &className) const;
void registerFieldMappingIO(CreateFieldMappingIOFnPtr createFunc);
FieldMappingIO::Ptr createFieldMappingIO(const std::string &className) const;
static ClassFactory& singleton();
private:
// Typedefs ------------------------------------------------------------------
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;
// Data members --------------------------------------------------------------
FieldFuncMap m_fields;
NameVec m_fieldNames;
FieldIOFuncMap m_fieldIOs;
NameVec m_fieldIONames;
FieldMappingFuncMap m_mappings;
NameVec m_fieldMappingNames;
FieldMappingIOFuncMap m_mappingIOs;
NameVec m_fieldMappingIONames;
static boost::scoped_ptr<ClassFactory> ms_instance;
};
//----------------------------------------------------------------------------//
FIELD3D_NAMESPACE_HEADER_CLOSE
//----------------------------------------------------------------------------//
#endif // Include guard
FieldIO.h
Contains FieldIO class.
FieldMappingIO.h
Contains the FieldMappingIO base class and the NullFieldMappingIO and MatrixFieldMappingIO subclasses...
Field.h
Contains Field, WritableField and ResizableField classes.
ClassFactory::FieldMappingFuncMap
std::map< std::string, CreateFieldMappingFnPtr > FieldMappingFuncMap
Definition ClassFactory.h:138
ClassFactory::CreateFieldIOFnPtr
FieldIO::Ptr(* CreateFieldIOFnPtr)()
Definition ClassFactory.h:79
ClassFactory::m_fieldIONames
NameVec m_fieldIONames
Definition ClassFactory.h:151
ClassFactory::createField
FieldRes::Ptr createField(const std::string &className) const
Instances an object by name.
Definition ClassFactory.cpp:114
ClassFactory::createFieldIO
FieldIO::Ptr createFieldIO(const std::string &className) const
Instances an IO object by name.
Definition ClassFactory.cpp:165
ClassFactory::singleton
static ClassFactory & singleton()
}
Definition ClassFactory.cpp:278
ClassFactory::NameVec
std::vector< std::string > NameVec
Definition ClassFactory.h:135
ClassFactory::ClassFactory
ClassFactory()
Standard constructor.
Definition ClassFactory.cpp:65
ClassFactory::CreateFieldMappingIOFnPtr
FieldMappingIO::Ptr(* CreateFieldMappingIOFnPtr)()
Definition ClassFactory.h:81
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::createFieldMapping
FieldMapping::Ptr createFieldMapping(const std::string &className) const
Instances an object by name.
Definition ClassFactory.cpp:216
ClassFactory::createFieldMappingIO
FieldMappingIO::Ptr createFieldMappingIO(const std::string &className) const
Instances an IO object by name.
Definition ClassFactory.cpp:266
ClassFactory::FieldFuncMap
std::map< std::string, CreateFieldFnPtr > FieldFuncMap
Definition ClassFactory.h:136
ClassFactory::ms_instance
static boost::scoped_ptr< ClassFactory > ms_instance
Pointer to static instance.
Definition ClassFactory.h:165
ClassFactory::CreateFieldFnPtr
FieldRes::Ptr(* CreateFieldFnPtr)()
Definition ClassFactory.h:78
ClassFactory::registerField
void registerField(CreateFieldFnPtr createFunc)
Registers a class with the class pool.
Definition ClassFactory.cpp:72
ClassFactory::registerFieldMapping
void registerFieldMapping(CreateFieldMappingFnPtr createFunc)
Registers a class with the class pool.
Definition ClassFactory.cpp:177
ClassFactory::registerFieldIO
void registerFieldIO(CreateFieldIOFnPtr createFunc)
Registers an IO class with the class pool.
Definition ClassFactory.cpp:125
ClassFactory::registerFieldMappingIO
void registerFieldMappingIO(CreateFieldMappingIOFnPtr createFunc)
Registers an IO class with the class pool.
Definition ClassFactory.cpp:227
ClassFactory::m_fieldMappingIONames
NameVec m_fieldMappingIONames
Definition ClassFactory.h:162
ClassFactory::FieldIOFuncMap
std::map< std::string, CreateFieldIOFnPtr > FieldIOFuncMap
Definition ClassFactory.h:137
ClassFactory::m_mappings
FieldMappingFuncMap m_mappings
Map of create functions for FieldMappings. The key is the class name.
Definition ClassFactory.h:154
ClassFactory::m_fields
FieldFuncMap m_fields
Map of create functions for Fields. The key is the class name.
Definition ClassFactory.h:144
ClassFactory::m_fieldNames
NameVec m_fieldNames
Definition ClassFactory.h:146
ClassFactory::m_fieldIOs
FieldIOFuncMap m_fieldIOs
Map of create functions for FieldIO classes. The key is the class name.
Definition ClassFactory.h:149
ClassFactory::CreateFieldMappingFnPtr
FieldMapping::Ptr(* CreateFieldMappingFnPtr)()
Definition ClassFactory.h:80
ClassFactory::FieldMappingIOFuncMap
std::map< std::string, CreateFieldMappingIOFnPtr > FieldMappingIOFuncMap
Definition ClassFactory.h:139
ClassFactory::m_fieldMappingNames
NameVec m_fieldMappingNames
Definition ClassFactory.h:156
FieldIO::Ptr
boost::intrusive_ptr< FieldIO > Ptr
Definition FieldIO.h:91
FieldMappingIO::Ptr
boost::intrusive_ptr< FieldMappingIO > Ptr
Definition FieldMappingIO.h:71
FieldMapping::Ptr
boost::intrusive_ptr< FieldMapping > Ptr
Definition FieldMapping.h:92
FieldRes::Ptr
boost::intrusive_ptr< FieldRes > Ptr
Definition Field.h:213
FIELD3D_NAMESPACE_OPEN
Definition FieldMapping.cpp:74
ns.h
FIELD3D_API
#define FIELD3D_API
Definition ns.h:77
FIELD3D_NAMESPACE_HEADER_CLOSE
#define FIELD3D_NAMESPACE_HEADER_CLOSE
Definition ns.h:58