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 _OSG_ATTACHMENTMAPFIELDDATATYPE_H_
00040 #define _OSG_ATTACHMENTMAPFIELDDATATYPE_H_
00041
00042 #include <OSGFieldDataType.h>
00043 #include <OSGFieldContainerFieldDataType.h>
00044 #include <OSGFieldContainerPtrForward.h>
00045 #include <OSGAttachmentPtr.h>
00046
00047 #include <map>
00048
00049 OSG_BEGIN_NAMESPACE
00050
00051 typedef std::map<UInt32, AttachmentPtr> AttachmentMap;
00052
00053 #if !defined(OSG_DO_DOC) || (OSG_DOC_LEVEL >= 3)
00054
00055 #ifdef OSG_DOC_FILES_IN_MODULE
00056
00060 #endif
00061
00064 #if !defined(OSG_DOC_DEV_TRAITS)
00065
00066 #endif
00067
00068 template <>
00069 struct FieldTraitsRecurseMapper<AttachmentMap, false> :
00070 public FieldTraitsRecurseBase<AttachmentMap>
00071 {
00072 enum { bHasParent = 0x00 };
00073
00074 static UInt32 getBinSize(const AttachmentMap &oObject)
00075 {
00076 AttachmentMap::const_iterator mapIt = oObject.begin();
00077 AttachmentMap::const_iterator mapEnd = oObject.end();
00078
00079 UInt32 uiNumPublicObjects = 0;
00080
00081 while(mapIt != mapEnd)
00082 {
00083 if(mapIt->second->getInternal().getValue() == false)
00084 {
00085 ++uiNumPublicObjects;
00086 }
00087
00088 ++mapIt;
00089 }
00090
00091 return sizeof(UInt32) +
00092 uiNumPublicObjects * (sizeof(UInt16) + sizeof(UInt32));
00093 }
00094
00095 static UInt32 getBinSize(const AttachmentMap *pObjectStore,
00096 UInt32 uiNumObjects)
00097 {
00098 UInt32 size = 0;
00099
00100
00101 for(UInt32 i = 0; i < uiNumObjects; ++i)
00102 {
00103 size += getBinSize(pObjectStore[i]);
00104 }
00105
00106 return size;
00107 }
00108
00109 static void copyToBin( BinaryDataHandler &pMem,
00110 const AttachmentMap &pObject)
00111 {
00112 UInt16 binding;
00113 UInt32 fcId;
00114 UInt32 uiNumPublicObjects = 0;
00115
00116 AttachmentMap::const_iterator mapIt = pObject.begin();
00117 AttachmentMap::const_iterator mapEnd = pObject.end();
00118
00119 while(mapIt != mapEnd)
00120 {
00121 if(mapIt->second->getInternal().getValue() == false)
00122 {
00123 ++uiNumPublicObjects;
00124 }
00125
00126 ++mapIt;
00127 }
00128
00129 pMem.putValue(uiNumPublicObjects);
00130
00131 mapIt = pObject.begin();
00132
00133 for(; mapIt != mapEnd; ++mapIt)
00134 {
00135 if(mapIt->second->getInternal().getValue() == false)
00136 {
00137 binding = mapIt->first & 0xffff;
00138 fcId = getContainerId(mapIt->second);
00139
00140 pMem.putValue(binding);
00141 pMem.putValue(fcId);
00142 }
00143 }
00144 }
00145
00146 static void copyToBin( BinaryDataHandler &pMem,
00147 const AttachmentMap *pObjectStore,
00148 UInt32 uiNumObjects)
00149 {
00150 for(UInt32 i = 0; i < uiNumObjects; ++i)
00151 {
00152 copyToBin(pMem, pObjectStore[i]);
00153 }
00154 }
00155
00156 static void copyFromBin(BinaryDataHandler &pMem,
00157 AttachmentMap &pObject)
00158 {
00159 FieldContainerPtr fcp;
00160
00161 UInt32 key;
00162 UInt16 binding;
00163 UInt32 fcId;
00164 UInt32 size;
00165
00166 pMem.getValue(size);
00167
00168 pObject.clear();
00169
00170 for(UInt32 i = 0; i < size; ++i)
00171 {
00172 pMem.getValue(binding);
00173 pMem.getValue(fcId);
00174
00175 fcp = FieldContainerFactory::the()->getMappedContainer(fcId);
00176
00177 if(fcp != NullFC)
00178 {
00179 key = (UInt32 (fcp->getGroupId()) << 16) | binding;
00180
00181 (static_cast<FieldContainerPtr &>(pObject[key])) = fcp;
00182 }
00183 else
00184 {
00185 SFATAL << "FieldTraitsRecurseMapper<AttachmentMap, false>::copyFromBin: Couldn't find container id: " << fcId << std::endl;
00186 }
00187 }
00188 }
00189
00190 static void copyFromBin(BinaryDataHandler &pMem,
00191 AttachmentMap *pObjectStore,
00192 UInt32 uiNumObjects)
00193 {
00194 for(UInt32 i = 0; i < uiNumObjects; ++i)
00195 {
00196 copyFromBin(pMem, pObjectStore[i]);
00197 }
00198 }
00199 };
00200
00201 #if !defined(OSG_DOC_DEV_TRAITS)
00202
00204 #endif
00205
00208 #if !defined(OSG_DOC_DEV_TRAITS)
00209
00210 #endif
00211
00212 template <>
00213 struct OSG_SYSTEMLIB_DLLMAPPING FieldDataTraits<AttachmentMap> :
00214 public FieldTraitsRecurseMapper<AttachmentMap, false>
00215 {
00216 static DataType _type;
00217
00218 enum { StringConvertable = 0x01 };
00219 enum { bHasParent = 0x00 };
00220
00221 static DataType &getType (void) { return _type; }
00222 static const Char8 *getSName(void) { return "SFAttachmentMap"; }
00223 static const Char8 *getMName(void) { return "MFAttachmentMap"; }
00224
00225 static bool getFromString( AttachmentMap &,
00226 const Char8 *&)
00227 {
00228 return false;
00229 }
00230
00231 static void putToString (const AttachmentMap &,
00232 std::string &outStr)
00233 {
00234 outStr.assign("AttachmentMap");
00235 }
00236 };
00237
00238 #if !defined(OSG_DOC_DEV_TRAITS)
00239
00241 #endif
00242
00243 #endif // !defined(OSG_DO_DOC) || (OSG_DOC_LEVEL >= 3)
00244
00245 OSG_END_NAMESPACE
00246
00247 #define OSGATTACHMENTMAPFIELDDATATYPE_HEADER_CVSID "@(#)$Id: $"
00248
00249 #endif
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261