1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2000-2003 by the OpenSG Forum *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
15 * This library is free software; you can redistribute it and/or modify it *
16 * under the terms of the GNU Library General Public License as published *
17 * by the Free Software Foundation, version 2. *
19 * This library is distributed in the hope that it will be useful, but *
20 * WITHOUT ANY WARRANTY; without even the implied warranty of *
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
22 * Library General Public License for more details. *
24 * You should have received a copy of the GNU Library General Public *
25 * License along with this library; if not, write to the Free Software *
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
37 \*---------------------------------------------------------------------------*/
42 /*-------------------------- constructor ----------------------------------*/
44 template <class MPFieldT> inline
45 MPFieldStore<MPFieldT>::MPFieldStore(void) :
51 /*--------------------------- destructor ----------------------------------*/
53 template <class MPFieldT> inline
54 MPFieldStore<MPFieldT>::~MPFieldStore(void)
58 /*------------------------------ access -----------------------------------*/
60 template <class MPFieldT> inline
61 MPFieldT *MPFieldStore<MPFieldT>::getMPField(const Char8 *szName,
62 const Char8 *szTypeName,
65 MPFieldT *returnValue = NULL;
66 MPFieldType *pElemType;
68 returnValue = findMPField(szName);
70 if(returnValue == NULL)
72 pElemType = findMPFieldType(szTypeName);
76 returnValue = pElemType->create(szName, bGlobal);
78 if(returnValue != NULL)
80 if(returnValue->isGlobal() == true)
82 OSG::addRef(returnValue);
85 _mFieldMap[std::string(returnValue->getCName())]= returnValue;
90 PWARNING << "could not find type named : " << szName << std::endl;
100 /*------------------------------- get -----------------------------------*/
102 template <class MPFieldT> inline
103 MPFieldT *MPFieldStore<MPFieldT>::findMPField(const Char8 *szName)
110 gIt = _mFieldMap.find(std::string(szName));
112 if(gIt != _mFieldMap.end())
114 return (*gIt).second;
122 template <class MPFieldT> inline
123 void MPFieldStore<MPFieldT>::removeMPField(MPFieldT *pField)
128 MPFieldMapIt gIt = _mFieldMap.find(std::string(pField->getCName()));
130 if(gIt != _mFieldMap.end())
132 if((*gIt).second->isGlobal() == true)
134 subRef((*gIt).second);
137 _mFieldMap.erase(gIt);
141 /*-------------------------------------------------------------------------*/
144 template <class MPFieldT> inline
145 void MPFieldStore<MPFieldT>::clear(void)
147 MPFieldMapIt gIt = _mFieldMap.begin();
149 // don't delete objects that are refcounted - rather leak them
150 // than destroying an object with active references to it.
152 while(gIt != _mFieldMap.end())
154 if((*gIt).second != NULL &&
155 (*gIt).second->isGlobal() == true &&
156 (*gIt).second->getRefCount() == 1 )
158 delete (*gIt).second;
168 template <class MPFieldT> inline
169 typename MPFieldStore<MPFieldT>::MPFieldType *
170 MPFieldStore<MPFieldT>::findMPFieldType(const Char8 *szName) const
172 MPFieldTypeMapCIt gIt;
176 SWARNING << "typename == NULL" << std::endl;
180 gIt = _mFieldTypeMap.find(std::string(szName));
182 if(gIt != _mFieldTypeMap.end())
184 return (*gIt).second;
192 /*-------------------------------------------------------------------------*/
195 template <class MPFieldT> inline
196 UInt32 MPFieldStore<MPFieldT>::registerMPType(MPFieldType *pType)
198 UInt32 returnValue = 0;
203 MPFieldType *pTmp = findMPFieldType(pType->getCName());
207 SLOG << "Error could not add second mp type with name "
215 returnValue = TypeFactory::the()->registerType(pType);
219 SLOG << "Error in base type registration" << std::endl;
224 _mFieldTypeMap[std::string(pType->getCName())] = pType;