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 \*---------------------------------------------------------------------------*/
39 #ifndef _OSGMATERIALMAPFIELDS_H_
40 #define _OSGMATERIALMAPFIELDS_H_
45 #include "OSGSystemDef.h"
46 #include "OSGSField.h"
47 #include "OSGFieldTraits.h"
48 #include "OSGContainerForwards.h"
49 #include "OSGRenderPropertiesPool.h"
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
;
77 /*! \ingroup GrpSystemMaterialFieldSFields \ingroup GrpLibOSGSystem
80 struct SFMaterialMapKey
: public SField
<MaterialMapKey
> {};
82 /*! \ingroup GrpSystemMaterialFieldMFields \ingroup GrpLibOSGSystem
84 struct MFMaterialMapKey
: public MField
<MaterialMapKey
> {};
87 /*! \ingroup GrpSystemMaterialFieldTraits
88 \ingroup GrpLibOSGSystem
92 struct FieldTraits
<MaterialMap
> :
93 public FieldTraitsTemplateBase
<MaterialMap
>
97 static DataType _type
;
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
,
127 // defaut: individual field sizes
128 for(SizeT i
= 0; i
< numObjects
; ++i
)
130 size
+= getBinSize(aMaps
[i
]);
136 static OSG_SYSTEM_DLLMAPPING
void copyToBin( BinaryDataHandler
&pMem
,
137 const MaterialMap
&aMap
);
139 static void copyToBin( BinaryDataHandler
&pMem
,
140 const MaterialMap
*aMaps
,
143 for(SizeT i
= 0; i
< numObjects
; ++i
)
145 copyToBin(pMem
, aMaps
[i
]);
149 static OSG_SYSTEM_DLLMAPPING
void copyFromBin(BinaryDataHandler
&pMem
,
152 static void copyFromBin(BinaryDataHandler
&pMem
,
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
;
169 /*! \ingroup GrpSystemMaterialFieldSFields \ingroup GrpLibOSGSystem
172 struct SFMaterialPtrMap
: public SField
<MaterialMap
> {};
175 /*! \ingroup GrpSystemMaterialFieldHandle
176 \ingroup GrpLibOSGSystem
180 class OSG_SYSTEM_DLLMAPPING GetSFieldHandle
<SFMaterialPtrMap
> :
181 public GetMapFieldHandle
183 /*========================= PROTECTED ===============================*/
187 typedef GetMapFieldHandle Inherited
;
188 typedef GetFieldHandle Base
;
190 /*========================== 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
241 class OSG_SYSTEM_DLLMAPPING
242 EditSFieldHandle
<SFMaterialPtrMap
> : public EditMapFieldHandle
244 /*========================== PRIVATE ================================*/
248 void operator =(const EditSFieldHandle
&rhs
);
250 /*========================= 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
;
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
,
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;
342 #include "OSGMaterialMapFields.inl"
344 #endif /* _OSGMATERIALMAPFIELDS_H_ */