fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / System / FileIO / WRL / OSGVRMLPrototypeHandler.inl
blob6134df59d2f8d37db391692a739c51a08e75741c
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 \*---------------------------------------------------------------------------*/
40 //#define OSG_DEBUG_VRML
42 #ifndef OSG_DO_DOC
43 #    ifdef OSG_DEBUG_VRML
44 #        define OSG_VRML_ARG(ARG) ARG
45 #    else
46 #        define OSG_VRML_ARG(ARG)
47 #    endif
48 #else
49 #    define OSG_VRML_ARG(ARG) ARG
50 #endif
53 OSG_BEGIN_NAMESPACE
55 /*! \class OSG::VRMLPrototypeHandler
56  */
58 /*-------------------------------------------------------------------------*/
59 /*                            Constructors                                 */
61 template <class BaseT> inline
62 VRMLNodePrototypeHandler<BaseT>::VRMLNodePrototypeHandler(void) :
63      Inherited      (    ),
65     _pCurrentHelper (NULL),
66     _mNodeHelperHash(    )
70 /*-------------------------------------------------------------------------*/
71 /*                             Destructor                                  */
73 template <class BaseT> inline
74 VRMLNodePrototypeHandler<BaseT>::~VRMLNodePrototypeHandler(void)
76     typename NameHelperMap::iterator mNodeHelperIt  = _mNodeHelperHash.begin();
77     typename NameHelperMap::iterator mNodeHelperEnd = _mNodeHelperHash.end  ();
79     while(mNodeHelperIt != mNodeHelperEnd)
80     {
81         delete (mNodeHelperIt)->second;
83         ++mNodeHelperIt;
84     }
87 /*-------------------------------------------------------------------------*/
88 /*                            Skel Replacements                            */
90 template <class BaseT> inline
91 void VRMLNodePrototypeHandler<BaseT>::beginProto(const Char8 *szProtoname)
93 #ifdef OSG_DEBUG_VRML
94     indentLog(VRMLNodeHelper::getIndent(), PINFO);
95     PINFO << "Begin Proto " << szProtoname << std::endl;
96 #endif
98     std::string szName;
100     typename NameHelperMap::iterator mNodeHelperIt = 
101         _mNodeHelperHash.find(szProtoname);
103     if(mNodeHelperIt == _mNodeHelperHash.end())
104     {
105         VRMLNodeHelper *pNewHelper = 
106             VRMLNodeHelperFactory::the()->createHelper(szProtoname);
108         if(pNewHelper == NULL)
109         {
110             szName.assign(szProtoname);
112             _pCurrentHelper = VRMLDefaultHelper::create();
114             _pCurrentHelper->init(szProtoname);
116             _mNodeHelperHash[szName] = _pCurrentHelper;
117         }
118         else
119         {
120             szName.assign(szProtoname);
122             _pCurrentHelper = pNewHelper;
124             _pCurrentHelper->init(szProtoname);
126             _mNodeHelperHash[szName] = _pCurrentHelper;
127         }
128     }
129     else
130     {
131         fprintf(stderr, "Helper already present for %s\n", szProtoname);
132     }
134 #if 0
135     Char8 *szName = NULL;
136     if(mNodeDescIt == _mNodeDescHash.end())
137     {
138         else if(osgStringCaseCmp("PointSet", szProtoname) == 0)
139         {
140             osgStringDup(szProtoname, szName);
142             _pCurrentNodeDesc = new VRMLGeometryPointSetDesc();
144             _pCurrentNodeDesc->init(szProtoname);
146             _mNodeDescHash[szName] = _pCurrentNodeDesc;
147         }
148         else if(osgStringCaseCmp("Appearance", szProtoname) == 0)
149         {
150             osgStringDup(szProtoname, szName);
152             _pCurrentNodeDesc = new VRMLAppearanceDesc();
154             _pCurrentNodeDesc->init(szProtoname);
156             _mNodeDescHash[szName] = _pCurrentNodeDesc;
157         }
158         else if(osgStringCaseCmp("Box", szProtoname) == 0)
159         {
160             osgStringDup(szProtoname, szName);
162             _pCurrentNodeDesc = new VRMLGeometryObjectDesc("Box");
164             _pCurrentNodeDesc->init(szProtoname);
166             _mNodeDescHash[szName] = _pCurrentNodeDesc;
167         }
168         else if(osgStringCaseCmp("Cone", szProtoname) == 0)
169         {
170             osgStringDup(szProtoname, szName);
172             _pCurrentNodeDesc = new VRMLGeometryObjectDesc("Cone");
174             _pCurrentNodeDesc->init(szProtoname);
176             _mNodeDescHash[szName] = _pCurrentNodeDesc;
177         }
178         else if(osgStringCaseCmp("Cylinder", szProtoname) == 0)
179         {
180             osgStringDup(szProtoname, szName);
182             _pCurrentNodeDesc = new VRMLGeometryObjectDesc("Cylinder");
184             _pCurrentNodeDesc->init(szProtoname);
186             _mNodeDescHash[szName] = _pCurrentNodeDesc;
187         }
188         else if(osgStringCaseCmp("Sphere", szProtoname) == 0)
189         {
190             osgStringDup(szProtoname, szName);
192             _pCurrentNodeDesc = new VRMLGeometryObjectDesc("Sphere");
194             _pCurrentNodeDesc->init(szProtoname);
196             _mNodeDescHash[szName] = _pCurrentNodeDesc;
197         }
198         else if(osgStringCaseCmp("TextureTransform", szProtoname) == 0)
199         {
200             osgStringDup(szProtoname, szName);
202             _pCurrentNodeDesc = new VRMLTextureTransformDesc();
204             _pCurrentNodeDesc->init(szProtoname);
206             _mNodeDescHash[szName] = _pCurrentNodeDesc;
207         }
208         else if(osgStringCaseCmp("ImageTexture", szProtoname) == 0)
209         {
210             osgStringDup(szProtoname, szName);
212             _pCurrentNodeDesc = new VRMLImageTextureDesc();
214             _pCurrentNodeDesc->init(szProtoname);
216             _mNodeDescHash[szName] = _pCurrentNodeDesc;
217         }
218         else if(osgStringCaseCmp("PixelTexture", szProtoname) == 0)
219         {
220             osgStringDup(szProtoname, szName);
222             _pCurrentNodeDesc = new VRMLPixelTextureDesc();
224             _pCurrentNodeDesc->init(szProtoname);
226             _mNodeDescHash[szName] = _pCurrentNodeDesc;
227         }
228         else if(osgStringCaseCmp("LOD", szProtoname) == 0)
229         {
230             osgStringDup(szProtoname, szName);
232             _pCurrentNodeDesc = new VRMLLODDesc();
234             _pCurrentNodeDesc->init(szProtoname);
236             _mNodeDescHash[szName] = _pCurrentNodeDesc;
237         }
238         else if(osgStringCaseCmp("Switch", szProtoname) == 0)
239         {
240             osgStringDup(szProtoname, szName);
242             _pCurrentNodeDesc = new VRMLSwitchDesc();
244             _pCurrentNodeDesc->init(szProtoname);
246             _mNodeDescHash[szName] = _pCurrentNodeDesc;
247         }
248         else if(osgStringCaseCmp("Group", szProtoname) == 0)
249         {
250             osgStringDup(szProtoname, szName);
252             _pCurrentNodeDesc = new VRMLGroupDesc();
254             _pCurrentNodeDesc->init(szProtoname);
256             _mNodeDescHash[szName] = _pCurrentNodeDesc;
257         }
258         else if(osgStringCaseCmp("Inline", szProtoname) == 0)
259         {
260             osgStringDup(szProtoname, szName);
262             _pCurrentNodeDesc = new VRMLInlineDesc();
264             _pCurrentNodeDesc->init(szProtoname);
266             _mNodeDescHash[szName] = _pCurrentNodeDesc;
267         }
268         else if(osgStringCaseCmp("Viewpoint", szProtoname) == 0)
269         {
270             osgStringDup(szProtoname, szName);
272             _pCurrentNodeDesc = new VRMLViewpointDesc();
274             _pCurrentNodeDesc->init(szProtoname);
276             _mNodeDescHash[szName] = _pCurrentNodeDesc;
277         }
278         else if(osgStringCaseCmp("Extrusion", szProtoname) == 0)
279         {
280             osgStringDup(szProtoname, szName);
282             _pCurrentNodeDesc = new VRMLExtrusionDesc();
284             _pCurrentNodeDesc->init(szProtoname);
286             _mNodeDescHash[szName] = _pCurrentNodeDesc;
287         }
288         else
289         {
290             osgStringDup(szProtoname, szName);
292             _pCurrentNodeDesc = new VRMLNodeDesc;
294             _pCurrentNodeDesc->init(szProtoname);
296             _mNodeDescHash[szName] = _pCurrentNodeDesc;
297         }
299     }
300     else
301     {
302 #ifdef OSG_DEBUG_VRML
303         indentLog(VRMLNodeDesc::getIndent(), PINFO);
304         PINFO << "Could not add second proto named "
305               << szProtoname
306               << std::endl;
307 #endif
308     }
310 #endif
312     VRMLNodeHelper::incIndent();
313     VRMLNodeHelper::incIndent();
316 template <class BaseT> inline
317 void VRMLNodePrototypeHandler<BaseT>::endProtoInterface(void)
319     if(_pCurrentHelper != NULL)
320         _pCurrentHelper->endProtoInterface();
322 #ifdef OSG_DEBUG_VRML
323     VRMLNodeHelper::decIndent();
324 #endif
327 template <class BaseT> inline
328 void VRMLNodePrototypeHandler<BaseT>::endProto(void)
330 #ifdef OSG_DEBUG_VRML
331     VRMLNodeHelper::decIndent();
332 #endif
335 template <class BaseT> inline
336 void VRMLNodePrototypeHandler<BaseT>::beginEventInDecl(
337     const Char8  *OSG_VRML_ARG(szEventType),
338     const UInt32,
339     const Char8  *OSG_VRML_ARG(szEventName))
341 #ifdef OSG_DEBUG_VRML
342     indentLog(VRMLNodeHelper::getIndent(), PINFO);
343     PINFO << "AddEventIn " << szEventType << " " << szEventName << std::endl;
344 #endif
347 template <class BaseT> inline
348 void VRMLNodePrototypeHandler<BaseT>::beginEventOutDecl(
349     const Char8  *OSG_VRML_ARG(szEventType),
350     const UInt32,
351     const Char8  *OSG_VRML_ARG(szEventName))
353 #ifdef OSG_DEBUG_VRML
354     indentLog(VRMLNodeHelper::getIndent(), PINFO);
355     PINFO << "AddEventOut " << szEventType << " " << szEventName << std::endl;
356 #endif
359 template <class BaseT> inline
360 void VRMLNodePrototypeHandler<BaseT>::beginFieldDecl(
361     const Char8  *szFieldType,
362     const UInt32  uiFieldTypeId,
363     const Char8  *szFieldName)
365 #ifdef OSG_DEBUG_VRML
366     indentLog(VRMLNodeHelper::getIndent(), PINFO);
367     PINFO << "AddField " 
368           << szFieldType 
369           << " " << uiFieldTypeId 
370           << " " << szFieldName 
371           << std::endl;
372 #endif
374     if(_pCurrentHelper != NULL)
375     {
376         _pCurrentHelper->prototypeAddField(
377             szFieldType,
378             Self::mapIntExtFieldType(szFieldName, uiFieldTypeId),
379             szFieldName);
380     }
383 template <class BaseT> inline
384 void VRMLNodePrototypeHandler<BaseT>::endFieldDecl(void)
388 template <class BaseT> inline
389 void VRMLNodePrototypeHandler<BaseT>::beginExposedFieldDecl(
390     const Char8  *szFieldType,
391     const UInt32  uiFieldTypeId,
392     const Char8  *szFieldName)
394     beginFieldDecl(szFieldType, uiFieldTypeId, szFieldName);
397 template <class BaseT> inline
398 void VRMLNodePrototypeHandler<BaseT>::endExposedFieldDecl(void)
400     endFieldDecl();
404 /*-------------------------------------------------------------------------*/
405 /*                                Dump                                     */
408 /*-------------------------------------------------------------------------*/
409 /*                               Helper                                    */
411 template <class BaseT> inline
412 VRMLNodeHelper *VRMLNodePrototypeHandler<BaseT>::findNodeHelper(
413     const Char8 *szNodeTypename)
415     VRMLNodeHelper *returnValue = NULL;
417     typename NameHelperMap::iterator mNodeHelperIt =
418         _mNodeHelperHash.find(szNodeTypename);
420     if(mNodeHelperIt != _mNodeHelperHash.end())
421     {
422 #ifdef OSG_DEBUG_VRML
423         indentLog(VRMLNodeHelper::getIndent(), PINFO);
424         PINFO << "Found Node "
425               << mNodeHelperIt->first << " ("
426               << szNodeTypename     << ")" << std::endl;
427 #endif
429         returnValue = mNodeHelperIt->second;
430     }
432     return returnValue;
436 template <class BaseT> inline
437 void VRMLNodePrototypeHandler<BaseT>::preStandardProtos (void)
441 template <class BaseT> inline
442 void VRMLNodePrototypeHandler<BaseT>::postStandardProtos(void)
444     VRMLNodeHelper         *pNodeHelper         = NULL;
445     VRMLShapeHelper        *pShapeHelper        = NULL;
446     VRMLAppearanceHelper   *pAppearanceHelper   = NULL;
447     VRMLMaterialHelper     *pMaterialHelper     = NULL;
449     pNodeHelper = findNodeHelper("Shape");
451     if(pNodeHelper != NULL)
452     {
453         pShapeHelper = dynamic_cast<VRMLShapeHelper *>(pNodeHelper);
454     }
456     pNodeHelper = findNodeHelper("Appearance");
458     if(pNodeHelper != NULL)
459     {
460         pAppearanceHelper = dynamic_cast<VRMLAppearanceHelper *>(pNodeHelper);
461     }
463     pNodeHelper = findNodeHelper("Material");
465     if(pNodeHelper != NULL)
466     {
467         pMaterialHelper = dynamic_cast<VRMLMaterialHelper *>(pNodeHelper);
468     }
470     if(pShapeHelper != NULL)
471     {
472         pShapeHelper->setMaterialHelper(pMaterialHelper);
473     }
475     if(pAppearanceHelper != NULL)
476     {
477         pAppearanceHelper->setMaterialHelper(pMaterialHelper);
478     }
481 OSG_END_NAMESPACE