changed: auto add updateData callback to stages so that stagedata can be updated...
[opensg.git] / Source / Base / FieldContainer / Mixins / OSGSimpleAttachment.h
blob0d305a114c44bc5b0a15c8be578d20ad3a2e4c89
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 #ifndef _OSGSIMPLEATTACHMENT_H_
40 #define _OSGSIMPLEATTACHMENT_H_
42 #ifdef __sgi
43 #pragma once
44 #endif
46 #include "OSGAttachment.h"
48 #include "boost/bind.hpp"
50 OSG_BEGIN_NAMESPACE
52 /*! \ingroup GrpBaseFieldContainerMixins
53 \ingroup GrpLibOSGBase
56 template <class AttachmentDescT>
57 class SimpleAttachment : public Attachment
60 /*========================== PUBLIC =================================*/
62 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 ===============================*/
81 protected:
83 typedef Inherited::TypeObject TypeObject;
84 typedef TypeObject::InitPhase InitPhase;
86 /*! \nohierarchy */
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,
99 UInt32 uiSyncInfo,
100 AspectOffsetStore &oOffsets );
103 /*! \nohierarchy */
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,
116 UInt32 uiSyncInfo,
117 AspectOffsetStore &oOffsets );
120 /*! \nohierarchy */
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,
133 UInt32 uiSyncInfo,
134 AspectOffsetStore &oOffsets );
137 /*! \nohierarchy */
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,
150 UInt32 uiSyncInfo,
151 AspectOffsetStore &oOffsets );
155 typedef typename
156 boost::mpl::if_<boost::mpl::bool_<
157 (StoredFieldType::isPointerField == true)>,
158 SFieldPtrFunctions,
159 SFieldValFunctions>::type SFieldFunctions;
161 typedef typename
162 boost::mpl::if_<boost::mpl::bool_<
163 (StoredFieldType::isPointerField == true)>,
164 MFieldPtrFunctions,
165 MFieldValFunctions>::type MFieldFunctions;
167 typedef typename
168 boost::mpl::if_<boost::mpl::bool_<(StoredFieldType::isSField == true)>,
169 SFieldFunctions,
170 MFieldFunctions>::type FieldFunctions;
173 /*========================== PUBLIC =================================*/
175 public:
177 using Inherited::getField;
179 OSG_GEN_INTERNALPTR(Self);
181 enum
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 */
193 /*! \{ */
195 OSG_FIELD_CONTAINER_TMPL_DECL;
197 /*! \} */
198 /*---------------------------------------------------------------------*/
199 /*! \name Get */
200 /*! \{ */
202 StoredFieldType *editFieldPtr(void);
203 const StoredFieldType *getFieldPtr (void) const;
205 const StoredFieldType &getField (void) const;
207 /*! \} */
208 /*---------------------------------------------------------------------*/
209 /*! \name Binary Access */
210 /*! \{ */
212 virtual SizeT getBinSize (ConstFieldMaskArg whichField);
214 virtual void copyToBin (BinaryDataHandler &pMem,
215 ConstFieldMaskArg whichField);
216 virtual void copyFromBin(BinaryDataHandler &pMem,
217 ConstFieldMaskArg whichField);
219 /*! \} */
220 /*---------------------------------------------------------------------*/
221 /*! \name Dump */
222 /*! \{ */
224 virtual void dump( UInt32 uiIndent = 0,
225 const BitVector bvFlags = 0) const;
227 /*! \} */
228 /*========================== PRIVATE ================================*/
230 protected:
232 /*---------------------------------------------------------------------*/
233 /*! \name Type information */
234 /*! \{ */
236 static TypeObject _type;
238 static void classDescInserter(TypeObject &oType);
239 static Char8 *getClassname (void );
241 /*! \} */
242 /*---------------------------------------------------------------------*/
243 /*! \name Fields */
244 /*! \{ */
246 StoredFieldType _field;
248 /*! \} */
249 /*---------------------------------------------------------------------*/
250 /*! \name Constructors */
251 /*! \{ */
253 SimpleAttachment(void);
254 SimpleAttachment(const SimpleAttachment &source);
256 /*! \} */
257 /*---------------------------------------------------------------------*/
258 /*! \name Destructors */
259 /*! \{ */
261 virtual ~SimpleAttachment(void);
263 /*! \} */
264 /*---------------------------------------------------------------------*/
265 /*! \name Destructors */
266 /*! \{ */
268 #ifdef OSG_MT_CPTR_ASPECT
269 virtual ObjCPtr createAspectCopy(const FieldContainer *pRefAspect) const;
270 #endif
273 /*! \} */
274 /*---------------------------------------------------------------------*/
275 /*! \name Sync */
276 /*! \{ */
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);
290 #endif
292 /*! \} */
293 /*---------------------------------------------------------------------*/
294 /*! \name Edit */
295 /*! \{ */
297 GetFieldHandlePtr getHandleField (void) const;
298 EditFieldHandlePtr editHandleField(void);
300 /*! \} */
301 /*========================== PRIVATE ================================*/
303 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) \
315 template <> inline \
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(), \
325 "", \
326 OSG_RC_FIELD_DESC(Self::Simple), \
327 false, \
328 Field::MFDefaultFlags, \
329 static_cast<FieldEditMethodSig>(&Self::editHandleField), \
330 static_cast<FieldGetMethodSig >(&Self::getHandleField )); \
332 oType.addInitialDesc(pDesc); \
335 template <> \
336 SimpleAttachment< DESC >::TypeObject \
337 SimpleAttachment<DESC >::_type( \
338 DESC::getTypeName (), \
339 DESC::getParentTypeName(), \
340 DESC::getGroupName (), \
341 0, \
342 reinterpret_cast<PrototypeCreateF>(&Self::createEmptyLocal), \
343 NULL, \
344 NULL, \
345 reinterpret_cast<InitalInsertDescFunc>(&Self::classDescInserter), \
346 false, \
349 OSG_END_NAMESPACE
351 #include "OSGSimpleAttachment.inl"
353 #endif /* _OSGSIMPLEATTACHMENT_H_ */