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 00044 #include <OSGTypeFactory.h> 00045 00046 #include <iostream> 00047 00048 OSG_BEGIN_NAMESPACE 00049 00050 00051 /*-------------------------- constructor ----------------------------------*/ 00052 00053 template <class MPFieldT> inline 00054 MPFieldStore<MPFieldT>::MPFieldStore(void) 00055 { 00056 } 00057 00058 /*--------------------------- destructor ----------------------------------*/ 00059 00060 template <class MPFieldT> inline 00061 MPFieldStore<MPFieldT>::~MPFieldStore(void) 00062 { 00063 } 00064 00065 /*------------------------------ access -----------------------------------*/ 00066 00067 template <class MPFieldT> inline 00068 MPFieldT *MPFieldStore<MPFieldT>::getMPField(const Char8 *szName, 00069 const Char8 *szTypeName) 00070 { 00071 MPFieldT *returnValue = NULL; 00072 MPFieldType *pElemType; 00073 00074 returnValue = findMPField(szName); 00075 00076 if(returnValue == NULL) 00077 { 00078 pElemType = findMPFieldType(szTypeName); 00079 00080 if(pElemType != NULL) 00081 { 00082 returnValue = pElemType->create(szName); 00083 00084 if(returnValue != NULL) 00085 { 00086 _mFieldMap[IDStringLink(returnValue->getCName())]= returnValue; 00087 } 00088 } 00089 else 00090 { 00091 PWARNING << "could not find type named : " << szName << std::endl; 00092 00093 returnValue = NULL; 00094 } 00095 } 00096 00097 return returnValue; 00098 } 00099 00100 00101 /*------------------------------- get -----------------------------------*/ 00102 00103 template <class MPFieldT> inline 00104 MPFieldT *MPFieldStore<MPFieldT>::findMPField(const Char8 *szName) 00105 { 00106 MPFieldMapIt gIt; 00107 00108 if(szName == NULL) 00109 return NULL; 00110 00111 gIt = _mFieldMap.find(IDStringLink(szName)); 00112 00113 if(gIt != _mFieldMap.end()) 00114 { 00115 return (*gIt).second; 00116 } 00117 else 00118 { 00119 return NULL; 00120 } 00121 } 00122 00123 template <class MPFieldT> inline 00124 void MPFieldStore<MPFieldT>::removeMPField(MPFieldT *pField) 00125 { 00126 if(pField == NULL) 00127 return; 00128 00129 MPFieldMapIt gIt = _mFieldMap.find(IDStringLink(pField->getCName())); 00130 00131 if(gIt != _mFieldMap.end()) 00132 { 00133 _mFieldMap.erase(gIt); 00134 } 00135 } 00136 00137 /*-------------------------------------------------------------------------*/ 00138 /* Helper */ 00139 00140 template <class MPFieldT> inline 00141 void MPFieldStore<MPFieldT>::clear(void) 00142 { 00143 MPFieldMapIt gIt = _mFieldMap.begin(); 00144 00145 while(gIt != _mFieldMap.end()) 00146 { 00147 delete (*gIt).second; 00148 00149 ++gIt; 00150 } 00151 00152 _mFieldMap.clear(); 00153 } 00154 00155 00156 template <class MPFieldT> inline 00157 typename MPFieldStore<MPFieldT>::MPFieldType * 00158 MPFieldStore<MPFieldT>::findMPFieldType(const Char8 *szName) const 00159 { 00160 MPFieldTypeMapCIt gIt; 00161 00162 if(szName == NULL) 00163 { 00164 SWARNING << "typename == NULL" << std::endl; 00165 return NULL; 00166 } 00167 00168 gIt = _mFieldTypeMap.find(IDStringLink(szName)); 00169 00170 if(gIt != _mFieldTypeMap.end()) 00171 { 00172 return (*gIt).second; 00173 } 00174 else 00175 { 00176 return NULL; 00177 } 00178 } 00179 00180 /*-------------------------------------------------------------------------*/ 00181 /* Register */ 00182 00183 template <class MPFieldT> inline 00184 UInt32 MPFieldStore<MPFieldT>::registerMPType(MPFieldType *pType) 00185 { 00186 UInt32 returnValue = 0; 00187 00188 if(pType == NULL) 00189 return 0; 00190 00191 MPFieldType *pTmp = findMPFieldType(pType->getCName()); 00192 00193 if(pTmp != NULL) 00194 { 00195 SLOG << "Error could not add second mp type with name " 00196 << pType->getCName() 00197 << std::endl; 00198 00199 return returnValue; 00200 } 00201 00202 /* 00203 returnValue = TypeFactory::the()->registerType(pType); 00204 00205 if(returnValue == 0) 00206 { 00207 SLOG << "Error in base type registration" << std::endl; 00208 return returnValue; 00209 } 00210 */ 00211 00212 _mFieldTypeMap[IDStringLink(pType->getCName())] = pType; 00213 00214 return returnValue; 00215 } 00216 00217 OSG_END_NAMESPACE 00218 00219 #define OSGTHREADMANAGER_INLINE_CVSID "@(#)$Id: $"
1.5.5