1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2003 by the OpenSG Forum *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
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. *
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. *
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. *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
37 \*---------------------------------------------------------------------------*/
39 #ifndef _OSGSIMPLEATTACHMENT_H_
40 #define _OSGSIMPLEATTACHMENT_H_
46 #include "OSGAttachment.h"
48 #include "boost/bind.hpp"
52 /*! \ingroup GrpBaseFieldContainerMixins
53 \ingroup GrpLibOSGBase
56 template <class AttachmentDescT
>
57 class SimpleAttachment
: public Attachment
60 /*========================== PUBLIC =================================*/
64 typedef Attachment Inherited
;
65 typedef Attachment ParentContainer
;
67 typedef AttachmentDescT SimpleDesc
;
68 typedef typename
SimpleDesc::FieldTypeT StoredFieldType
;
69 typedef typename
StoredFieldType::ArgumentType ArgumentType
;
71 typedef SimpleAttachment
<AttachmentDescT
> Self
;
73 typedef typename
StoredFieldType::GetHandle GetHandle
;
74 typedef typename
StoredFieldType::GetHandlePtr GetHandlePtr
;
76 typedef typename
StoredFieldType::EditHandle EditHandle
;
77 typedef typename
StoredFieldType::EditHandlePtr EditHandlePtr
;
79 /*========================= PROTECTED ===============================*/
83 typedef Inherited::TypeObject TypeObject
;
84 typedef TypeObject::InitPhase InitPhase
;
87 struct SFieldValFunctions
89 static StoredFieldType
*editFieldPtr (StoredFieldType
*pField
,
90 SimpleAttachment
*pThis
);
93 static EditFieldHandlePtr
editHandleField(StoredFieldType
*pField
,
94 SimpleAttachment
*pThis
);
96 static void syncField(StoredFieldType
*pField
,
97 StoredFieldType
*pSourceField
,
98 ConstFieldMaskArg syncMode
,
100 AspectOffsetStore
&oOffsets
);
104 struct SFieldPtrFunctions
106 static StoredFieldType
*editFieldPtr (StoredFieldType
*pField
,
107 SimpleAttachment
*pThis
);
110 static EditFieldHandlePtr
editHandleField(StoredFieldType
*pField
,
111 SimpleAttachment
*pThis
);
113 static void syncField(StoredFieldType
*pField
,
114 StoredFieldType
*pSourceField
,
115 ConstFieldMaskArg syncMode
,
117 AspectOffsetStore
&oOffsets
);
121 struct MFieldValFunctions
123 static StoredFieldType
*editFieldPtr (StoredFieldType
*pField
,
124 SimpleAttachment
*pThis
);
127 static EditFieldHandlePtr
editHandleField(StoredFieldType
*pField
,
128 SimpleAttachment
*pThis
);
130 static void syncField(StoredFieldType
*pField
,
131 StoredFieldType
*pSourceField
,
132 ConstFieldMaskArg syncMode
,
134 AspectOffsetStore
&oOffsets
);
138 struct MFieldPtrFunctions
140 static StoredFieldType
*editFieldPtr (StoredFieldType
*pField
,
141 SimpleAttachment
*pThis
);
144 static EditFieldHandlePtr
editHandleField(StoredFieldType
*pField
,
145 SimpleAttachment
*pThis
);
147 static void syncField(StoredFieldType
*pField
,
148 StoredFieldType
*pSourceField
,
149 ConstFieldMaskArg syncMode
,
151 AspectOffsetStore
&oOffsets
);
156 boost::mpl::if_
<boost::mpl::bool_
<
157 (StoredFieldType::isPointerField
== true)>,
159 SFieldValFunctions
>::type SFieldFunctions
;
162 boost::mpl::if_
<boost::mpl::bool_
<
163 (StoredFieldType::isPointerField
== true)>,
165 MFieldValFunctions
>::type MFieldFunctions
;
168 boost::mpl::if_
<boost::mpl::bool_
<(StoredFieldType::isSField
== true)>,
170 MFieldFunctions
>::type FieldFunctions
;
173 /*========================== PUBLIC =================================*/
177 using Inherited::getField
;
179 OSG_GEN_INTERNALPTR(Self
);
183 SimpleFieldId
= Inherited::NextFieldId
,
184 NextFieldId
= SimpleFieldId
+ 1
187 static const BitVector SimpleFieldMask
= Inherited::NextFieldMask
;
188 static const BitVector NextFieldMask
= SimpleFieldMask
<< 1;
191 /*---------------------------------------------------------------------*/
192 /*! \name General Fieldcontainer Declaration */
195 OSG_FIELD_CONTAINER_TMPL_DECL
;
198 /*---------------------------------------------------------------------*/
202 StoredFieldType
*editFieldPtr(void);
203 const StoredFieldType
*getFieldPtr (void) const;
205 const StoredFieldType
&getField (void) const;
208 /*---------------------------------------------------------------------*/
209 /*! \name Binary Access */
212 virtual SizeT
getBinSize (ConstFieldMaskArg whichField
);
214 virtual void copyToBin (BinaryDataHandler
&pMem
,
215 ConstFieldMaskArg whichField
);
216 virtual void copyFromBin(BinaryDataHandler
&pMem
,
217 ConstFieldMaskArg whichField
);
220 /*---------------------------------------------------------------------*/
224 virtual void dump( UInt32 uiIndent
= 0,
225 const BitVector bvFlags
= 0) const;
228 /*========================== PRIVATE ================================*/
232 /*---------------------------------------------------------------------*/
233 /*! \name Type information */
236 static TypeObject _type
;
238 static void classDescInserter(TypeObject
&oType
);
239 static Char8
*getClassname (void );
242 /*---------------------------------------------------------------------*/
246 StoredFieldType _field
;
249 /*---------------------------------------------------------------------*/
250 /*! \name Constructors */
253 SimpleAttachment(void);
254 SimpleAttachment(const SimpleAttachment
&source
);
257 /*---------------------------------------------------------------------*/
258 /*! \name Destructors */
261 virtual ~SimpleAttachment(void);
264 /*---------------------------------------------------------------------*/
265 /*! \name Destructors */
268 #ifdef OSG_MT_CPTR_ASPECT
269 virtual ObjCPtr
createAspectCopy(const FieldContainer
*pRefAspect
) const;
274 /*---------------------------------------------------------------------*/
278 #ifdef OSG_MT_CPTR_ASPECT
279 virtual void execSyncV( FieldContainer
&oFrom
,
280 ConstFieldMaskArg whichField
,
281 AspectOffsetStore
&oOffsets
,
282 ConstFieldMaskArg syncMode
,
283 const UInt32 uiSyncInfo
);
285 void execSync ( SimpleAttachment
*pFrom
,
286 ConstFieldMaskArg whichField
,
287 AspectOffsetStore
&oOffsets
,
288 ConstFieldMaskArg syncMode
,
289 const UInt32 uiSyncInfo
);
293 /*---------------------------------------------------------------------*/
297 GetFieldHandlePtr
getHandleField (void) const;
298 EditFieldHandlePtr
editHandleField(void);
301 /*========================== PRIVATE ================================*/
305 friend class FieldContainer
;
307 /*! \brief prohibit default functions (move to 'public' if needed) */
308 SimpleAttachment
&operator =(const SimpleAttachment
&source
);
310 void setPointerValue(ArgumentType pVal
);
311 void addPointerValue(ArgumentType pVal
);
314 #define OSG_SIMPLEATTACHMENT_INST(DESC) \
316 void SimpleAttachment< DESC >::classDescInserter(TypeObject &oType) \
318 FieldDescriptionBase *pDesc; \
320 typedef StoredFieldType::Description SFDesc; \
322 pDesc = new SFDesc( \
323 StoredFieldType::getClassType(), \
324 DESC::getFieldName(), \
326 OSG_RC_FIELD_DESC(Self::Simple), \
328 Field::MFDefaultFlags, \
329 static_cast<FieldEditMethodSig>(&Self::editHandleField), \
330 static_cast<FieldGetMethodSig >(&Self::getHandleField )); \
332 oType.addInitialDesc(pDesc); \
336 SimpleAttachment< DESC >::TypeObject \
337 SimpleAttachment<DESC >::_type( \
338 DESC::getTypeName (), \
339 DESC::getParentTypeName(), \
340 DESC::getGroupName (), \
342 reinterpret_cast<PrototypeCreateF>(&Self::createEmptyLocal), \
345 reinterpret_cast<InitalInsertDescFunc>(&Self::classDescInserter), \
351 #include "OSGSimpleAttachment.inl"
353 #endif /* _OSGSIMPLEATTACHMENT_H_ */