Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

OSGFieldFactory.cpp

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002  *                                OpenSG                                     *
00003  *                                                                           *
00004  *                                                                           *
00005  *             Copyright (C) 2000-2002 by the OpenSG Forum                   *
00006  *                                                                           *
00007  *                            www.opensg.org                                 *
00008  *                                                                           *
00009  *   contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de          *
00010  *                                                                           *
00011 \*---------------------------------------------------------------------------*/
00012 /*---------------------------------------------------------------------------*\
00013  *                                License                                    *
00014  *                                                                           *
00015  * This library is free software; you can redistribute it and/or modify it   *
00016  * under the terms of the GNU Library General Public License as published    *
00017  * by the Free Software Foundation, version 2.                               *
00018  *                                                                           *
00019  * This library is distributed in the hope that it will be useful, but       *
00020  * WITHOUT ANY WARRANTY; without even the implied warranty of                *
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         *
00022  * Library General Public License for more details.                          *
00023  *                                                                           *
00024  * You should have received a copy of the GNU Library General Public         *
00025  * License along with this library; if not, write to the Free Software       *
00026  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                 *
00027  *                                                                           *
00028 \*---------------------------------------------------------------------------*/
00029 /*---------------------------------------------------------------------------*\
00030  *                                Changes                                    *
00031  *                                                                           *
00032  *                                                                           *
00033  *                                                                           *
00034  *                                                                           *
00035  *                                                                           *
00036  *                                                                           *
00037 \*---------------------------------------------------------------------------*/
00038 
00039 #include <stdlib.h>
00040 #include <stdio.h>
00041 
00042 #include "OSGConfig.h"
00043 #include "OSGFieldFactory.h"
00044 #include "OSGFieldType.h"
00045 #include "OSGBaseFunctions.h"
00046 #include "OSGLog.h"
00047 
00048 OSG_USING_NAMESPACE
00049 
00050 /*-------------------------------------------------------------------------*/
00051 /*                            Class Variable                               */
00052 
00053 FieldFactory FieldFactory::_the;
00054 
00055 std::map<UInt32, FieldType *> *FieldFactory::_fieldTypeM  = NULL;
00056 
00057 /*-------------------------------------------------------------------------*/
00058 /*                             Destructor                                  */
00059 
00060 FieldFactory::~FieldFactory(void)
00061 {
00062     SINFO << "INFO: Destroy Singleton FieldFactory" << std::endl;
00063 }
00064 
00065 /*-------------------------------------------------------------------------*/
00066 /*                               Create                                    */
00067 
00068 Field *FieldFactory::createField(UInt32 typeId)
00069 {
00070     FieldType *pType = getFieldType(typeId);
00071 
00072 
00073     if((pType                != NULL) &&
00074        (pType->_createMethod != NULL))
00075     {
00076         return pType->_createMethod();
00077     }
00078     else
00079     {
00080         return NULL;
00081     }
00082 }
00083 
00084 Field *FieldFactory::createField(const Char8 *szName)
00085 {
00086     FieldType *pType          = getFieldType(szName);
00087 
00088     if((pType                != NULL) &&
00089        (pType->_createMethod != NULL))
00090     {
00091         return pType->_createMethod();
00092     }
00093     else
00094     {
00095         return NULL;
00096     }
00097 }
00098 
00099 /*-------------------------------------------------------------------------*/
00100 /*                                Get                                      */
00101 
00102 UInt32 FieldFactory::getNFieldTypes(void)
00103 {
00104     if(_fieldTypeM != NULL) 
00105         return _fieldTypeM->size();
00106 
00107     return 0;
00108 }
00109     
00110 FieldType *FieldFactory::getFieldType(const Char8 *szName)
00111 {
00112     std::map<UInt32, FieldType *>::iterator  mIt;
00113     FieldType                               *returnValue = NULL;
00114     
00115     if(_fieldTypeM != NULL) 
00116     {
00117         mIt = _fieldTypeM->begin();
00118 
00119         while(mIt != _fieldTypeM->end())
00120         {
00121             if(strcmp(szName, (*mIt).second->getCName()) == 0)
00122             {
00123                 returnValue = (*mIt).second;
00124                 break;
00125             }
00126             
00127             mIt++;
00128         }
00129     }
00130 
00131     return returnValue;
00132 }
00133 
00134 FieldType *FieldFactory::getFieldType(UInt32 typeId)
00135 {
00136     std::map<UInt32, FieldType *>::iterator  mIt;
00137 
00138     if(_fieldTypeM == NULL)
00139         return NULL;
00140    
00141     mIt = _fieldTypeM->find(typeId);
00142 
00143     if(mIt != _fieldTypeM->end())
00144     {
00145         return (*mIt).second;
00146     }
00147     else
00148     {
00149         return NULL;
00150     }
00151 }
00152 
00153 const Char8 *FieldFactory::getFieldTypeName(UInt32 typeId)
00154 {
00155     FieldType *pFieldType = getFieldType(typeId);
00156 
00157     return pFieldType ? pFieldType->getCName() : NULL;
00158 }
00159 
00160 /*-------------------------------------------------------------------------*/
00161 /*                                 the                                     */
00162 
00163 FieldFactory &FieldFactory::the(void)
00164 {
00165     return _the;
00166 }
00167 
00168 /*-------------------------------------------------------------------------*/
00169 /*                            Constructors                                 */
00170 
00171 FieldFactory::FieldFactory(void)
00172 {
00173 }
00174 
00175 /*-------------------------------------------------------------------------*/
00176 /*                                 Add                                     */
00177 
00178 #ifdef OSG_WIN32_ICL
00179 #pragma warning (disable : 383)
00180 #endif
00181 
00182 void FieldFactory::addType(FieldType *pType)
00183 {
00184     if(pType == NULL)
00185         return;
00186 
00187     if(getFieldType(pType->getId()) != NULL)
00188         return;
00189 
00190     if(_fieldTypeM == NULL)
00191         _fieldTypeM = new std::map<UInt32, FieldType *>();
00192 
00193     (*_fieldTypeM)[pType->getId()] = pType;
00194 }
00195 
00196 #ifdef OSG_WIN32_ICL
00197 #pragma warning (default : 383)
00198 #endif
00199 
00200 
00201 
00202 /*-------------------------------------------------------------------------*/
00203 /*                              cvs id's                                   */
00204 
00205 #ifdef __sgi
00206 #pragma set woff 1174
00207 #endif
00208 
00209 #ifdef OSG_LINUX_ICC
00210 #pragma warning( disable : 177 )
00211 #endif
00212 
00213 namespace 
00214 {
00215     static Char8 cvsid_cpp[] = "@(#)$Id: $";
00216     static Char8 cvsid_hpp[] = OSGFIELDFACTORY_HEADER_CVSID;
00217 }
00218 

Generated on Thu Aug 25 04:04:49 2005 for OpenSG by  doxygen 1.4.3