changed: auto add updateData callback to stages so that stagedata can be updated...
[opensg.git] / Source / Base / Field / OSGFieldDescFactory.cpp
blob5ce596b893f8ac3810108a21ac1a1f3d43e14dfa
1 /*---------------------------------------------------------------------------*\
2 * OpenSG *
3 * *
4 * *
5 * Copyright (C) 2000-2002 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 #include <stdlib.h>
40 #include <stdio.h>
42 #include "OSGConfig.h"
43 #include "OSGFieldDescFactory.h"
44 #include "OSGFieldType.h"
45 #include "OSGBaseFunctions.h"
46 #include "OSGLog.h"
47 #include "OSGFactoryController.h"
49 #include "OSGSingletonHolder.ins"
51 OSG_BEGIN_NAMESPACE
53 OSG_SINGLETON_INST(FieldDescFactoryBase, addPostFactoryExitFunction)
55 template class SingletonHolder<FieldDescFactoryBase>;
57 OSG_END_NAMESPACE
59 OSG_BEGIN_NAMESPACE
61 /*-------------------------------------------------------------------------*/
62 /* Class Variable */
64 //std::map<UInt32, FieldType *> *FieldDescFactory::_fieldTypeM = NULL;
66 /*-------------------------------------------------------------------------*/
67 /* Destructor */
69 FieldDescFactoryBase::~FieldDescFactoryBase(void)
71 // At this point, the Log is already destroyed
72 //SINFO << "INFO: Destroy Singleton FieldDescFactory" << std::endl;
75 /*-------------------------------------------------------------------------*/
76 /* Create */
78 Field *FieldDescFactoryBase::createField(UInt32 typeId)
80 #if 0
81 FieldType *pType = getFieldType(typeId);
84 if((pType != NULL) &&
85 (pType->_createMethod != NULL))
87 return pType->_createMethod();
89 else
91 return NULL;
93 #else
94 return NULL;
95 #endif
98 Field *FieldDescFactoryBase::createField(const Char8 *szName)
100 #if 0
101 FieldType *pType = getFieldType(szName);
103 if((pType != NULL) &&
104 (pType->_createMethod != NULL))
106 return pType->_createMethod();
108 else
110 return NULL;
112 #else
113 return NULL;
114 #endif
117 /*-------------------------------------------------------------------------*/
118 /* Get */
120 UInt32 FieldDescFactoryBase::getNumFieldTypes(void)
122 #if 0
123 if(_fieldTypeM != NULL)
124 return _fieldTypeM->size();
125 #endif
127 return 0;
130 FieldType *FieldDescFactoryBase::getFieldType(const Char8 *szName)
132 #if 0
133 std::map<UInt32, FieldType *>::iterator mIt;
134 FieldType *returnValue = NULL;
136 if(_fieldTypeM != NULL)
138 mIt = _fieldTypeM->begin();
140 while(mIt != _fieldTypeM->end())
142 if(strcmp(szName, (*mIt).second->getCName()) == 0)
144 returnValue = (*mIt).second;
145 break;
148 mIt++;
152 return returnValue;
153 #else
154 return NULL;
155 #endif
158 FieldType *FieldDescFactoryBase::getFieldType(UInt32 typeId)
160 #if 0
161 std::map<UInt32, FieldType *>::iterator mIt;
163 if(_fieldTypeM == NULL)
164 return NULL;
166 mIt = _fieldTypeM->find(typeId);
168 if(mIt != _fieldTypeM->end())
170 return (*mIt).second;
172 else
174 return NULL;
176 #else
177 return NULL;
178 #endif
181 const Char8 *FieldDescFactoryBase::getFieldTypeName(UInt32 typeId)
183 #if 0
184 FieldType *pFieldType = getFieldType(typeId);
186 return pFieldType ? pFieldType->getCName() : NULL;
187 #else
188 return NULL;
189 #endif
192 FieldDescriptionBase *FieldDescFactoryBase::createByName(
193 const Char8 *szFieldTypename,
194 const Char8 *szFieldname,
195 FieldEditMethod fEditMethod,
196 FieldGetMethod fGetMethod,
197 UInt32 uiFieldFlags )
199 if(szFieldTypename == NULL)
201 FWARNING(("FieldDescFactory::create, no typename given\n"));
203 return NULL;
206 FieldDescriptionBase *returnValue = NULL;
207 std::string tmpStr = szFieldTypename;
209 NameCreatorMapConstIt ncIt = _mNameCreatorMap.find(tmpStr);
211 if(ncIt != _mNameCreatorMap.end())
213 if(ncIt->second.first)
215 returnValue = ncIt->second.first(szFieldname,
216 uiFieldFlags,
218 fEditMethod,
219 fGetMethod);
221 else
223 FWARNING(("no desc creator registered for %s\n",
224 szFieldTypename));
227 else
229 FWARNING(("could not find desc creator for %s\n",
230 szFieldTypename));
233 return returnValue;
236 FieldDescriptionBase *FieldDescFactoryBase::createByNameIdx(
237 const Char8 *szFieldTypename,
238 const Char8 *szFieldname,
239 FieldIndexEditMethod fEditMethod,
240 FieldIndexGetMethod fGetMethod,
241 UInt32 uiFieldFlags )
243 if(szFieldTypename == NULL)
245 FWARNING(("FieldDescFactory::createIdx, no typename given\n"));
247 return NULL;
250 FieldDescriptionBase *returnValue = NULL;
251 std::string tmpStr = szFieldTypename;
253 NameCreatorMapConstIt ncIt = _mNameCreatorMap.find(tmpStr);
255 if(ncIt != _mNameCreatorMap.end())
257 if(ncIt->second.second)
259 returnValue = ncIt->second.second(szFieldname,
260 uiFieldFlags,
262 fEditMethod,
263 fGetMethod);
265 else
267 FWARNING(("no desc idx creator registered for %s\n",
268 szFieldTypename));
271 else
273 FWARNING(("could not find desc idx creator for %s\n",
274 szFieldTypename));
277 return returnValue;
281 FieldDescriptionBase *FieldDescFactoryBase::create(
282 UInt32 uiFieldTypeId,
283 const Char8 *szFieldname,
284 FieldEditMethod fEditMethod,
285 FieldGetMethod fGetMethod,
286 UInt32 uiFieldFlags )
288 if(uiFieldTypeId >= _vCreators.size())
290 FWARNING(("FieldDescFactory::create, unknown type id %d (%"PRISize")\n",
291 uiFieldTypeId,
292 _vCreators.size()));
294 return NULL;
297 FieldDescriptionBase *returnValue = NULL;
299 if(_vCreators[uiFieldTypeId].first)
301 returnValue = _vCreators[uiFieldTypeId].first(szFieldname,
302 uiFieldFlags,
304 fEditMethod,
305 fGetMethod);
307 else
309 FWARNING(("no desc creator registered for %d\n",
310 uiFieldTypeId));
313 return returnValue;
316 FieldDescriptionBase *FieldDescFactoryBase::createIdx(
317 UInt32 uiFieldTypeId,
318 const Char8 *szFieldname,
319 FieldIndexEditMethod fEditMethod,
320 FieldIndexGetMethod fGetMethod,
321 UInt32 uiFieldFlags )
323 if(uiFieldTypeId >= _vCreators.size())
325 FWARNING(("FieldDescFactory::createIdx, unknown type id %d (%"
326 PRISize")\n",
328 uiFieldTypeId,
329 _vCreators.size()));
331 return NULL;
334 FieldDescriptionBase *returnValue = NULL;
336 if(_vCreators[uiFieldTypeId].second)
338 returnValue = _vCreators[uiFieldTypeId].second(szFieldname,
339 uiFieldFlags,
341 fEditMethod,
342 fGetMethod);
344 else
346 FWARNING(("no desc idx creator registered for %d\n",
347 uiFieldTypeId));
350 return returnValue;
353 /*-------------------------------------------------------------------------*/
354 /* the */
356 void FieldDescFactoryBase::registerDescription(
357 const Char8 *szFieldTypename,
358 UInt32 uiTypeId,
359 FieldDescCreator fCreator,
360 IndexedFieldDescCreator fIdxCreator )
362 if(szFieldTypename == NULL)
363 return;
365 // fprintf(stderr, "register %s (%d)\n", szFieldTypename, uiTypeId);
367 std::string tmpStr = szFieldTypename;
369 NameCreatorMapConstIt ncIt = _mNameCreatorMap.find(tmpStr);
371 if(ncIt == _mNameCreatorMap.end())
373 DescCreators tmpCreators;
375 tmpCreators.first = fCreator;
376 tmpCreators.second = fIdxCreator;
378 _mNameCreatorMap[tmpStr] = tmpCreators;
380 if(uiTypeId >= _vCreators.size())
382 _vCreators.resize(uiTypeId + 1);
385 _vCreators[uiTypeId] = tmpCreators;
387 else
389 FWARNING(("could not add second desc creator for %s\n",
390 szFieldTypename));
394 /*-------------------------------------------------------------------------*/
395 /* Constructors */
397 FieldDescFactoryBase::FieldDescFactoryBase(void) :
398 Inherited ("FieldDescFactory"),
399 _mNameCreatorMap( ),
400 _vCreators ( )
402 FactoryController::the()->registerFactory(this);
406 bool FieldDescFactoryBase::initialize(void)
408 // fprintf(stderr, "FieldDescFactoryBase::initialize\n");
410 return true;
414 bool FieldDescFactoryBase::terminate(void)
416 // fprintf(stderr, "FieldDescFactoryBase::terminate\n");
418 return true;
422 bool FieldDescFactoryBase::initializePendingElements(void)
424 // fprintf(stderr, "FieldDescFactoryBase::initializePendingElements\n");
426 return true;
430 bool FieldDescFactoryBase::initializeFactoryPost(void)
432 // fprintf(stderr, "FieldDescFactoryBase::initializeFactoryPost\n");
434 return true;
437 bool FieldDescFactoryBase::initializePendingElementsFactoryPost(void)
439 // fprintf(stderr,
440 // "FieldDescFactoryBase::initializePendingElementsFactoryPost\n");
442 return true;
445 /*-------------------------------------------------------------------------*/
446 /* Add */
448 #if 0
449 void FieldDescFactoryBase::registerType(FieldType *pType)
453 void FieldDescFactoryBase::addType(FieldType *pType)
455 if(pType == NULL)
456 return;
458 if(getFieldType(pType->getId()) != NULL)
459 return;
461 if(_fieldTypeM == NULL)
462 _fieldTypeM = new std::map<UInt32, FieldType *>();
464 (*_fieldTypeM)[pType->getId()] = pType;
466 #endif
468 OSG_END_NAMESPACE