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 #ifndef SO_MEMORY_OBJECT_H
00026 #define SO_MEMORY_OBJECT_H
00027
00028 #include <Inventor/misc/SoRefCounter.h>
00029 #include <Inventor/STL/map>
00030 #include <Inventor/SbDataType.h>
00031 #include <Inventor/threads/SbThreadMutex.h>
00032
00033 #ifdef _WIN32
00034 #pragma warning(push)
00035 #pragma warning(disable:4251)
00036 #endif
00037
00038 class SoBufferObject;
00039
00041
00042
00043
00044
00045
00046
00047
00048
00050
00069 class SoMemoryObject : public SoRefCounter
00070 {
00071 public:
00072
00078 enum CopyPolicy
00079 {
00083 COPY = 0,
00087 NO_COPY,
00092 NO_COPY_AND_DELETE,
00097 NO_COPY_AND_FREE
00098 };
00099
00105 SoMemoryObject();
00106
00115 SoMemoryObject(void* buf, size_t byteSize, bool owner=true);
00116
00120 SoMemoryObject(void* buf, size_t byteSize, SbDataType type, CopyPolicy policy);
00121
00122
00128 SoMemoryObject(SoBufferObject* bufObj, SbDataType type=SbDataType::UNSIGNED_BYTE, bool owner=true);
00129
00134 virtual ~SoMemoryObject();
00135
00140 void* get() const;
00141
00145 size_t length() const;
00146
00150 inline SbDataType getType() const;
00151
00152 private:
00153
00154 void setOwner(bool f) { m_policy = f ? NO_COPY_AND_FREE:NO_COPY; }
00155
00156
00157 void setBuffer(void *buf, size_t byteSize);
00158
00159
00160 void forceSize(size_t byteSize);
00161
00162 static SoMemoryObject* getMemoryObject(uint32_t id);
00163 uint32_t getId() { return m_index; }
00164 void setId( uint32_t id );
00165
00166 inline SoBufferObject* getBufferObject() const;
00167
00168 private:
00169 void registerMemObj();
00170
00174 void releaseValues();
00175
00179 template <typename T> void deleteValues(void *buffer);
00180
00184 template <typename T> void allocValues(void*& buffer, size_t byteSize);
00185
00186
00187 bool m_userPointer;
00188 SoBufferObject * m_bufferObj;
00189
00190 uint32_t m_index;
00191 static uint32_t index;
00192
00193 typedef std::map< uint32_t, SoMemoryObject*> SoMemObjMap;
00194 typedef SoMemObjMap::value_type SoMemObjValue;
00195 static SoMemObjMap s_memObjMap;
00196 static SbThreadMutex s_accessMutex;
00197
00198 SbDataType m_type;
00199 CopyPolicy m_policy;
00200 };
00201
00202
00203 SbDataType
00204 SoMemoryObject::getType() const
00205 {
00206 return m_type;
00207 }
00208
00209 SoBufferObject*
00210 SoMemoryObject::getBufferObject() const
00211 {
00212 return m_bufferObj;
00213 }
00214
00215 #ifdef _WIN32
00216 #pragma warning(pop)
00217 #endif
00218
00219 #endif // SO_MEMORY_OBJECT_H
00220
00221
00222