fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / Base / Threading / OSGThreadManager.inl
blob5980c6471ccfd1a9efb438e279e43b338ff79908
1 /*---------------------------------------------------------------------------*\
2  *                                OpenSG                                     *
3  *                                                                           *
4  *                                                                           *
5  *             Copyright (C) 2000-2003 by the OpenSG Forum                   *
6  *                                                                           *
7  *                            www.opensg.org                                 *
8  *                                                                           *
9  *   contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de          *
10  *                                                                           *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
13  *                                License                                    *
14  *                                                                           *
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.                               *
18  *                                                                           *
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.                          *
23  *                                                                           *
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.                 *
27  *                                                                           *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
30  *                                Changes                                    *
31  *                                                                           *
32  *                                                                           *
33  *                                                                           *
34  *                                                                           *
35  *                                                                           *
36  *                                                                           *
37 \*---------------------------------------------------------------------------*/
39 OSG_BEGIN_NAMESPACE
42 /*-------------------------- constructor ----------------------------------*/
44 template <class MPFieldT> inline
45 MPFieldStore<MPFieldT>::MPFieldStore(void) :
46     _mFieldTypeMap(),
47     _mFieldMap    ()
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,
63                                                    bool   bGlobal   )
65     MPFieldT    *returnValue = NULL;
66     MPFieldType *pElemType;
68     returnValue = findMPField(szName);
70     if(returnValue == NULL)
71     {
72         pElemType = findMPFieldType(szTypeName);
74         if(pElemType != NULL)
75         {
76             returnValue = pElemType->create(szName, bGlobal);
78             if(returnValue != NULL)
79             {
80                 if(returnValue->isGlobal() == true)
81                 {
82                     OSG::addRef(returnValue);
83                 }
85                 _mFieldMap[std::string(returnValue->getCName())]= returnValue;
86             }
87         }
88         else
89         {
90             PWARNING  << "could not find type named : " << szName << std::endl;
92             returnValue = NULL;
93         }
94     }
96     return returnValue;
100 /*------------------------------- get -----------------------------------*/
102 template <class MPFieldT> inline
103 MPFieldT *MPFieldStore<MPFieldT>::findMPField(const Char8 *szName)
105     MPFieldMapIt gIt;
107     if(szName == NULL)
108         return NULL;
110     gIt = _mFieldMap.find(std::string(szName));
112     if(gIt != _mFieldMap.end())
113     {
114         return (*gIt).second;
115     }
116     else
117     {
118         return NULL;
119     }
122 template <class MPFieldT> inline
123 void MPFieldStore<MPFieldT>::removeMPField(MPFieldT *pField)
125     if(pField == NULL)
126         return;
128     MPFieldMapIt gIt = _mFieldMap.find(std::string(pField->getCName()));
130     if(gIt != _mFieldMap.end())
131     {
132         if((*gIt).second->isGlobal() == true)
133         {
134             subRef((*gIt).second);
135         }
137         _mFieldMap.erase(gIt);
138     }
141 /*-------------------------------------------------------------------------*/
142 /*                               Helper                                    */
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())
153      {
154          if((*gIt).second                != NULL && 
155             (*gIt).second->isGlobal()    == true && 
156             (*gIt).second->getRefCount() == 1     )
157          {
158              delete (*gIt).second;
159          }
161          ++gIt;
162      }
164     _mFieldMap.clear();
168 template <class MPFieldT> inline
169 typename MPFieldStore<MPFieldT>::MPFieldType *
170     MPFieldStore<MPFieldT>::findMPFieldType(const Char8 *szName) const
172     MPFieldTypeMapCIt gIt;
174     if(szName == NULL)
175     {
176         SWARNING << "typename == NULL" << std::endl;
177         return NULL;
178     }
180     gIt = _mFieldTypeMap.find(std::string(szName));
182     if(gIt != _mFieldTypeMap.end())
183     {
184         return (*gIt).second;
185     }
186     else
187     {
188         return NULL;
189     }
192 /*-------------------------------------------------------------------------*/
193 /*                             Register                                    */
195 template <class MPFieldT> inline
196 UInt32 MPFieldStore<MPFieldT>::registerMPType(MPFieldType *pType)
198     UInt32 returnValue = 0;
200     if(pType == NULL)
201         return 0;
203     MPFieldType *pTmp = findMPFieldType(pType->getCName());
205     if(pTmp != NULL)
206     {
207         SLOG << "Error could not add second mp type with name "
208                 << pType->getCName()
209                 << std::endl;
211         return returnValue;
212     }
215     returnValue = TypeFactory::the()->registerType(pType);
217     if(returnValue == 0)
218     {
219         SLOG << "Error in base type registration" << std::endl;
220         return returnValue;
221     }
224     _mFieldTypeMap[std::string(pType->getCName())] = pType;
226     return returnValue;
229 OSG_END_NAMESPACE