yapf/blob.hpp
branchcustombridgeheads
changeset 5619 a2f1d08e2215
parent 5616 0570ae953222
child 5620 3b40a41f90d2
--- a/yapf/blob.hpp	Sun Dec 31 23:48:04 2006 +0000
+++ b/yapf/blob.hpp	Mon Jan 01 01:43:40 2007 +0000
@@ -74,7 +74,7 @@
 		AppendRaw(src);
 	}
 	/** move constructor - take ownership of blob data */
-	FORCEINLINE CBlobBaseSimple(CHdr*& pHdr_1) {assert(pHdr_1 != NULL); ptr_u.m_pHdr_1 = pHdr_1; pHdr_1 = NULL;}
+	FORCEINLINE CBlobBaseSimple(CHdr * const & pHdr_1) {assert(pHdr_1 != NULL); ptr_u.m_pHdr_1 = pHdr_1; *(CHdr**)&pHdr_1 = NULL;}
 	/** destructor */
 	FORCEINLINE ~CBlobBaseSimple() { Free(); }
 protected:
@@ -219,7 +219,7 @@
 };
 
 /** Blob - simple dynamic Titem_ array. Titem_ (template argument) is a placeholder for any type.
-*  Titem_ can be any size_tegral type, posize_ter, or structure. Using Blob instead of just plain C array
+*  Titem_ can be any integral type, pointer, or structure. Using Blob instead of just plain C array
 *  simplifies the resource management in several ways:
 *  1. When adding new item(s) it automatically grows capacity if needed.
 *  2. When variable of type Blob comes out of scope it automatically frees the data buffer.
@@ -231,12 +231,13 @@
 public:
 	typedef Titem_ Titem;
 	typedef Tbase_ Tbase;
+	typedef typename Tbase::size_t size_t;
 
 	static const size_t Titem_size = sizeof(Titem);
 
 	struct OnTransfer {
 		typename Tbase_::CHdr *m_pHdr_1;
-		OnTransfer(OnTransfer& src) : m_pHdr_1(src.m_pHdr_1) {assert(src.m_pHdr_1 != NULL); src.m_pHdr_1 = NULL;}
+		OnTransfer(const OnTransfer& src) : m_pHdr_1(src.m_pHdr_1) {assert(src.m_pHdr_1 != NULL); *(typename Tbase_::CHdr**)&src.m_pHdr_1 = NULL;}
 		OnTransfer(CBlobT& src) : m_pHdr_1(src.ptr_u.m_pHdr_1) {src.InitEmpty();}
 		~OnTransfer() {assert(m_pHdr_1 == NULL);}
 	};
@@ -246,31 +247,31 @@
 	/** Constructor - makes new Blob with data */
 	FORCEINLINE CBlobT(const Titem_ *p, size_t num_items) : Tbase((int8*)p, num_items * Titem_size) {}
 	/** Copy constructor - make new blob to become copy of the original (source) blob */
-	FORCEINLINE CBlobT(const Tbase& src) : Tbase(src) {assert((RawSize() % Titem_size) == 0);}
+	FORCEINLINE CBlobT(const Tbase& src) : Tbase(src) {assert((Tbase::RawSize() % Titem_size) == 0);}
 	/** Take ownership constructor */
-	FORCEINLINE CBlobT(OnTransfer& ot) : Tbase(ot.m_pHdr_1) {}
+	FORCEINLINE CBlobT(const OnTransfer& ot) : Tbase(ot.m_pHdr_1) {}
 	/** Destructor - ensures that allocated memory (if any) is freed */
 	FORCEINLINE ~CBlobT() { Free(); }
 	/** Check the validity of item index (only in debug mode) */
 	FORCEINLINE void CheckIdx(size_t idx) { assert(idx >= 0); assert(idx < Size()); }
 	/** Return posize_ter to the first data item - non-const version */
-	FORCEINLINE Titem* Data() { return (Titem*)RawData(); }
+	FORCEINLINE Titem* Data() { return (Titem*)Tbase::RawData(); }
 	/** Return posize_ter to the first data item - const version */
-	FORCEINLINE const Titem* Data() const { return (const Titem*)RawData(); }
+	FORCEINLINE const Titem* Data() const { return (const Titem*)Tbase::RawData(); }
 	/** Return posize_ter to the idx-th data item - non-const version */
 	FORCEINLINE Titem* Data(size_t idx) { CheckIdx(idx); return (Data() + idx); }
 	/** Return posize_ter to the idx-th data item - const version */
 	FORCEINLINE const Titem* Data(size_t idx) const { CheckIdx(idx); return (Data() + idx); }
 	/** Return number of items in the Blob */
-	FORCEINLINE size_t Size() const { return (RawSize() / Titem_size); }
+	FORCEINLINE size_t Size() const { return (Tbase::RawSize() / Titem_size); }
 	/** Return total number of items that can fit in the Blob without buffer reallocation */
-	FORCEINLINE size_t MaxSize() const { return (MaxRawSize() / Titem_size); }
+	FORCEINLINE size_t MaxSize() const { return (Tbase::MaxRawSize() / Titem_size); }
 	/** Return number of additional items that can fit in the Blob without buffer reallocation */
-	FORCEINLINE size_t GetReserve() const { return ((MaxRawSize() - RawSize()) / Titem_size); }
+	FORCEINLINE size_t GetReserve() const { return ((Tbase::MaxRawSize() - Tbase::RawSize()) / Titem_size); }
 	/** Free the memory occupied by Blob destroying all items */
 	FORCEINLINE void Free()
 	{
-		assert((RawSize() % Titem_size) == 0);
+		assert((Tbase::RawSize() % Titem_size) == 0);
 		size_t old_size = Size();
 		if (old_size > 0) {
 			// destroy removed items;
@@ -280,7 +281,7 @@
 		Tbase::Free();
 	}
 	/** Grow number of data items in Blob by given number - doesn't construct items */
-	FORCEINLINE Titem* GrowSizeNC(size_t num_items) { return (Titem*)GrowRawSize(num_items * Titem_size); }
+	FORCEINLINE Titem* GrowSizeNC(size_t num_items) { return (Titem*)Tbase::GrowRawSize(num_items * Titem_size); }
 	/** Grow number of data items in Blob by given number - constructs new items (using Titem_'s default constructor) */
 	FORCEINLINE Titem* GrowSizeC(size_t num_items)
 	{
@@ -290,7 +291,7 @@
 	/** Destroy given number of items and reduce the Blob's data size */
 	FORCEINLINE void ReduceSize(size_t num_items)
 	{
-		assert((RawSize() % Titem_size) == 0);
+		assert((Tbase::RawSize() % Titem_size) == 0);
 		size_t old_size = Size();
 		assert(num_items <= old_size);
 		size_t new_size = (num_items <= old_size) ? (old_size - num_items) : 0;
@@ -298,7 +299,7 @@
 		Titem* pI_last_to_destroy = Data(new_size);
 		for (Titem* pI = Data(old_size - 1); pI >= pI_last_to_destroy; pI--) pI->~Titem();
 		// remove them
-		ReduceRawSize(num_items * Titem_size);
+		Tbase::ReduceRawSize(num_items * Titem_size);
 	}
 	/** Append one data item at the end (calls Titem_'s default constructor) */
 	FORCEINLINE Titem* AppendNew()
@@ -344,11 +345,11 @@
 		// destroy the last item
 		pLast->~Titem_();
 		// and reduce the raw blob size
-		ReduceRawSize(Titem_size);
+		Tbase::ReduceRawSize(Titem_size);
 	}
 	/** Ensures that given number of items can be added to the end of Blob. Returns posize_ter to the
 	*  first free (unused) item */
-	FORCEINLINE Titem* MakeFreeSpace(size_t num_items) { return (Titem*)MakeRawFreeSpace(num_items * Titem_size); }
+	FORCEINLINE Titem* MakeFreeSpace(size_t num_items) { return (Titem*)Tbase::MakeRawFreeSpace(num_items * Titem_size); }
 
 	FORCEINLINE OnTransfer Transfer() {return OnTransfer(*this);};
 };