Jelajahi Sumber

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 tahun lalu
induk
melakukan
4b46794156
2 mengubah file dengan 13 tambahan dan 1 penghapusan
  1. 10 0
      sqstdlib/sqstdblob.cpp
  2. 3 1
      sqstdlib/sqstdblobimpl.h

+ 10 - 0
sqstdlib/sqstdblob.cpp

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

+ 3 - 1
sqstdlib/sqstdblobimpl.h

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