changed: gcc8 base update
[opensg.git] / Source / System / FieldContainer / Attachments / OSGVoidPAttachment.cpp
blob7dcee7b2ca73e1629cc07d5573e6c38452563714
1 /*---------------------------------------------------------------------------*\
2 * OpenSG *
3 * *
4 * *
5 * Copyright (C) 2000,2001,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 <cstdlib>
40 #include <cstdio>
42 #include "OSGConfig.h"
44 #include "OSGAttachmentContainer.h"
45 #include "OSGVoidPAttachment.h"
47 OSG_BEGIN_NAMESPACE
49 OSG_SIMPLEATTACHMENT_INST(VoidPAttachmentDesc);
51 template <>
52 SimpleAttachment<VoidPAttachmentDesc>::TypeObject &
53 SimpleAttachment<VoidPAttachmentDesc>::getType(void)
55 return _type;
58 template <>
59 const SimpleAttachment<VoidPAttachmentDesc>::TypeObject &
60 SimpleAttachment<VoidPAttachmentDesc>::getType(void) const
62 return _type;
65 template <>
66 SimpleAttachment<VoidPAttachmentDesc>::TypeObject &
67 SimpleAttachment<VoidPAttachmentDesc>::getClassType(void)
69 return _type;
72 /*-------------------------------------------------------------------------*/
73 /* Name Attachment Utility Functions */
75 /*!
76 Return the void * attached to the container, NULL if none attached or
77 container is NULL.
80 void *getVoidP(AttachmentContainer * const pContainer)
82 if(pContainer == NULL)
83 return NULL;
85 // Get attachment pointer
86 Attachment *att =
87 pContainer->findAttachment(
88 VoidPAttachment::getClassType().getGroupId());
90 if(att == NULL)
91 return NULL;
93 // Cast to name pointer
95 VoidPAttachment *voidP = dynamic_cast<VoidPAttachment *>(att);
97 if(voidP == NULL)
98 return NULL;
100 return voidP->getFieldPtr()->getValue();
104 /*! Set the name attached to the container. If the container doesn't have a
105 name attachement yet one is created.
108 void setVoidP(AttachmentContainer * const pContainer,
109 void * pData,
110 bool bInternal)
112 if(pContainer == NULL)
114 FFATAL(("setVoidP: no container?!?"));
115 return;
118 // Get attachment pointer
120 VoidPAttachmentUnrecPtr voidP = NULL;
121 Attachment *att =
122 pContainer->findAttachment(
123 VoidPAttachment::getClassType().getGroupId());
125 if(att == NULL)
127 voidP = VoidPAttachment::create();
129 pContainer->addAttachment(voidP);
131 else
133 voidP = dynamic_cast<VoidPAttachment *>(att);
135 if(voidP == NULL)
137 FFATAL(("setVoidP: VoidP Attachment is not castable to Name?!?"));
138 return;
142 voidP->editFieldPtr()->setValue(pData);
143 voidP->setInternal(bInternal);
146 OSG_END_NAMESPACE