changed: auto add updateData callback to stages so that stagedata can be updated...
[opensg.git] / Source / Base / Field / OSGMField.h
blob7ae846a166150b20867ed7c6ac6c7abeaa7f90cd
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 _OSGMFIELD_H_
40 #define _OSGMFIELD_H_
41 #ifdef __sgi
42 #pragma once
43 #endif
45 #include "OSGField.h"
46 #include "OSGFieldTraits.h"
47 #include "OSGSysFieldTraits.h"
48 #include "OSGFieldType.h"
49 #include "OSGMFieldVector.h"
50 #include "OSGBinaryDataHandler.h"
51 #include "OSGFieldHandle.h"
52 #include "OSGFieldDescFactory.h"
54 #include <boost/shared_ptr.hpp>
56 #include <algorithm>
57 #include <sstream>
59 OSG_BEGIN_NAMESPACE
61 /*! Base class for all multi field, for example MFMatrix
62 \ingroup GrpBaseField
63 \ingroup GrpBaseFieldMulti
64 \ingroup GrpLibOSGBase
67 template<class ValueT,
68 Int32 iNamespace = 0,
69 class AllocT OSG_STL_ALLOCATOR_DEFAULT(ValueT)>
70 class MField : public Field
72 /*========================== PUBLIC =================================*/
74 public:
76 #ifndef DOXYGEN_SHOULD_SKIP_THIS
77 typedef MFieldVector<ValueT, AllocT> StorageType;
78 #else
79 typedef vector <ValueT, AllocT> StorageType;
80 #endif
81 typedef typename StorageType::Inherited StorageTypeParent;
83 typedef typename StorageType::iterator iterator;
84 typedef typename StorageType::const_iterator const_iterator;
86 typedef typename
87 StorageType::reverse_iterator reverse_iterator;
88 typedef typename
89 StorageType::const_reverse_iterator const_reverse_iterator;
92 typedef typename StorageType::reference reference;
93 typedef typename StorageType::const_reference const_reference;
95 typedef typename StorageType::size_type size_type;
96 typedef typename StorageType::value_type value_type;
98 typedef FieldTraits <ValueT,
99 iNamespace> MFieldTraits;
101 typedef MField <ValueT,
102 iNamespace,
103 AllocT > Self;
105 typedef ValueT StoredType;
107 typedef typename MFieldTraits::ArgumentType ArgumentType;
109 typedef FieldDescription<
110 MFieldTraits,
111 FieldType::MultiField > Description;
113 typedef EditMFieldHandle <Self > EditHandle;
114 typedef boost::shared_ptr<EditHandle> EditHandlePtr;
116 typedef GetMFieldHandle <Self > GetHandle;
117 typedef boost::shared_ptr<GetHandle> GetHandlePtr;
119 /*---------------------------------------------------------------------*/
121 static const Int32 Namespace = iNamespace;
123 static const bool isSField = false;
124 static const bool isMField = true;
126 static const bool isPointerField = false;
128 static const FieldType::Class Class = FieldType::ValueField;
130 /*---------------------------------------------------------------------*/
131 /*! \name Class Get */
132 /*! \{ */
134 static const FieldType &getClassType(void);
136 /*! \} */
137 /*---------------------------------------------------------------------*/
138 /*! \name Constructors */
139 /*! \{ */
141 MField(void);
142 MField(const MField &obj);
143 explicit MField(const UInt32 size);
145 /*! \} */
146 /*---------------------------------------------------------------------*/
147 /*! \name Destructor */
148 /*! \{ */
150 ~MField(void);
152 /*! \} */
153 /*---------------------------------------------------------------------*/
154 /*! \name Get */
155 /*! \{ */
157 StorageType &getValues(void);
158 const StorageType &getValues(void) const;
160 /*! \} */
161 /*---------------------------------------------------------------------*/
162 /*! \name Set */
163 /*! \{ */
165 void setValues (const StorageType &value);
166 void setValues (const StorageTypeParent &value);
167 void setValues (const Self &obj );
169 void addValueFromCString(const Char8 *str );
171 /*! \} */
172 /*---------------------------------------------------------------------*/
173 /*! \name Push */
174 /*! \{ */
176 void pushValuesToString (std::string &str ) const;
177 void pushValuesFromStream (std::istream &str );
178 void pushValuesToStream (OutStream &str ) const;
179 void pushIndexedValueFromCString(Char8 const *str,
180 UInt32 index);
181 void pushIndexedValueToStream (OutStream &str,
182 UInt32 index) const;
183 void pushSizeToStream (OutStream &str ) const;
185 /*! \} */
186 /*---------------------------------------------------------------------*/
187 /*! \name Binary Interface */
188 /*! \{ */
190 SizeT getBinSize (void ) const;
192 void copyToBin (BinaryDataHandler &pMem) const;
193 void copyFromBin(BinaryDataHandler &pMem);
195 /*! \} */
196 /*---------------------------------------------------------------------*/
197 /*! \name STL Interface */
198 /*! \{ */
200 iterator begin (void );
201 iterator end (void );
203 reverse_iterator rbegin (void );
204 reverse_iterator rend (void );
207 const_iterator begin (void ) const;
208 const_iterator end (void ) const;
210 const_reverse_iterator rbegin (void ) const;
211 const_reverse_iterator rend (void ) const;
214 reference front (void );
215 const_reference front (void ) const;
217 reference back (void );
218 const_reference back (void ) const;
220 void clear (void );
222 iterator insert (size_type index,
223 ArgumentType value );
224 iterator insert (iterator pos,
225 ArgumentType value );
226 void insert (iterator pos,
227 size_type n,
228 ArgumentType value );
229 template <class InputIterator>
230 void insert (iterator pos,
231 InputIterator first,
232 InputIterator last );
234 iterator erase (iterator pos );
235 void erase (size_type index );
236 iterator erase (iterator first,
237 iterator last );
239 iterator find (ArgumentType value );
240 const_iterator find (ArgumentType value ) const;
241 Int32 findIndex(ArgumentType value ) const;
243 void push_back(ArgumentType value );
245 void resize (size_type newsize,
246 StoredType t = StoredType());
247 void reserve (size_type newsize );
249 size_type size (void ) const;
250 UInt32 size32 (void ) const;
252 size_type capacity (void ) const;
253 bool empty (void ) const;
254 void swap (MField &right);
256 void replace (size_type index,
257 ArgumentType value );
258 void replace (iterator pos,
259 ArgumentType value );
261 #ifdef OSG_1_COMPAT
262 void addValue (ArgumentType value );
263 #endif
265 /*! \} */
266 /*---------------------------------------------------------------------*/
267 /*! \name Index Operator */
268 /*! \{ */
270 reference operator [](size_type index);
271 const_reference operator [](size_type index) const;
273 /*! \} */
274 /*---------------------------------------------------------------------*/
275 /*! \name Compare */
276 /*! \{ */
278 bool operator ==(const MField &source) const;
280 /*! \} */
281 /*---------------------------------------------------------------------*/
282 /*! \name Assignment */
283 /*! \{ */
285 void operator =(const MField &source);
287 /*! \} */
288 /*---------------------------------------------------------------------*/
289 /*! \name MT Sync */
290 /*! \{ */
292 #ifdef OSG_MT_CPTR_ASPECT
293 void syncWith (Self &source,
294 ConstFieldMaskArg syncMode,
295 UInt32 uiSyncInfo,
296 AspectOffsetStore &oOffsets );
298 void beginEdit (UInt32 uiAspect,
299 AspectOffsetStore &oOffsets );
302 Self *resolveShare (UInt32 uiAspect,
303 AspectOffsetStore &oOffsets );
305 void terminateShare(UInt32 uiAspect,
306 AspectOffsetStore &oOffsets );
308 bool isShared (void );
309 #endif
311 /*! \} */
312 /*---------------------------------------------------------------------*/
313 /*! \name MT Sync */
314 /*! \{ */
316 void dump( UInt32 uiIndent = 0,
317 const BitVector bvFlags = 0) const;
319 /*! \} */
320 /*---------------------------------------------------------------------*/
321 /*! \name MT Sync */
322 /*! \{ */
324 /*! \} */
325 /*========================= PROTECTED ===============================*/
327 protected:
329 /*---------------------------------------------------------------------*/
330 /*! \name Type information */
331 /*! \{ */
333 typedef Field Inherited;
335 /*! \} */
336 /*---------------------------------------------------------------------*/
337 /*! \name Member */
338 /*! \{ */
340 static FieldType _fieldType;
342 StorageType _values;
344 #ifdef OSG_MT_CPTR_ASPECT
345 UInt32 _uiSharedWith;
346 #endif
348 #if defined(OSG_TMPL_STATIC_MEMBER_NEEDS_HELPER_FCT)
349 const FieldType &fieldTypeExportHelper(void);
350 #endif
352 static FieldDescriptionBase *
353 createFieldDescription (const Char8 *szFieldname,
354 UInt32 uiFieldFlags,
355 FieldEditMethod fEditMethod,
356 FieldGetMethod fGetMethod );
358 static FieldDescriptionBase *
359 createIdxFieldDescription(const Char8 *szFieldname,
360 UInt32 uiFieldFlags,
361 FieldIndexEditMethod fEditMethod,
362 FieldIndexGetMethod fGetMethod );
364 /*! \} */
365 /*========================== PRIVATE ================================*/
367 private:
370 OSG_END_NAMESPACE
372 #include "OSGMField.inl"
374 #endif /* _OSGMFIELD_H_ */