changed: auto add updateData callback to stages so that stagedata can be updated...
[opensg.git] / Source / Base / FieldContainer / Mixins / OSGSimpleAttachment.inl
blob165ddfe2e430f7bcf0b4fac1ccf23b4ff0ca2858
1 /*---------------------------------------------------------------------------*\
2  *                                OpenSG                                     *
3  *                                                                           *
4  *                                                                           *
5  *           Copyright (C) 2003 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 OSG_BEGIN_NAMESPACE
41 OSG_FIELD_CONTAINER_TMPL_NO_TYPE_DEF  (SimpleAttachment, AttachmentDescT)
42 OSG_RC_GET_STATIC_TYPE_ID_INL_TMPL_DEF(SimpleAttachment, AttachmentDescT)
44 template <class AttachmentDescT> inline
45 typename SimpleAttachment<AttachmentDescT>::StoredFieldType *
46     SimpleAttachment<AttachmentDescT>::SFieldValFunctions::editFieldPtr(
47         StoredFieldType  *pField,
48         SimpleAttachment *pThis )
50     pThis->editSField(SimpleAttachment::SimpleFieldMask);
52     return pField;
55 template <class AttachmentDescT> inline
56 EditFieldHandlePtr 
57     SimpleAttachment<AttachmentDescT>::SFieldValFunctions::editHandleField(
58         StoredFieldType  *pField,
59         SimpleAttachment *pThis)
61     typename SimpleAttachment::EditHandlePtr returnValue(
62         new typename SimpleAttachment::EditHandle(
63              pField, 
64              pThis->getType().getFieldDesc(SimpleAttachment::SimpleFieldId),
65              pThis));
67     pThis->editSField(SimpleAttachment::SimpleFieldMask);
69     return returnValue;
72 template <class AttachmentDescT> inline
73 void
74 SimpleAttachment<AttachmentDescT>::SFieldValFunctions::syncField(
75     StoredFieldType   *pField,
76     StoredFieldType   *pSourceField,
77     ConstFieldMaskArg  syncMode,
78     UInt32             uiSyncInfo,
79     AspectOffsetStore &oOffsets   )
81     pField->syncWith(*pSourceField);
85 template <class AttachmentDescT> inline
86 typename SimpleAttachment<AttachmentDescT>::StoredFieldType *
87     SimpleAttachment<AttachmentDescT>::SFieldPtrFunctions::editFieldPtr(
88         StoredFieldType  *pField,
89         SimpleAttachment *pThis )
91     return NULL;
94 template <class AttachmentDescT> inline
95 EditFieldHandlePtr 
96     SimpleAttachment<AttachmentDescT>::SFieldPtrFunctions::editHandleField(
97         StoredFieldType  *pField,
98         SimpleAttachment *pThis)
100     typename SimpleAttachment::EditHandlePtr returnValue(
101         new typename SimpleAttachment::EditHandle(
102              pField, 
103              pThis->getType().getFieldDesc(SimpleAttachment::SimpleFieldId),
104              pThis));
106     pThis->editSField(SimpleAttachment::SimpleFieldMask);
108     returnValue->setSetMethod(
109         boost::bind(&SimpleAttachment::setPointerValue, pThis, _1));
111     return returnValue;
114 template <class AttachmentDescT> inline
115 void
116 SimpleAttachment<AttachmentDescT>::SFieldPtrFunctions::syncField(
117     StoredFieldType   *pField,
118     StoredFieldType   *pSourceField,
119     ConstFieldMaskArg  syncMode,
120     UInt32             uiSyncInfo,
121     AspectOffsetStore &oOffsets   )
123     pField->syncWith(*pSourceField);
128 template <class AttachmentDescT> inline
129 typename SimpleAttachment<AttachmentDescT>::StoredFieldType *
130     SimpleAttachment<AttachmentDescT>::MFieldValFunctions::editFieldPtr(
131         StoredFieldType  *pField,
132         SimpleAttachment *pThis )
134     pThis->editMField(*pField, SimpleAttachment::SimpleFieldMask);
136     return pField;
139 template <class AttachmentDescT> inline
140 EditFieldHandlePtr 
141     SimpleAttachment<AttachmentDescT>::MFieldValFunctions::editHandleField(
142         StoredFieldType  *pField,
143         SimpleAttachment *pThis)
145     typename SimpleAttachment::EditHandlePtr returnValue(
146         new typename SimpleAttachment::EditHandle(
147              pField, 
148              pThis->getType().getFieldDesc(SimpleAttachment::SimpleFieldId),
149              pThis));
151     pThis->editMField(*pField, SimpleAttachment::SimpleFieldMask);
153     return returnValue;
156 template <class AttachmentDescT> inline
157 void
158 SimpleAttachment<AttachmentDescT>::MFieldValFunctions::syncField(
159     StoredFieldType   *pField,
160     StoredFieldType   *pSourceField,
161     ConstFieldMaskArg  syncMode,
162     UInt32             uiSyncInfo,
163     AspectOffsetStore &oOffsets   )
165     pField->syncWith(*pSourceField, syncMode, uiSyncInfo, oOffsets);
168 template <class AttachmentDescT> inline
169 typename SimpleAttachment<AttachmentDescT>::StoredFieldType *
170     SimpleAttachment<AttachmentDescT>::MFieldPtrFunctions::editFieldPtr(
171         StoredFieldType  *pField,
172         SimpleAttachment *pThis )
174     return NULL;
177 template <class AttachmentDescT> inline
178 EditFieldHandlePtr 
179     SimpleAttachment<AttachmentDescT>::MFieldPtrFunctions::editHandleField(
180         StoredFieldType  *pField,
181         SimpleAttachment *pThis)
183     typename SimpleAttachment::EditHandlePtr returnValue(
184         new typename SimpleAttachment::EditHandle(
185              pField, 
186              pThis->getType().getFieldDesc(SimpleAttachment::SimpleFieldId),
187              pThis));
189     pThis->editMField(*pField, SimpleAttachment::SimpleFieldMask);
191     returnValue->setSetMethod(
192         boost::bind(&SimpleAttachment::addPointerValue, pThis, _1));
194     return returnValue;
197 template <class AttachmentDescT> inline
198 void
199 SimpleAttachment<AttachmentDescT>::MFieldPtrFunctions::syncField(
200     StoredFieldType   *pField,
201     StoredFieldType   *pSourceField,
202     ConstFieldMaskArg  syncMode,
203     UInt32             uiSyncInfo,
204     AspectOffsetStore &oOffsets   )
206     pField->syncWith(*pSourceField, syncMode, uiSyncInfo, oOffsets);
210 template <class AttachmentDescT> inline
211 typename SimpleAttachment<AttachmentDescT>::StoredFieldType *
212     SimpleAttachment<AttachmentDescT>::editFieldPtr(void)
214     return FieldFunctions::editFieldPtr(&_field, this);
217 template <class AttachmentDescT> inline
218 const typename SimpleAttachment<AttachmentDescT>::StoredFieldType *
219     SimpleAttachment<AttachmentDescT>::getFieldPtr(void) const
221     return &_field;
224 template <class AttachmentDescT> inline
225 const typename SimpleAttachment<AttachmentDescT>::StoredFieldType &
226     SimpleAttachment<AttachmentDescT>::getField(void) const
228     return _field;
231 template <class AttachmentDescT> inline
232 Char8 *SimpleAttachment<AttachmentDescT>::getClassname(void)
234     return SimpleDesc::getTypeName();
237 template <class AttachmentDescT> inline
238 SimpleAttachment<AttachmentDescT>::SimpleAttachment(void) :
239      Inherited(),
240     _field    ()
244 template <class AttachmentDescT> inline
245 SimpleAttachment<AttachmentDescT>::SimpleAttachment(
246     const SimpleAttachment &source) :
248      Inherited(source       ),
249     _field    (source._field)
253 template <class AttachmentDescT> inline
254 SimpleAttachment<AttachmentDescT>::~SimpleAttachment(void)
258 #ifdef OSG_MT_CPTR_ASPECT
259 template <class AttachmentDescT> inline
260 void SimpleAttachment<AttachmentDescT>::execSync(
261           SimpleAttachment  *pFrom,
262           ConstFieldMaskArg  whichField,
263           AspectOffsetStore &oOffsets,
264           ConstFieldMaskArg  syncMode  ,
265     const UInt32             uiSyncInfo)
267     // At least sync the parents for now
268     Inherited::execSync(pFrom,
269                         whichField,
270                         oOffsets,
271                         syncMode,
272                         uiSyncInfo);
274     if(FieldBits::NoField != (SimpleFieldMask & whichField))
275     {
276         FieldFunctions::syncField(&_field,
277                                   &(pFrom->_field),
278                                   syncMode,
279                                   uiSyncInfo,
280                                   oOffsets   );
281     }
284 template <class AttachmentDescT> inline
285  void SimpleAttachment<AttachmentDescT>::execSyncV(
286             FieldContainer    &oFrom,
287             ConstFieldMaskArg  whichField,
288             AspectOffsetStore &oOffsets,
289             ConstFieldMaskArg  syncMode  ,
290       const UInt32             uiSyncInfo)
292     this->execSync(static_cast<SimpleAttachment *>(&oFrom), 
293                    whichField,
294                    oOffsets,
295                    syncMode,
296                    uiSyncInfo);
298 #endif
300 #ifdef OSG_MT_CPTR_ASPECT
301 template <class AttachmentDescT> inline
302 typename SimpleAttachment<AttachmentDescT>::ObjCPtr 
303     SimpleAttachment<AttachmentDescT>::createAspectCopy(
304         const FieldContainer *pRefAspect) const
306     ObjCPtr returnValue; 
308     newAspectCopy(returnValue, 
309                   dynamic_cast<const Self *>(pRefAspect),
310                   dynamic_cast<const Self *>(this)); 
312     return returnValue; 
314 #endif
316 template <class AttachmentDescT> inline
317 SizeT SimpleAttachment<AttachmentDescT>::getBinSize(
318     ConstFieldMaskArg  whichField)
320     SizeT returnValue = Inherited::getBinSize(whichField);
321     
322     if(FieldBits::NoField != (SimpleFieldMask & whichField))
323     {
324         returnValue += _field.getBinSize();
325     }
327     return returnValue;
331 template <class AttachmentDescT> inline
332 void SimpleAttachment<AttachmentDescT>::copyToBin(
333     BinaryDataHandler &pMem, 
334     ConstFieldMaskArg  whichField)
336     Inherited::copyToBin(pMem, whichField);
337     
338     if(FieldBits::NoField != (SimpleFieldMask & whichField))
339     {
340         _field.copyToBin(pMem);
341     }
344 template <class AttachmentDescT> inline
345 void SimpleAttachment<AttachmentDescT>::copyFromBin(
346     BinaryDataHandler &pMem, 
347     ConstFieldMaskArg  whichField)
349     Inherited::copyFromBin(pMem, whichField);
350     
351     if(FieldBits::NoField != (SimpleFieldMask & whichField))
352     {
353         _field.copyFromBin(pMem);
354     }
357 template <class AttachmentDescT> inline
358 void SimpleAttachment<AttachmentDescT>::dump(
359           UInt32, 
360     const BitVector) const
364 template <class AttachmentDescT> inline
365 GetFieldHandlePtr SimpleAttachment<AttachmentDescT>::getHandleField(void) const
367     GetHandlePtr returnValue(
368         new  GetHandle(
369              &_field, 
370              this->getType().getFieldDesc(SimpleFieldId),
371              const_cast<Self *>(this)));
373     return returnValue;
376 template <class AttachmentDescT> inline
377 EditFieldHandlePtr SimpleAttachment<AttachmentDescT>::editHandleField(void)
379 #if 0
380     EditHandlePtr returnValue(
381         new  EditHandle(
382              &_field, 
383              this->getType().getFieldDesc(SimpleFieldId),
384              this));
385 #endif
386 //    editSField(TravMaskFieldMask);
388 //    return returnValue;
390     return FieldFunctions::editHandleField(&_field, this);
393 template <class AttachmentDescT> inline
394 void SimpleAttachment<AttachmentDescT>::setPointerValue(ArgumentType pVal)
396     OSG::setRefd(_field.getValue(), pVal);
399 template <class AttachmentDescT> inline
400 void SimpleAttachment<AttachmentDescT>::addPointerValue(ArgumentType pVal)
402     OSG::addRef(pVal);
404     _field.push_back(pVal);
407 OSG_END_NAMESPACE