Browse Source

Add a static member to SQBlob to access the class typetag of it, also add new function to set the len of internal buffer this way we can use the buffer directly in functions like fread.

mingodad 13 years ago
parent
commit
4b46794156
2 changed files with 13 additions and 1 deletions
  1. 10 0
      sqstdlib/sqstdblob.cpp
  2. 3 1
      sqstdlib/sqstdblobimpl.h

+ 10 - 0
sqstdlib/sqstdblob.cpp

@@ -11,6 +11,8 @@
 
 
 //Blob
 //Blob
 
 
+SQUserPointer SQBlob::SQBlob_TAG = (SQUserPointer)SQSTD_BLOB_TYPE_TAG;
+
 SQBlob::SQBlob(SQInteger size, SQInteger allocated) {
 SQBlob::SQBlob(SQInteger size, SQInteger allocated) {
     _size = size;
     _size = size;
     _allocated = allocated > 0 ? allocated : size;
     _allocated = allocated > 0 ? allocated : size;
@@ -96,6 +98,14 @@ SQInteger SQBlob::Seek(SQInteger offset, SQInteger origin) {
         default: return -1;
         default: return -1;
     }
     }
     return 0;
     return 0;
+}
+
+bool SQBlob::SetLen(SQInteger len){
+    if(len <= _allocated || Resize(len)){
+        _size = len;
+        return true;
+    }
+    return false;
 }
 }
 
 
 #define SETUP_BLOB(v) \
 #define SETUP_BLOB(v) \

+ 3 - 1
sqstdlib/sqstdblobimpl.h

@@ -28,7 +28,9 @@ struct SQBlob : public SQStream
 	SQInteger Flush() { return 0; }
 	SQInteger Flush() { return 0; }
 	SQInteger Tell() { return _ptr; }
 	SQInteger Tell() { return _ptr; }
 	SQInteger Len() { return _size; }
 	SQInteger Len() { return _size; }
-	SQUserPointer GetBuf(){ return _buf; }
+	SQUserPointer GetBuf(){ return _buf; }
+	bool SetLen(SQInteger len);
+	static SQUserPointer SQBlob_TAG;
 private:
 private:
 	SQInteger _size;
 	SQInteger _size;
 	SQInteger _allocated;
 	SQInteger _allocated;