yapf/blob.hpp
author tron
Tue, 14 Nov 2006 11:01:59 +0000
changeset 5081 fe3a6da19d9f
parent 4549 106ed18a7675
child 5082 d7719dfaa7e1
permissions -rw-r--r--
(svn r7145) Remove extra semicolons
3900
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
     1
/* $Id$ */
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
     2
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
     3
#ifndef  BLOB_HPP
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
     4
#define  BLOB_HPP
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
     5
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
     6
template <class Titem_>
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
     7
FORCEINLINE void MemCpyT(Titem_* d, const Titem_* s, int num_items = 1)
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
     8
{
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
     9
	memcpy(d, s, num_items * sizeof(Titem_));
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    10
}
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    11
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    12
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    13
/** Base class for simple binary blobs.
4549
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4434
diff changeset
    14
 *  Item is byte.
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4434
diff changeset
    15
 *  The word 'simple' means:
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4434
diff changeset
    16
 *    - no configurable allocator type (always made from heap)
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4434
diff changeset
    17
 *    - no smart deallocation - deallocation must be called from the same
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4434
diff changeset
    18
 *        module (DLL) where the blob was allocated
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4434
diff changeset
    19
 *    - no configurable allocation policy (how big blocks should be allocated)
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4434
diff changeset
    20
 *    - no extra ownership policy (i.e. 'copy on write') when blob is copied
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4434
diff changeset
    21
 *    - no thread synchronization at all */
3900
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    22
class CBlobBaseSimple {
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    23
protected:
4434
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 3972
diff changeset
    24
	struct CHdr {
3900
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    25
		int    m_size;      // actual blob size in bytes
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    26
		int    m_max_size;  // maximum (allocated) size in bytes
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    27
	};
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    28
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    29
	union {
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    30
		int8   *m_pData;
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    31
		CHdr   *m_pHdr_1;
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    32
	} ptr_u;
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    33
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    34
public:
5081
fe3a6da19d9f (svn r7145) Remove extra semicolons
tron
parents: 4549
diff changeset
    35
	ST_CONST(int, Ttail_reserve = 4) // four extra bytes will be always allocated and zeroed at the end
3900
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    36
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    37
	FORCEINLINE CBlobBaseSimple() { InitEmpty(); }
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    38
	FORCEINLINE CBlobBaseSimple(const CBlobBaseSimple& src)
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    39
	{
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    40
		InitEmpty();
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    41
		AppendRaw(src);
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    42
	}
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    43
	FORCEINLINE ~CBlobBaseSimple() { Free(); }
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    44
protected:
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    45
	FORCEINLINE void InitEmpty() { static CHdr hdrEmpty[] = {{0, 0}, {0, 0}}; ptr_u.m_pHdr_1 = &hdrEmpty[1]; }
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    46
	FORCEINLINE void Init(CHdr* hdr) { ptr_u.m_pHdr_1 = &hdr[1]; }
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    47
	FORCEINLINE CHdr& Hdr() { return ptr_u.m_pHdr_1[-1]; }
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    48
	FORCEINLINE const CHdr& Hdr() const { return ptr_u.m_pHdr_1[-1]; }
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    49
	FORCEINLINE int& RawSizeRef() { return Hdr().m_size; };
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    50
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    51
public:
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    52
	FORCEINLINE bool IsEmpty() const { return RawSize() == 0; }
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    53
	FORCEINLINE int RawSize() const { return Hdr().m_size; };
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    54
	FORCEINLINE int MaxRawSize() const { return Hdr().m_max_size; };
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    55
	FORCEINLINE int8* RawData() { return ptr_u.m_pData; }
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    56
	FORCEINLINE const int8* RawData() const { return ptr_u.m_pData; }
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    57
	FORCEINLINE uint32 Crc32() const {return CCrc32::Calc(RawData(), RawSize());}
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    58
	FORCEINLINE void Clear() { RawSizeRef() = 0; }
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    59
	FORCEINLINE void Free() { if (MaxRawSize() > 0) {RawFree(&Hdr()); InitEmpty();} }
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    60
	FORCEINLINE void CopyFrom(const CBlobBaseSimple& src) { Clear(); AppendRaw(src); }
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    61
	FORCEINLINE void MoveFrom(CBlobBaseSimple& src) { Free(); ptr_u.m_pData = src.ptr_u.m_pData; src.InitEmpty(); }
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    62
	FORCEINLINE void Swap(CBlobBaseSimple& src) { int8 *tmp = ptr_u.m_pData; ptr_u.m_pData = src.ptr_u.m_pData; src.ptr_u.m_pData = tmp; }
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    63
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    64
	FORCEINLINE void AppendRaw(int8 *p, int num_bytes)
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    65
	{
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    66
		assert(p != NULL);
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    67
		if (num_bytes > 0) {
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    68
			memcpy(GrowRawSize(num_bytes), p, num_bytes);
4434
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 3972
diff changeset
    69
		} else {
3900
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    70
			assert(num_bytes >= 0);
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    71
		}
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    72
	}
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    73
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    74
	FORCEINLINE void AppendRaw(const CBlobBaseSimple& src)
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    75
	{
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    76
		if (!src.IsEmpty())
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    77
			memcpy(GrowRawSize(src.RawSize()), src.RawData(), src.RawSize());
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    78
	}
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    79
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    80
	/** Reallocate if there is no free space for num_bytes bytes.
4549
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4434
diff changeset
    81
	 *  @return pointer to the new data to be added */
3900
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    82
	FORCEINLINE int8* MakeRawFreeSpace(int num_bytes)
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    83
	{
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    84
		assert(num_bytes >= 0);
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    85
		int new_size = RawSize() + num_bytes;
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    86
		if (new_size > MaxRawSize()) SmartAlloc(new_size);
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    87
		FixTail();
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    88
		return ptr_u.m_pData + RawSize();
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    89
	}
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    90
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    91
	/** Increase RawSize() by num_bytes.
4549
106ed18a7675 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4434
diff changeset
    92
	 *  @return pointer to the new data added */
3900
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    93
	FORCEINLINE int8* GrowRawSize(int num_bytes)
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    94
	{
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    95
		int8* pNewData = MakeRawFreeSpace(num_bytes);
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    96
		RawSizeRef() += num_bytes;
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    97
		return pNewData;
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    98
	}
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    99
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   100
	/** Decrease RawSize() by num_bytes. */
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   101
	FORCEINLINE void ReduceRawSize(int num_bytes)
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   102
	{
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   103
		if (MaxRawSize() > 0 && num_bytes > 0) {
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   104
			assert(num_bytes <= RawSize());
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   105
			if (num_bytes < RawSize()) RawSizeRef() -= num_bytes;
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   106
			else RawSizeRef() = 0;
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   107
		}
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   108
	}
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   109
	/** reallocate blob data if needed */
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   110
	void SmartAlloc(int new_size)
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   111
	{
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   112
		int old_max_size = MaxRawSize();
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   113
		if (old_max_size >= new_size) return;
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   114
		// calculate minimum block size we need to allocate
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   115
		int min_alloc_size = sizeof(CHdr) + new_size + Ttail_reserve;
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   116
		// ask allocation policy for some reasonable block size
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   117
		int alloc_size = AllocPolicy(min_alloc_size);
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   118
		// allocate new block
4434
a08cb4b5c179 (svn r6204) -Cleanup: replace non-indentation with spaces; like '}<TAB>else {' -> '} else {', tabs between code and comment, etc.
rubidium
parents: 3972
diff changeset
   119
		CHdr* pNewHdr = RawAlloc(alloc_size);
3900
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   120
		// setup header
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   121
		pNewHdr->m_size = RawSize();
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   122
		pNewHdr->m_max_size = alloc_size - (sizeof(CHdr) + Ttail_reserve);
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   123
		// copy existing data
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   124
		if (RawSize() > 0)
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   125
			memcpy(pNewHdr + 1, ptr_u.m_pData, pNewHdr->m_size);
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   126
		// replace our block with new one
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   127
		CHdr* pOldHdr = &Hdr();
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   128
		Init(pNewHdr);
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   129
		if (old_max_size > 0)
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   130
			RawFree(pOldHdr);
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   131
	}
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   132
	/** simple allocation policy - can be optimized later */
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   133
	FORCEINLINE static int AllocPolicy(int min_alloc)
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   134
	{
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   135
		if (min_alloc < (1 << 9)) {
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   136
			if (min_alloc < (1 << 5)) return (1 << 5);
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   137
			return (min_alloc < (1 << 7)) ? (1 << 7) : (1 << 9);
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   138
		}
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   139
		if (min_alloc < (1 << 15)) {
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   140
			if (min_alloc < (1 << 11)) return (1 << 11);
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   141
			return (min_alloc < (1 << 13)) ? (1 << 13) : (1 << 15);
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   142
		}
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   143
		if (min_alloc < (1 << 20)) {
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   144
			if (min_alloc < (1 << 17)) return (1 << 17);
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   145
			return (min_alloc < (1 << 19)) ? (1 << 19) : (1 << 20);
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   146
		}
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   147
		min_alloc = (min_alloc | ((1 << 20) - 1)) + 1;
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   148
		return min_alloc;
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   149
	}
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   150
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   151
	/** all allocation should happen here */
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   152
	static FORCEINLINE CHdr* RawAlloc(int num_bytes) { return (CHdr*)malloc(num_bytes); }
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   153
	/** all deallocations should happen here */
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   154
	static FORCEINLINE void RawFree(CHdr* p) { free(p); }
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   155
	/** fixing the four bytes at the end of blob data - useful when blob is used to hold string */
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   156
	FORCEINLINE void FixTail()
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   157
	{
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   158
		if (MaxRawSize() > 0) {
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   159
			int8 *p = &ptr_u.m_pData[RawSize()];
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   160
			for (int i = 0; i < Ttail_reserve; i++) p[i] = 0;
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   161
		}
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   162
	}
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   163
};
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   164
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   165
template <class Titem_, class Tbase_ = CBlobBaseSimple>
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   166
class CBlobT : public CBlobBaseSimple {
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   167
	// make template arguments public:
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   168
public:
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   169
	typedef Titem_ Titem;
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   170
	typedef Tbase_ Tbase;
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   171
5081
fe3a6da19d9f (svn r7145) Remove extra semicolons
tron
parents: 4549
diff changeset
   172
	ST_CONST(int, Titem_size = sizeof(Titem))
3900
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   173
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   174
	FORCEINLINE CBlobT() : Tbase() {}
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   175
	FORCEINLINE CBlobT(const Tbase& src) : Tbase(src) {assert((RawSize() % Titem_size) == 0);}
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   176
	FORCEINLINE ~CBlobT() { Free(); }
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   177
	FORCEINLINE void CheckIdx(int idx) { assert(idx >= 0); assert(idx < Size()); }
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   178
	FORCEINLINE Titem* Data() { return (Titem*)RawData(); }
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   179
	FORCEINLINE const Titem* Data() const { return (const Titem*)RawData(); }
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   180
	FORCEINLINE Titem* Data(int idx) { CheckIdx(idx); return (Data() + idx); }
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   181
	FORCEINLINE const Titem* Data(int idx) const { CheckIdx(idx); return (Data() + idx); }
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   182
	FORCEINLINE int Size() const { return (RawSize() / Titem_size); }
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   183
	FORCEINLINE void Free()
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   184
	{
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   185
		assert((RawSize() % Titem_size) == 0);
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   186
		int old_size = Size();
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   187
		if (old_size > 0) {
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   188
			// destroy removed items;
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   189
			Titem* pI_last_to_destroy = Data(0);
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   190
			for (Titem* pI = Data(old_size - 1); pI >= pI_last_to_destroy; pI--) pI->~Titem_();
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   191
		}
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   192
		Tbase::Free();
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   193
	}
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   194
	FORCEINLINE Titem* GrowSizeNC(int num_items) { return (Titem*)GrowRawSize(num_items * Titem_size); }
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   195
	FORCEINLINE Titem* GrowSizeC(int num_items)
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   196
	{
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   197
		Titem* pI = GrowSizeNC(num_items);
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   198
		for (int i = num_items; i > 0; i--, pI++) new (pI) Titem();
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   199
	}
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   200
	FORCEINLINE void ReduceSize(int num_items)
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   201
	{
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   202
		assert((RawSize() % Titem_size) == 0);
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   203
		int old_size = Size();
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   204
		assert(num_items <= old_size);
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   205
		int new_size = (num_items <= old_size) ? (old_size - num_items) : 0;
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   206
		// destroy removed items;
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   207
		Titem* pI_last_to_destroy = Data(new_size);
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   208
		for (Titem* pI = Data(old_size - 1); pI >= pI_last_to_destroy; pI--) pI->~Titem();
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   209
		// remove them
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   210
		ReduceRawSize(num_items * Titem_size);
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   211
	}
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   212
	FORCEINLINE Titem* AppendNew()
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   213
	{
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   214
		Titem& dst = *GrowSizeNC(1);
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   215
		Titem* pNewItem = new (&dst) Titem();
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   216
		return pNewItem;
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   217
	}
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   218
	FORCEINLINE Titem* Append(const Titem& src)
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   219
	{
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   220
		Titem& dst = *GrowSizeNC(1);
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   221
		Titem* pNewItem = new (&dst) Titem(src);
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   222
		return pNewItem;
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   223
	}
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   224
	FORCEINLINE Titem* Append(const Titem* pSrc, int num_items)
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   225
	{
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   226
		Titem* pDst = GrowSizeNC(num_items);
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   227
		Titem* pDstOrg = pDst;
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   228
		Titem* pDstEnd = pDst + num_items;
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   229
		while (pDst < pDstEnd) new (pDst++) Titem(*(pSrc++));
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   230
		return pDstOrg;
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   231
	}
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   232
	FORCEINLINE void RemoveBySwap(int idx)
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   233
	{
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   234
		CheckIdx(idx);
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   235
		// destroy removed item
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   236
		Titem* pRemoved = Data(idx);
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   237
		RemoveBySwap(pRemoved);
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   238
	}
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   239
	FORCEINLINE void RemoveBySwap(Titem* pItem)
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   240
	{
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   241
		Titem* pLast = Data(Size() - 1);
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   242
		assert(pItem >= Data() && pItem <= pLast);
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   243
		// move last item to its new place
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   244
		if (pItem != pLast) {
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   245
			pItem->~Titem_();
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   246
			new (pItem) Titem_(*pLast);
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   247
		}
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   248
		// destroy the last item
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   249
		pLast->~Titem_();
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   250
		// and reduce the raw blob size
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   251
		ReduceRawSize(Titem_size);
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   252
	}
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   253
	FORCEINLINE Titem* MakeFreeSpace(int num_items) { return (Titem*)MakeRawFreeSpace(num_items * Titem_size); }
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   254
};
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   255
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   256
// simple string implementation
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   257
struct CStrA : public CBlobT<char>
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   258
{
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   259
	typedef CBlobT<char> base;
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   260
	CStrA(const char* str = NULL) {Append(str);}
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   261
	FORCEINLINE CStrA(const CBlobBaseSimple& src) : base(src) {}
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   262
	void Append(const char* str) {if (str != NULL && str[0] != '\0') base::Append(str, (int)strlen(str));}
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   263
};
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   264
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
   265
#endif /* BLOB_HPP */