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 \*---------------------------------------------------------------------------*/
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>
61 /*! Base class for all multi field, for example MFMatrix
63 \ingroup GrpBaseFieldMulti
64 \ingroup GrpLibOSGBase
67 template<class ValueT
,
69 class AllocT
OSG_STL_ALLOCATOR_DEFAULT(ValueT
)>
70 class MField
: public Field
72 /*========================== PUBLIC =================================*/
76 #ifndef DOXYGEN_SHOULD_SKIP_THIS
77 typedef MFieldVector
<ValueT
, AllocT
> StorageType
;
79 typedef vector
<ValueT
, AllocT
> StorageType
;
81 typedef typename
StorageType::Inherited StorageTypeParent
;
83 typedef typename
StorageType::iterator iterator
;
84 typedef typename
StorageType::const_iterator const_iterator
;
87 StorageType::reverse_iterator reverse_iterator
;
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
,
105 typedef ValueT StoredType
;
107 typedef typename
MFieldTraits::ArgumentType ArgumentType
;
109 typedef FieldDescription
<
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 */
134 static const FieldType
&getClassType(void);
137 /*---------------------------------------------------------------------*/
138 /*! \name Constructors */
142 MField(const MField
&obj
);
143 explicit MField(const UInt32 size
);
146 /*---------------------------------------------------------------------*/
147 /*! \name Destructor */
153 /*---------------------------------------------------------------------*/
157 StorageType
&getValues(void);
158 const StorageType
&getValues(void) const;
161 /*---------------------------------------------------------------------*/
165 void setValues (const StorageType
&value
);
166 void setValues (const StorageTypeParent
&value
);
167 void setValues (const Self
&obj
);
169 void addValueFromCString(const Char8
*str
);
172 /*---------------------------------------------------------------------*/
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
,
181 void pushIndexedValueToStream (OutStream
&str
,
183 void pushSizeToStream (OutStream
&str
) const;
186 /*---------------------------------------------------------------------*/
187 /*! \name Binary Interface */
190 SizeT
getBinSize (void ) const;
192 void copyToBin (BinaryDataHandler
&pMem
) const;
193 void copyFromBin(BinaryDataHandler
&pMem
);
196 /*---------------------------------------------------------------------*/
197 /*! \name STL Interface */
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;
222 iterator
insert (size_type index
,
223 ArgumentType value
);
224 iterator
insert (iterator pos
,
225 ArgumentType value
);
226 void insert (iterator pos
,
228 ArgumentType value
);
229 template <class InputIterator
>
230 void insert (iterator pos
,
232 InputIterator last
);
234 iterator
erase (iterator pos
);
235 void erase (size_type index
);
236 iterator
erase (iterator first
,
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
);
262 void addValue (ArgumentType value
);
266 /*---------------------------------------------------------------------*/
267 /*! \name Index Operator */
270 reference
operator [](size_type index
);
271 const_reference
operator [](size_type index
) const;
274 /*---------------------------------------------------------------------*/
278 bool operator ==(const MField
&source
) const;
281 /*---------------------------------------------------------------------*/
282 /*! \name Assignment */
285 void operator =(const MField
&source
);
288 /*---------------------------------------------------------------------*/
292 #ifdef OSG_MT_CPTR_ASPECT
293 void syncWith (Self
&source
,
294 ConstFieldMaskArg syncMode
,
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 );
312 /*---------------------------------------------------------------------*/
316 void dump( UInt32 uiIndent
= 0,
317 const BitVector bvFlags
= 0) const;
320 /*---------------------------------------------------------------------*/
325 /*========================= PROTECTED ===============================*/
329 /*---------------------------------------------------------------------*/
330 /*! \name Type information */
333 typedef Field Inherited
;
336 /*---------------------------------------------------------------------*/
340 static FieldType _fieldType
;
344 #ifdef OSG_MT_CPTR_ASPECT
345 UInt32 _uiSharedWith
;
348 #if defined(OSG_TMPL_STATIC_MEMBER_NEEDS_HELPER_FCT)
349 const FieldType
&fieldTypeExportHelper(void);
352 static FieldDescriptionBase
*
353 createFieldDescription (const Char8
*szFieldname
,
355 FieldEditMethod fEditMethod
,
356 FieldGetMethod fGetMethod
);
358 static FieldDescriptionBase
*
359 createIdxFieldDescription(const Char8
*szFieldname
,
361 FieldIndexEditMethod fEditMethod
,
362 FieldIndexGetMethod fGetMethod
);
365 /*========================== PRIVATE ================================*/
372 #include "OSGMField.inl"
374 #endif /* _OSGMFIELD_H_ */