OSGAttachmentMapFieldTraits.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #ifndef _OSGATTACHMENTMAPFIELDTRAITS_H_
00040 #define _OSTATTACHMENTMAPFIELDTRAITS_H_
00041 #ifdef __sgi
00042 #pragma once
00043 #endif
00044
00045 #include "OSGFieldTraits.h"
00046 #include "OSGContainerForwards.h"
00047 #include "OSGContainerPtrFuncs.h"
00048
00049 #include "OSGFieldContainerAttachment.h"
00050 #include "OSGFieldBundleAttachment.h"
00051
00052 #include "map"
00053
00054 OSG_BEGIN_NAMESPACE
00055
00056 typedef std::map<UInt32,
00057 FieldBundleAttachmentP > FieldBundleAttachmentMap;
00058 typedef std::map<UInt32,
00059 FieldContainerAttachmentPtr> FieldContainerAttachmentMap;
00060
00061 #if !defined(OSG_DO_DOC) || (OSG_DOC_LEVEL >= 3)
00062
00063 #ifdef OSG_DOC_FILES_IN_MODULE
00064
00068 #endif
00069
00072 #if !defined(OSG_DOC_DEV_TRAITS)
00073
00074 #endif
00075
00076 template <>
00077 struct FieldTraits<FieldBundleAttachmentMap> :
00078 public FieldTraitsTemplateBase<FieldBundleAttachmentMap>
00079 {
00080 private:
00081
00082 static DataType _type;
00083
00084 public:
00085
00086 typedef FieldTraits<FieldBundleAttachmentMap> Self;
00087
00088
00089 enum { Convertible = Self::NotConvertible };
00090
00091 static OSG_SYSTEM_DLLMAPPING
00092 DataType &getType (void);
00093
00094 static const Char8 *getSName (void)
00095 {
00096 return "SFBundeAttachmentMap";
00097 }
00098
00099 static const Char8 *getMName (void)
00100 {
00101 return "MFBundleAttachmentMap";
00102 }
00103 };
00104
00105 #if !defined(OSG_DOC_DEV_TRAITS)
00106
00108 #endif
00109
00110
00113 #if !defined(OSG_DOC_DEV_TRAITS)
00114
00115 #endif
00116
00117 template <>
00118 struct FieldTraits<FieldContainerAttachmentMap> :
00119 public FieldTraitsTemplateBase<FieldContainerAttachmentMap>
00120 {
00121 private:
00122
00123 static DataType _type;
00124
00125 public:
00126
00127 typedef FieldTraits<FieldContainerAttachmentMap> Self;
00128
00129
00130 enum { Convertible = Self::NotConvertible };
00131
00132 static OSG_SYSTEM_DLLMAPPING
00133 DataType &getType (void);
00134
00135 static const Char8 *getSName (void)
00136 {
00137 return "SFFieldContainerAttachmentPtrMap";
00138 }
00139
00140 static const Char8 *getMName (void)
00141 {
00142 return "MFFieldContainerAttachmentPtrMap";
00143 }
00144
00145 static UInt32 getBinSize(const FieldContainerAttachmentMap &aMap)
00146 {
00147 FieldContainerAttachmentMap::const_iterator mapIt = aMap.begin();
00148 FieldContainerAttachmentMap::const_iterator mapEnd = aMap.end ();
00149
00150 UInt32 numPublicObjects = 0;
00151
00152 for(; mapIt != mapEnd; ++mapIt)
00153 {
00154 if(mapIt->second->getInternal().getValue() == false)
00155 {
00156 ++numPublicObjects;
00157 }
00158 }
00159
00160
00161 return sizeof(UInt32) +
00162 numPublicObjects * (sizeof(UInt16) + sizeof(UInt32));
00163 }
00164
00165 static UInt32 getBinSize(const FieldContainerAttachmentMap *aMaps,
00166 UInt32 numObjects)
00167 {
00168 UInt32 size = 0;
00169
00170
00171 for(UInt32 i = 0; i < numObjects; ++i)
00172 {
00173 size += getBinSize(aMaps[i]);
00174 }
00175
00176 return size;
00177 }
00178
00179 static void copyToBin( BinaryDataHandler &pMem,
00180 const FieldContainerAttachmentMap &aMap )
00181 {
00182 FieldContainerAttachmentMap::const_iterator mapIt = aMap.begin();
00183 FieldContainerAttachmentMap::const_iterator mapEnd = aMap.end ();
00184
00185 UInt32 numPublicObjects = 0;
00186 UInt16 binding;
00187 UInt32 fcId;
00188
00189 for(; mapIt != mapEnd; ++mapIt)
00190 {
00191 if(mapIt->second->getInternal().getValue() == false)
00192 {
00193 ++numPublicObjects;
00194 }
00195 }
00196
00197 pMem.putValue(numPublicObjects);
00198
00199 for(mapIt = aMap.begin(); mapIt != mapEnd; ++mapIt)
00200 {
00201 if(mapIt->second->getInternal().getValue() == false)
00202 {
00203 binding = mapIt->first & 0xFFFF;
00204 fcId = OSG::getContainerId(mapIt->second);
00205
00206 pMem.putValue(binding);
00207 pMem.putValue(fcId );
00208 }
00209 }
00210 }
00211
00212 static void copyToBin( BinaryDataHandler &pMem,
00213 const FieldContainerAttachmentMap *aMaps,
00214 UInt32 numObjects)
00215 {
00216 for(UInt32 i = 0; i < numObjects; ++i)
00217 {
00218 copyToBin(pMem, aMaps[i]);
00219 }
00220 }
00221
00222 static void copyFromBin(BinaryDataHandler &pMem,
00223 FieldContainerAttachmentMap &aMap )
00224 {
00225 FieldContainerAttachmentPtr attPtr;
00226 UInt32 key;
00227 UInt16 binding;
00228 UInt32 fcId;
00229 UInt32 size;
00230
00231 pMem.getValue(size);
00232 aMap.clear();
00233
00234 for(UInt32 i = 0; i < size; ++i)
00235 {
00236 pMem.getValue(binding);
00237 pMem.getValue(fcId );
00238
00239 attPtr = dynamic_cast<FieldContainerAttachmentPtr>(
00240 FieldContainerFactory::the()->getMappedContainer(fcId));
00241
00242 key = (static_cast<UInt32>(attPtr->getGroupId()) << 16) | binding;
00243
00244 aMap.insert(FieldContainerAttachmentMap::value_type(key, attPtr));
00245 }
00246 }
00247
00248 static void copyFromBin(BinaryDataHandler &pMem,
00249 FieldContainerAttachmentMap *aMaps,
00250 UInt32 numObjects)
00251 {
00252 for(UInt32 i = 0; i < numObjects; ++i)
00253 {
00254 copyFromBin(pMem, aMaps[i]);
00255 }
00256 }
00257 };
00258
00259 #if !defined(OSG_DOC_DEV_TRAITS)
00260
00262 #endif
00263
00264 #endif // !defined(OSG_DO_DOC) || (OSG_DOC_LEVEL >= 3)
00265
00266 OSG_END_NAMESPACE
00267
00268 #endif