changed: gcc8 base update
[opensg.git] / Source / Base / FieldContainer / Attachments / OSGNameAttachment.cpp
blobf4697faf607e70a72e06df63b5874ceba530bece
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 "OSGNameAttachment.h"
47 OSG_BEGIN_NAMESPACE
49 OSG_SIMPLEATTACHMENT_INST(NameAttachmentDesc);
51 template <>
52 SimpleAttachment<NameAttachmentDesc>::TypeObject &
53 SimpleAttachment<NameAttachmentDesc>::getType(void)
55 return _type;
58 template <>
59 const SimpleAttachment<NameAttachmentDesc>::TypeObject &
60 SimpleAttachment<NameAttachmentDesc>::getType(void) const
62 return _type;
65 template <>
66 SimpleAttachment<NameAttachmentDesc>::TypeObject &
67 SimpleAttachment<NameAttachmentDesc>::getClassType(void)
69 return _type;
72 /*-------------------------------------------------------------------------*/
73 /* Name Attachment Utility Functions */
75 /*!
76 Return the name attached to the container, NULL if none attached or
77 container is NULL.
80 const Char8 *getName(AttachmentContainer const * const pContainer)
82 if(pContainer == NULL)
83 return NULL;
85 // Get attachment pointer
86 Attachment *att =
87 pContainer->findAttachment(Name::getClassType().getGroupId());
89 if(att == NULL)
90 return NULL;
92 // Cast to name pointer
94 Name *name = dynamic_cast<Name *>(att);
96 if(name == NULL)
97 return NULL;
99 return name->getFieldPtr()->getValue().c_str();
102 /*! Set the name attached to the container. If the container doesn't have a
103 name attachement yet one is created.
106 void setName(AttachmentContainer * const pContainer,
107 std::string const &namestring)
109 if(pContainer == NULL)
111 FFATAL(("setName: no container?!?\n"));
112 return;
115 // Get attachment pointer
117 NameUnrecPtr name = NULL;
118 Attachment *att =
119 pContainer->findAttachment(Name::getClassType().getGroupId());
121 if(att == NULL)
123 name = Name::createDependent(
124 pContainer->getFieldFlags()->_bNamespaceMask);
126 pContainer->addAttachment(name);
128 else
130 name = dynamic_cast<Name *>(att);
132 if(name == NULL)
134 FFATAL(("setName: Name Attachment is not castable to Name?!?\n"));
135 return;
140 name->editFieldPtr()->getValue().assign(namestring);
143 /*!
144 Set the name attached to the container. If the container doesn't have
145 name attachement yet one is created. If the name is NULL, an attached
146 name is removed.
149 void setName(AttachmentContainer * const pContainer, const Char8 *name)
151 if(name == NULL)
153 Attachment *att =
154 pContainer->findAttachment(Name::getClassType().getGroupId());
156 if(att != NULL)
158 pContainer->subAttachment(att);
161 else
163 setName(pContainer, std::string(name));
167 OSG_END_NAMESPACE