fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / System / Material / Base / OSGMaterialMapFields.h
blob9da245e4b51eb58fc1218751d28bb37988976e0e
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 _OSGMATERIALMAPFIELDS_H_
40 #define _OSGMATERIALMAPFIELDS_H_
41 #ifdef __sgi
42 #pragma once
43 #endif
45 #include "OSGSystemDef.h"
46 #include "OSGSField.h"
47 #include "OSGFieldTraits.h"
48 #include "OSGContainerForwards.h"
49 #include "OSGRenderPropertiesPool.h"
51 #include "map"
53 OSG_BEGIN_NAMESPACE
55 class PrimeMaterial;
57 /*! \ingroup GrpSystemMaterialFieldTraits
60 typedef RenderPropertiesPool::Singleton::ValueType MaterialMapKey;
62 /*! \ingroup GrpSystemMaterialFieldTraits
65 typedef std::map<MaterialMapKey, PrimeMaterial *> MaterialMap;
67 #ifndef DOXYGEN_SHOULD_SKIP_THIS
68 /*! \ingroup GrpSystemMaterialFieldSFields
71 typedef SField<MaterialMapKey> SFMaterialMapKey;
73 /*! \ingroup GrpSystemMaterialFieldMFields
75 typedef MField<MaterialMapKey> MFMaterialMapKey;
76 #else
77 /*! \ingroup GrpSystemMaterialFieldSFields \ingroup GrpLibOSGSystem
80 struct SFMaterialMapKey : public SField<MaterialMapKey> {};
82 /*! \ingroup GrpSystemMaterialFieldMFields \ingroup GrpLibOSGSystem
84 struct MFMaterialMapKey : public MField<MaterialMapKey> {};
85 #endif
87 /*! \ingroup GrpSystemMaterialFieldTraits
88 \ingroup GrpLibOSGSystem
91 template <>
92 struct FieldTraits<MaterialMap> :
93 public FieldTraitsTemplateBase<MaterialMap>
95 private:
97 static DataType _type;
99 public:
101 typedef FieldTraits<MaterialMap> Self;
103 typedef RenderPropertiesPool KeyPool;
105 enum { Convertible = Self::NotConvertible };
107 static OSG_SYSTEM_DLLMAPPING
108 DataType &getType (void);
110 static const Char8 *getSName (void)
112 return "SFMaterialPtrMap";
115 static const Char8 *getMName (void)
117 return "MFMaterialPtrMap";
120 static OSG_SYSTEM_DLLMAPPING SizeT getBinSize(const MaterialMap &aMap);
122 static SizeT getBinSize(const MaterialMap *aMaps,
123 SizeT numObjects)
125 SizeT size = 0;
127 // defaut: individual field sizes
128 for(SizeT i = 0; i < numObjects; ++i)
130 size += getBinSize(aMaps[i]);
133 return size;
136 static OSG_SYSTEM_DLLMAPPING void copyToBin( BinaryDataHandler &pMem,
137 const MaterialMap &aMap);
139 static void copyToBin( BinaryDataHandler &pMem,
140 const MaterialMap *aMaps,
141 SizeT numObjects)
143 for(SizeT i = 0; i < numObjects; ++i)
145 copyToBin(pMem, aMaps[i]);
149 static OSG_SYSTEM_DLLMAPPING void copyFromBin(BinaryDataHandler &pMem,
150 MaterialMap &aMap );
152 static void copyFromBin(BinaryDataHandler &pMem,
153 MaterialMap *aMaps,
154 SizeT numObjects)
156 for(SizeT i = 0; i < numObjects; ++i)
158 copyFromBin(pMem, aMaps[i]);
163 #ifndef DOXYGEN_SHOULD_SKIP_THIS
164 /*! \ingroup GrpSystemMaterialFieldSFields
167 typedef SField<MaterialMap> SFMaterialPtrMap;
168 #else
169 /*! \ingroup GrpSystemMaterialFieldSFields \ingroup GrpLibOSGSystem
172 struct SFMaterialPtrMap : public SField<MaterialMap> {};
173 #endif
175 /*! \ingroup GrpSystemMaterialFieldHandle
176 \ingroup GrpLibOSGSystem
179 template<>
180 class OSG_SYSTEM_DLLMAPPING GetSFieldHandle<SFMaterialPtrMap> :
181 public GetMapFieldHandle
183 /*========================= PROTECTED ===============================*/
185 protected:
187 typedef GetMapFieldHandle Inherited;
188 typedef GetFieldHandle Base;
190 /*========================== PUBLIC =================================*/
192 public:
194 typedef boost::shared_ptr<GetSFieldHandle> Ptr;
195 typedef FieldTraits<MaterialMap> MapFieldTraits;
196 typedef MapFieldTraits::KeyPool KeyPool;
197 typedef KeyPool::Singleton::ValueType KeyType;
199 /*---------------------------------------------------------------------*/
201 GetSFieldHandle(const GetSFieldHandle &source);
202 GetSFieldHandle(const SFMaterialPtrMap *pField,
203 const FieldDescriptionBase *pDescription,
204 FieldContainer *pContainer );
206 /*---------------------------------------------------------------------*/
208 virtual const FieldType &getType (void) const;
209 virtual bool isPointerField(void) const;
211 /*---------------------------------------------------------------------*/
213 virtual void traverse(TraverseCallback oCallBack);
215 /*---------------------------------------------------------------------*/
217 virtual bool empty (void );
218 virtual void flatten(MapList &vList);
219 virtual void flatten(ContainerList &vList);
221 /*---------------------------------------------------------------------*/
223 virtual void pushValueToStream(OutStream &str) const;
224 virtual void pushSizeToStream (OutStream &str) const;
226 /*---------------------------------------------------------------------*/
228 virtual bool equal(Base::Ptr rhs) const;
230 /*---------------------------------------------------------------------*/
232 SFMaterialPtrMap const * operator ->(void);
233 SFMaterialPtrMap const & operator * (void);
236 /*! \ingroup GrpSystemMaterialFieldHandle
237 \ingroup GrpLibOSGSystem
240 template<>
241 class OSG_SYSTEM_DLLMAPPING
242 EditSFieldHandle<SFMaterialPtrMap> : public EditMapFieldHandle
244 /*========================== PRIVATE ================================*/
246 private:
248 void operator =(const EditSFieldHandle &rhs);
250 /*========================= PROTECTED ===============================*/
252 protected:
254 typedef EditMapFieldHandle Inherited;
255 typedef EditFieldHandle Base;
257 typedef boost::function<void(PrimeMaterial * const,
258 MaterialMapKey )> AddMethod;
260 /*========================== PUBLIC =================================*/
262 FieldContainer *_pContainer;
263 AddMethod _fAddMethod;
265 public:
267 typedef boost::shared_ptr<EditSFieldHandle> Ptr;
268 typedef FieldTraits<MaterialMap> MapFieldTraits;
269 typedef MapFieldTraits::KeyPool KeyPool;
270 typedef KeyPool::Singleton::ValueType KeyType;
272 /*---------------------------------------------------------------------*/
274 EditSFieldHandle(const EditSFieldHandle &source );
275 EditSFieldHandle( SFMaterialPtrMap *pField,
276 const FieldDescriptionBase *pDescription,
277 FieldContainer *pContainer );
279 /*---------------------------------------------------------------------*/
281 virtual const FieldType &getType (void) const;
282 virtual bool isPointerField(void) const;
284 /*---------------------------------------------------------------------*/
286 virtual void add( FieldContainer *rhs,
287 const std::string &szBindings);
289 /*---------------------------------------------------------------------*/
291 virtual void traverse(TraverseCallback oCallBack);
293 /*---------------------------------------------------------------------*/
295 virtual bool empty (void );
296 virtual void flatten(MapList &vList);
297 virtual void flatten(ContainerList &vList);
299 /*---------------------------------------------------------------------*/
301 virtual bool loadFromBin( BinaryDataHandler *pMem,
302 UInt32 uiNumElements,
303 bool hasBindingInfo,
304 std::vector<UInt16> &vBindings,
305 std::vector<UInt32> &vIds );
307 virtual void fillFrom (const std::vector<UInt16> &vBindings,
308 const std::vector<UInt32> &vIds,
309 const std::map<UInt32, UInt32> &vIdMap );
311 /*---------------------------------------------------------------------*/
313 virtual void pushValueToStream(OutStream &str) const;
314 virtual void pushSizeToStream (OutStream &str) const;
316 /*---------------------------------------------------------------------*/
318 void setAddMethod(AddMethod fMethod);
320 virtual bool equal (Base::Ptr rhs ) const;
322 /*---------------------------------------------------------------------*/
324 virtual void pushValueFromCString(const Char8 *str );
326 virtual void copyValues ( GetFieldHandlePtr source) const;
327 virtual void shareValues ( GetFieldHandlePtr source) const;
329 /*---------------------------------------------------------------------*/
331 virtual void cloneValues(
332 GetFieldHandlePtr pSrc,
333 const TypePtrVector &shareTypes = TypePtrVector(),
334 const TypePtrVector &ignoreTypes = TypePtrVector(),
335 const TypeIdVector &shareGroupIds = TypeIdVector (),
336 const TypeIdVector &ignoreGroupIds = TypeIdVector ()) const;
340 OSG_END_NAMESPACE
342 #include "OSGMaterialMapFields.inl"
344 #endif /* _OSGMATERIALMAPFIELDS_H_ */