fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / Base / FieldContainer / Connector / OSGFieldConnector.cpp
blob4451e1a1b7f03d474aba3f497e230f56463c9b13
1 /*---------------------------------------------------------------------------*\
2 * OpenSG *
3 * *
4 * *
5 * Copyright (C) 2008 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 "OSGAttachmentContainer.h"
40 #include "OSGFieldConnector.h"
41 #include "OSGConnectorAttachment.h"
42 #include "OSGNode.h"
44 OSG_BEGIN_NAMESPACE
46 /*---------------------------------------------------------------------*/
47 /*! \name Connection handling */
48 /*! \{ */
50 /*! \ingroup GrpBaseFieldContainerConnector
51 \relatesalso AttachmentContainer
54 bool addConnection( OSG::AttachmentContainer *pSrcContainer,
55 const OSG::Char8 *szSrcName,
56 OSG::FieldContainer *pDstContainer,
57 const OSG::Char8 *szDstName )
59 if(pSrcContainer == NULL || szSrcName == NULL ||
60 pDstContainer == NULL || szDstName == NULL )
62 return false;
65 const FieldDescriptionBase *pSrcDesc = NULL;
66 const FieldDescriptionBase *pDstDesc = NULL;
68 GetFieldHandlePtr pSrcHnd = pSrcContainer->getField(szSrcName);
69 GetFieldHandlePtr pDstHnd = pDstContainer->getField(szDstName);
71 if(pSrcHnd != NULL && pSrcHnd->isValid() == true)
73 pSrcDesc = pSrcHnd->getDescription();
76 if(pDstHnd != NULL && pDstHnd->isValid() == true)
78 pDstDesc = pDstHnd->getDescription();
81 // check core for node
82 if(pSrcDesc == NULL)
84 Node *pNode = dynamic_cast<Node *>(pSrcContainer);
86 if(pNode != NULL && pNode->getCore() != NULL)
88 pSrcHnd = pNode->getCore()->getField(szSrcName);
90 if(pSrcHnd != NULL && pSrcHnd->isValid() == true)
92 pSrcDesc = pSrcHnd->getDescription();
97 // same here
98 if(pDstDesc == NULL)
100 Node *pNode = dynamic_cast<Node *>(pDstContainer);
102 if(pNode != NULL && pNode->getCore() != NULL)
104 pDstHnd = pNode->getCore()->getField(szDstName);
106 if(pDstHnd != NULL && pDstHnd->isValid() == true)
108 pDstDesc = pDstHnd->getDescription();
113 if(pSrcDesc == NULL || pDstDesc == NULL)
115 FWARNING(("addConnection: Failed to obtain field descriptions for "
116 "source container [%p] field [%s] desc [%p] - "
117 "destination container [%p] field [%s] desc [%p]\n",
118 static_cast<void *>(pSrcContainer),
119 szSrcName,
120 static_cast<const void *>(pSrcDesc),
121 static_cast<void *>(pDstContainer),
122 szDstName,
123 static_cast<const void *>(pDstDesc) ));
125 return false;
128 const Field *pSrcField = pSrcHnd->getField();
129 Field *pDstField = const_cast<Field *>(pDstHnd->getField());
131 pSrcContainer =
132 dynamic_cast<AttachmentContainer *>(pSrcHnd->getContainer());
134 pDstContainer =
135 dynamic_cast<FieldContainer *>(pDstHnd->getContainer());
137 if(pSrcContainer == NULL || pDstContainer == NULL)
139 FWARNING(("addConnection: Failed to obtain field handles for "
140 "source container [%p] - destination container [%p]\n",
141 static_cast<void *>(pSrcContainer),
142 static_cast<void *>(pDstContainer)));
144 return false;
147 BasicFieldConnector *pConn = pSrcDesc->createConnector(pSrcField,
148 pDstDesc,
149 pDstField);
151 if(pConn != NULL)
153 pConn->setTargetContainer(pDstContainer);
155 addConnector(pSrcContainer, pConn);
158 return true;
161 /*! \ingroup GrpBaseFieldContainerConnector
162 \relatesalso AttachmentContainer
165 bool subConnection( OSG::AttachmentContainer *pSrcContainer,
166 const OSG::Char8 *szSrcName,
167 OSG::FieldContainer *pDstContainer,
168 const OSG::Char8 *szDstName )
170 if(pSrcContainer == NULL)
172 return false;
176 const FieldDescriptionBase *pSrcDesc = NULL;
178 GetFieldHandlePtr pSrcHnd;
180 if(szSrcName != NULL)
182 pSrcHnd = pSrcContainer->getField(szSrcName);
184 if(pSrcHnd != NULL && pSrcHnd->isValid() == true)
186 pSrcDesc = pSrcHnd->getDescription();
189 // check core for node
190 if(pSrcDesc == NULL)
192 Node *pNode = dynamic_cast<Node *>(pSrcContainer);
194 if(pNode != NULL && pNode->getCore() != NULL)
196 pSrcHnd = pNode->getCore()->getField(szSrcName);
198 if(pSrcHnd != NULL && pSrcHnd->isValid() == true)
200 pSrcDesc = pSrcHnd->getDescription();
207 const FieldDescriptionBase *pDstDesc = NULL;
209 GetFieldHandlePtr pDstHnd;
211 if(pDstContainer != NULL && szDstName != NULL)
213 pDstHnd = pDstContainer->getField(szDstName);
215 if(pDstHnd != NULL && pDstHnd->isValid() == true)
217 pDstDesc = pDstHnd->getDescription();
220 // same here
221 if(pDstDesc == NULL)
223 Node *pNode = dynamic_cast<Node *>(pDstContainer);
225 if(pNode != NULL && pNode->getCore() != NULL)
227 pDstHnd = pNode->getCore()->getField(szDstName);
229 if(pDstHnd != NULL && pDstHnd->isValid() == true)
231 pDstDesc = pDstHnd->getDescription();
238 #if 0
239 if(pSrcDesc == NULL)
241 FWARNING(("subConnection: Failed to obtain field description for: "
242 "source container [%p] field [%s]\n",
243 pSrcContainer, szSrcName));
245 return false;
247 #endif
249 BitVector bSrcMask = TypeTraits<BitVector>::BitsClear;
250 BitVector bDstMask = TypeTraits<BitVector>::BitsClear;
252 if(pSrcDesc != NULL)
254 bSrcMask = pSrcDesc->getFieldMask();
256 pSrcContainer =
257 dynamic_cast<AttachmentContainer *>(pSrcHnd->getContainer());
259 else if(szSrcName == NULL)
261 bSrcMask = TypeTraits<BitVector>::BitsSet;
264 if(pDstDesc != NULL)
266 bDstMask = pDstDesc->getFieldMask();
268 pDstContainer =
269 dynamic_cast<AttachmentContainer *>(pDstHnd->getContainer());
271 else if(szDstName == NULL)
273 bDstMask = TypeTraits<BitVector>::BitsSet;
276 subConnector(pSrcContainer, bSrcMask,
277 pDstContainer, bDstMask);
279 return false;
282 /*! \} */
283 /*---------------------------------------------------------------------*/
285 OSG_END_NAMESPACE