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
00070 class SoMemoryObject : public SoRefCounter
00071 {
00072 public:
00073
00079 enum CopyPolicy
00080 {
00084 COPY = 0,
00088 NO_COPY,
00093 NO_COPY_AND_DELETE,
00098 NO_COPY_AND_FREE
00099 };
00100
00106 SoMemoryObject();
00107
00116 SoMemoryObject(void* buf, size_t byteSize, bool owner=true);
00117
00121 SoMemoryObject(void* buf, size_t byteSize, SbDataType type, CopyPolicy policy);
00122
00123
00129 SoMemoryObject(SoBufferObject* bufObj, SbDataType type=SbDataType::UNSIGNED_BYTE, bool owner=true);
00130
00135 virtual ~SoMemoryObject();
00136
00141 void* get() const;
00142
00146 size_t length() const;
00147
00151 inline SbDataType getType() const;
00152
00153 private:
00154
00155 void setOwner(bool f) { m_policy = f ? NO_COPY_AND_FREE:NO_COPY; }
00156
00157
00158 void setBuffer(void *buf, size_t byteSize);
00159
00160
00161 void forceSize(size_t byteSize);
00162
00163 static SoMemoryObject* getMemoryObject(uint32_t id);
00164 uint32_t getId() { return m_index; }
00165 void setId( uint32_t id );
00166
00167 inline SoBufferObject* getBufferObject() const;
00168
00169 private:
00170 void registerMemObj();
00171
00175 void releaseValues();
00176
00180 template <typename T> void deleteValues(void *buffer);
00181
00185 template <typename T> void allocValues(void*& buffer, size_t byteSize);
00186
00187
00188 bool m_userPointer;
00189 SoBufferObject * m_bufferObj;
00190
00191 uint32_t m_index;
00192 static uint32_t index;
00193
00194 typedef std::map< uint32_t, SoMemoryObject*> SoMemObjMap;
00195 typedef SoMemObjMap::value_type SoMemObjValue;
00196 static SoMemObjMap s_memObjMap;
00197 static SbThreadMutex s_accessMutex;
00198
00199 SbDataType m_type;
00200 CopyPolicy m_policy;
00201 };
00202
00203
00204 SbDataType
00205 SoMemoryObject::getType() const
00206 {
00207 return m_type;
00208 }
00209
00210 SoBufferObject*
00211 SoMemoryObject::getBufferObject() const
00212 {
00213 return m_bufferObj;
00214 }
00215
00216 #ifdef _WIN32
00217 #pragma warning(pop)
00218 #endif
00219
00220 #endif // SO_MEMORY_OBJECT_H
00221
00222
00223