fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / Contrib / ComplexSceneManager / VRMLNodes / OSGValueAccumulator.h
blob3ccc451722cb1ff8b9034c404e5699c794e9bff1
1 /*---------------------------------------------------------------------------*\
2 * OpenSG *
3 * *
4 * *
5 * Copyright (C) 2000-2006 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 _OSGVALUEACCUMULATOR_H_
40 #define _OSGVALUEACCUMULATOR_H_
41 #ifdef __sgi
42 #pragma once
43 #endif
46 #include "OSGConfig.h"
47 #include "OSGContribCSMDef.h"
49 #include "OSGCounter.h" // Parent
51 #include "OSGSysFields.h" // Step type
52 #include "OSGBaseFields.h"
53 #include "OSGMathFields.h"
54 #include "OSGVecFields.h"
56 OSG_BEGIN_NAMESPACE
58 //! \brief Real32Counter Base Class.
60 template<class Desc>
61 class SValueAccumulator : public NodeCore
63 public:
65 typedef NodeCore Inherited;
66 typedef NodeCore ParentContainer;
67 typedef SValueAccumulator Self;
69 typedef Inherited::TypeObject TypeObject;
70 typedef TypeObject::InitPhase InitPhase;
72 OSG_GEN_INTERNALPTR(Self);
74 /*========================== PUBLIC =================================*/
76 public:
78 enum
80 ValueFieldId = Inherited::NextFieldId,
81 RhsFieldId = ValueFieldId + 1,
82 NextFieldId = RhsFieldId + 1
85 static const OSG::BitVector ValueFieldMask =
86 (TypeTraits<BitVector>::One << ValueFieldId);
88 static const OSG::BitVector RhsFieldMask =
89 (TypeTraits<BitVector>::One << RhsFieldId);
91 typedef typename Desc::SFValueType SFValueType;
92 typedef typename SFValueType::StoredType ValueType;
94 /*---------------------------------------------------------------------*/
95 /*! \name Class Get */
96 /*! \{ */
98 static FieldContainerType &getClassType (void);
99 static UInt32 getClassTypeId (void);
100 static UInt16 getClassGroupId(void);
101 static const Char8 *getClassname (void);
103 /*! \} */
104 /*---------------------------------------------------------------------*/
105 /*! \name FieldContainer Get */
106 /*! \{ */
108 virtual FieldContainerType &getType (void);
109 virtual const FieldContainerType &getType (void) const;
111 virtual UInt32 getContainerSize(void) const;
113 /*! \} */
114 /*---------------------------------------------------------------------*/
115 /*! \name Field Get */
116 /*! \{ */
119 SFValueType *editSFValue (void);
120 const SFValueType *getSFValue (void) const;
122 ValueType &editValue (void);
123 ValueType getValue (void) const;
125 SFValueType *editSFRhs (void);
126 const SFValueType *getSFRhs (void) const;
128 ValueType &editRhs (void);
129 ValueType getRhs (void) const;
131 /*! \} */
132 /*---------------------------------------------------------------------*/
133 /*! \name Field Set */
134 /*! \{ */
136 void setValue(const ValueType value);
137 void setRhs (const ValueType value);
139 /*! \} */
140 /*---------------------------------------------------------------------*/
141 /*! \name Ptr MField Set */
142 /*! \{ */
144 virtual void changed(ConstFieldMaskArg whichField,
145 UInt32 origin,
146 BitVector details );
148 /*! \} */
149 /*---------------------------------------------------------------------*/
150 /*! \name Binary Access */
151 /*! \{ */
153 virtual SizeT getBinSize (ConstFieldMaskArg whichField);
154 virtual void copyToBin (BinaryDataHandler &pMem,
155 ConstFieldMaskArg whichField);
156 virtual void copyFromBin(BinaryDataHandler &pMem,
157 ConstFieldMaskArg whichField);
160 /*! \} */
161 /*---------------------------------------------------------------------*/
162 /*! \name Construction */
163 /*! \{ */
165 static ObjTransitPtr create (void );
166 static Self *createEmpty (void );
168 static ObjTransitPtr createLocal (BitVector bFlags = FCLocal::All);
169 static ObjTransitPtr createDependent (BitVector bFlags = FCLocal::All);
171 static Self *createEmptyLocal(BitVector bFlags = FCLocal::All);
173 /*! \} */
174 /*---------------------------------------------------------------------*/
175 /*! \name Copy */
176 /*! \{ */
178 virtual FieldContainerTransitPtr shallowCopy (void) const;
179 virtual FieldContainerTransitPtr shallowCopyLocal(
180 BitVector bFlags = FCLocal::All) const;
181 virtual FieldContainerTransitPtr shallowCopyDependent(
182 BitVector bFlags ) const;
184 /*! \} */
185 /*========================= PROTECTED ===============================*/
187 protected:
189 static TypeObject _type;
191 static void classDescInserter(TypeObject &oType);
193 /*---------------------------------------------------------------------*/
194 /*! \name Fields */
195 /*! \{ */
197 SFValueType _sfValue;
198 SFValueType _sfRhs;
200 /*! \} */
201 /*---------------------------------------------------------------------*/
202 /*! \name Constructors */
203 /*! \{ */
205 SValueAccumulator(void);
206 SValueAccumulator(const SValueAccumulator &source);
208 /*! \} */
209 /*---------------------------------------------------------------------*/
210 /*! \name Destructors */
211 /*! \{ */
213 virtual ~SValueAccumulator(void);
215 /*! \} */
216 /*---------------------------------------------------------------------*/
217 /*! \name onCreate */
218 /*! \{ */
220 /*! \} */
221 /*---------------------------------------------------------------------*/
222 /*! \name Generic Field Access */
223 /*! \{ */
225 GetFieldHandlePtr getHandleValue (void) const;
226 EditFieldHandlePtr editHandleValue (void);
228 GetFieldHandlePtr getHandleRhs (void) const;
229 EditFieldHandlePtr editHandleRhs (void);
232 /*! \} */
233 /*---------------------------------------------------------------------*/
234 /*! \name Sync */
235 /*! \{ */
237 #ifdef OSG_MT_CPTR_ASPECT
238 virtual void execSyncV( FieldContainer &oFrom,
239 ConstFieldMaskArg whichField,
240 AspectOffsetStore &oOffsets,
241 ConstFieldMaskArg syncMode ,
242 const UInt32 uiSyncInfo);
244 void execSync ( Self *pFrom,
245 ConstFieldMaskArg whichField,
246 AspectOffsetStore &oOffsets,
247 ConstFieldMaskArg syncMode ,
248 const UInt32 uiSyncInfo);
249 #endif
251 /*! \} */
252 /*---------------------------------------------------------------------*/
253 /*! \name Edit */
254 /*! \{ */
256 /*! \} */
257 /*---------------------------------------------------------------------*/
258 /*! \name Aspect Create */
259 /*! \{ */
261 #ifdef OSG_MT_CPTR_ASPECT
262 virtual FieldContainer *createAspectCopy(
263 const FieldContainer *pRefAspect) const;
264 #endif
266 /*! \} */
267 /*---------------------------------------------------------------------*/
268 /*! \name Edit */
269 /*! \{ */
270 /*! \} */
271 /*---------------------------------------------------------------------*/
272 /*! \name Sync */
273 /*! \{ */
275 virtual void resolveLinks(void);
277 /*! \} */
278 /*---------------------------------------------------------------------*/
279 /*! \name Init */
280 /*! \{ */
282 static void initMethod(InitPhase ePhase);
284 /*! \} */
285 /*========================== PRIVATE ================================*/
287 private:
289 friend class FieldContainer;
291 /*---------------------------------------------------------------------*/
293 // prohibit default functions (move to 'public' if you need one)
294 void operator =(const SValueAccumulator &source);
297 #if 0
298 struct Int32EmitterDesc
300 typedef SFInt32 SFValueType;
302 static const Char8 *getClassname(void)
304 return "Int32Emitter";
307 static Int32 getDefault(void)
309 return 0;
312 #endif
314 struct Real32AccumulatorDesc
316 typedef SFReal32 SFValueType;
318 static const Char8 *getClassname(void)
320 return "Real32Accumulator";
323 static Real32 getDefault(void)
325 return 0.f;
328 static void accumulate( Real32 &result,
329 const Real32 rhs )
331 result += rhs;
335 struct Vec2fAccumulatorDesc
337 typedef SFVec2f SFValueType;
339 static const Char8 *getClassname(void)
341 return "Vec2fAccumulator";
344 static Vec2f getDefault(void)
346 return Vec2f(0.f, 0.f);
349 static void accumulate( Vec2f &result,
350 const Vec2f rhs )
352 result += rhs;
354 fprintf(stderr, "step : %f %f, res : %f %f\n",
355 rhs[0],
356 rhs[1],
357 result[0],
358 result[1]);
362 struct MatrixAccumulatorDesc
364 typedef SFMatrix SFValueType;
366 static const Char8 *getClassname(void)
368 return "MatrixAccumulator";
371 static Matrix getDefault(void)
373 Matrix m;
375 m.setIdentity();
377 return m;
380 static void accumulate( Matrix &result,
381 const Matrix &rhs )
383 result.add(rhs);
387 //typedef SValueEmitter<Int32EmitterDesc > Int32Emitter;
388 typedef SValueAccumulator<Real32AccumulatorDesc> Real32Accumulator;
389 typedef SValueAccumulator<Vec2fAccumulatorDesc > Vec2fAccumulator;
390 typedef SValueAccumulator<MatrixAccumulatorDesc> MatrixAccumulator;
392 OSG_END_NAMESPACE
394 #include "OSGValueAccumulator.inl"
396 #endif /* _OSGVALUEACCUMULATOR_H_ */