Field3D
ClassFactory.h
Go to the documentation of this file.
00001 //----------------------------------------------------------------------------//
00002 
00003 /*
00004  * Copyright (c) 2009 Sony Pictures Imageworks Inc
00005  *
00006  * All rights reserved.
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted provided that the following conditions
00010  * are met:
00011  *
00012  * Redistributions of source code must retain the above copyright
00013  * notice, this list of conditions and the following disclaimer.
00014  * Redistributions in binary form must reproduce the above copyright
00015  * notice, this list of conditions and the following disclaimer in the
00016  * documentation and/or other materials provided with the
00017  * distribution.  Neither the name of Sony Pictures Imageworks nor the
00018  * names of its contributors may be used to endorse or promote
00019  * products derived from this software without specific prior written
00020  * permission.
00021  *
00022  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00023  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00024  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00025  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
00026  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00027  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00028  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00029  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00030  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
00031  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00032  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
00033  * OF THE POSSIBILITY OF SUCH DAMAGE.
00034  */
00035 
00036 //----------------------------------------------------------------------------//
00037 
00042 //----------------------------------------------------------------------------//
00043 
00044 #ifndef _INCLUDED_Field3D_ClassFactory_H_
00045 #define _INCLUDED_Field3D_ClassFactory_H_
00046 
00047 #include <map>
00048 #include <vector>
00049 
00050 #include "Field.h"
00051 #include "FieldIO.h"
00052 #include "FieldMappingIO.h"
00053 
00054 //----------------------------------------------------------------------------//
00055 
00056 #include "ns.h"
00057 
00058 FIELD3D_NAMESPACE_OPEN
00059 
00060 //----------------------------------------------------------------------------//
00061 // ClassFactory
00062 //----------------------------------------------------------------------------//
00063 
00068 //----------------------------------------------------------------------------//
00069   
00070 class ClassFactory
00071 {
00072     
00073 public:
00074     
00075   // Typedefs ------------------------------------------------------------------
00076 
00077   typedef FieldRes::Ptr (*CreateFieldFnPtr) ();
00078   typedef FieldIO::Ptr (*CreateFieldIOFnPtr) ();
00079   typedef FieldMapping::Ptr (*CreateFieldMappingFnPtr) ();
00080   typedef FieldMappingIO::Ptr (*CreateFieldMappingIOFnPtr) ();
00081 
00082   // Ctors, dtor ---------------------------------------------------------------
00083 
00085   ClassFactory();  
00086 
00087   // Main methods --------------------------------------------------------------
00088 
00091 
00094   void registerField(CreateFieldFnPtr createFunc);
00095 
00097   FieldRes::Ptr createField(const std::string &className) const;
00098 
00101   void registerFieldIO(CreateFieldIOFnPtr createFunc);
00102 
00104   FieldIO::Ptr createFieldIO(const std::string &className) const;
00105 
00107 
00110 
00113   void registerFieldMapping(CreateFieldMappingFnPtr createFunc);
00114 
00116   FieldMapping::Ptr createFieldMapping(const std::string &className) const;
00117 
00120   void registerFieldMappingIO(CreateFieldMappingIOFnPtr createFunc);
00121 
00123   FieldMappingIO::Ptr createFieldMappingIO(const std::string &className) const;
00124 
00126 
00128   static ClassFactory& singleton();
00129 
00130 private:
00131       
00132   // Typedefs ------------------------------------------------------------------
00133 
00134   typedef std::vector<std::string> NameVec;
00135   typedef std::map<std::string, CreateFieldFnPtr> FieldFuncMap;
00136   typedef std::map<std::string, CreateFieldIOFnPtr> FieldIOFuncMap;
00137   typedef std::map<std::string, CreateFieldMappingFnPtr> FieldMappingFuncMap;
00138   typedef std::map<std::string, CreateFieldMappingIOFnPtr> FieldMappingIOFuncMap;
00139 
00140   // Data members --------------------------------------------------------------
00141 
00143   FieldFuncMap m_fields;
00145   NameVec m_fieldNames;
00146 
00148   FieldIOFuncMap m_fieldIOs;
00150   NameVec m_fieldIONames;
00151 
00153   FieldMappingFuncMap m_mappings;
00155   NameVec m_fieldMappingNames;
00156 
00159   FieldMappingIOFuncMap m_mappingIOs;
00161   NameVec m_fieldMappingIONames;
00162 
00164   static ClassFactory *ms_instance;
00165 
00166 };
00167 
00168 //----------------------------------------------------------------------------//
00169 
00170 FIELD3D_NAMESPACE_HEADER_CLOSE
00171 
00172 //----------------------------------------------------------------------------//
00173 
00174 #endif // Include guard