Use size types

Make code more portable and modern.
This commit is contained in:
Kawe Mazidjatari 2023-08-29 22:05:20 +02:00
parent abaab38d9d
commit 4b7ca6b439
11 changed files with 412 additions and 412 deletions

View File

@ -146,7 +146,7 @@ void CModSystem::WriteModStatusList()
pModListKV->SetBool(mod->m_ModID.Get(), enabled);
}
CUtlBuffer buf = CUtlBuffer(int64_t(0), 0, CUtlBuffer::TEXT_BUFFER);
CUtlBuffer buf = CUtlBuffer(ssize_t(0), 0, CUtlBuffer::TEXT_BUFFER);
kv.RecursiveSaveToFile(buf, 0);
if (!FileSystem()->WriteFile(MOD_STATUS_LIST_FILE, "PLATFORM", buf))

View File

@ -20,7 +20,7 @@
//-----------------------------------------------------------------------------
typedef uint64 MemoryStackMark_t;
typedef size_t MemoryStackMark_t;
class CMemoryStack //: private IMemoryInfo
{
@ -28,27 +28,27 @@ public:
CMemoryStack();
~CMemoryStack();
bool Init( const char *pszAllocOwner, uint64 maxSize = 0, uint64 commitIncrement = 0, uint64 initialCommit = 0, uint64 alignment = 16 );
bool Init( const char *pszAllocOwner, size_t maxSize = 0, size_t commitIncrement = 0, size_t initialCommit = 0, size_t alignment = 16 );
void Term();
uint64 GetSize() const;
uint64 GetMaxSize() const ;
uint64 GetUsed() const;
size_t GetSize() const;
size_t GetMaxSize() const ;
size_t GetUsed() const;
void *Alloc( uint64 bytes, bool bClear = false ) RESTRICT;
void *Alloc( size_t bytes, bool bClear = false ) RESTRICT;
MemoryStackMark_t GetCurrentAllocPoint() const;
void FreeToAllocPoint( MemoryStackMark_t mark, bool bDecommit = true );
void FreeAll( bool bDecommit = true );
void Access( void **ppRegion, uint64 *pBytes );
void Access( void **ppRegion, size_t *pBytes );
void PrintContents() const;
void *GetBase();
const void *GetBase() const { return const_cast<CMemoryStack *>(this)->GetBase(); }
bool CommitSize( uint64 nBytes );
bool CommitSize( size_t nBytes );
void SetAllocOwner( const char *pszAllocOwner );
@ -78,12 +78,12 @@ private:
bool m_bPhysical;
char *m_pszAllocOwner;
uint64 m_unkSize; // Unknown field..
uint64 m_maxSize; // m_maxSize stores how big the stack can grow. It measures the reservation size.
uint64 m_alignment;
size_t m_unkSize; // Unknown field..
size_t m_maxSize; // m_maxSize stores how big the stack can grow. It measures the reservation size.
size_t m_alignment;
#ifdef MEMSTACK_VIRTUAL_MEMORY_AVAILABLE
uint64 m_commitIncrement;
uint64 m_minCommit;
size_t m_commitIncrement;
size_t m_minCommit;
#endif
#if defined( MEMSTACK_VIRTUAL_MEMORY_AVAILABLE ) && defined( _PS3 )
IVirtualMemorySection *m_pVirtualMemorySection;
@ -97,7 +97,7 @@ private:
//-------------------------------------
FORCEINLINE void *CMemoryStack::Alloc( uint64 bytes, bool bClear ) RESTRICT
FORCEINLINE void *CMemoryStack::Alloc( size_t bytes, bool bClear ) RESTRICT
{
sizeof(CMemoryStack);
Assert( m_pBase );
@ -129,7 +129,7 @@ FORCEINLINE void *CMemoryStack::Alloc( uint64 bytes, bool bClear ) RESTRICT
//-------------------------------------
inline bool CMemoryStack::CommitSize( uint64 nBytes )
inline bool CMemoryStack::CommitSize( size_t nBytes )
{
if ( GetSize() != nBytes )
{
@ -142,14 +142,14 @@ inline bool CMemoryStack::CommitSize( uint64 nBytes )
// How big can this memory stack grow? This is equivalent to how many
// bytes are reserved.
inline uint64 CMemoryStack::GetMaxSize() const
inline size_t CMemoryStack::GetMaxSize() const
{
return m_maxSize;
}
//-------------------------------------
inline uint64 CMemoryStack::GetUsed() const
inline size_t CMemoryStack::GetUsed() const
{
return ( m_pNextAlloc - m_pBase );
}

View File

@ -62,12 +62,12 @@ template <size_t maxLenInCharacters> int V_vsprintf_safe(OUT_Z_ARRAY char(&pDest
char const* V_stristr(char const* pStr, char const* pSearch);
const char* V_strnistr(const char* pStr, const char* pSearch, int64_t n);
const char* V_strnchr(const char* pStr, char c, int64_t n);
const char* V_strnistr(const char* pStr, const char* pSearch, ssize_t n);
const char* V_strnchr(const char* pStr, char c, ssize_t n);
bool V_isspace(int c);
// Strip white space at the beginning and end of a string
int64_t V_StrTrim(char* pStr);
ssize_t V_StrTrim(char* pStr);
int V_UTF8ToUnicode(const char* pUTF8, wchar_t* pwchDest, int cubDestSizeInBytes);
int V_UnicodeToUTF8(const wchar_t* pUnicode, char* pUTF8, int cubDestSizeInBytes);

View File

@ -44,30 +44,30 @@ public:
char* m_pReplacementString;
};
CUtlCharConversion(char nEscapeChar, const char* pDelimiter, int64 nCount, ConversionArray_t* pArray);
CUtlCharConversion(char nEscapeChar, const char* pDelimiter, ssize_t nCount, ConversionArray_t* pArray);
char GetEscapeChar() const;
const char* GetDelimiter() const;
int64 GetDelimiterLength() const;
ssize_t GetDelimiterLength() const;
const char* GetConversionString(char c) const;
int64 GetConversionLength(char c) const;
int64 MaxConversionLength() const;
ssize_t GetConversionLength(char c) const;
ssize_t MaxConversionLength() const;
// Finds a conversion for the passed-in string, returns length
virtual char FindConversion(const char* pString, int64* pLength);
virtual char FindConversion(const char* pString, ssize_t* pLength);
protected:
struct ConversionInfo_t
{
int64 m_nLength;
ssize_t m_nLength;
char* m_pReplacementString;
};
char m_nEscapeChar;
const char* m_pDelimiter;
int64 m_nDelimiterLength;
int64 m_nCount;
int64 m_nMaxConversionLength;
ssize_t m_nDelimiterLength;
ssize_t m_nCount;
ssize_t m_nMaxConversionLength;
char m_pList[256];
ConversionInfo_t m_pReplacements[256];
};
@ -165,13 +165,13 @@ public:
};
// Overflow functions when a get or put overflows
typedef bool (CUtlBuffer::* UtlBufferOverflowFunc_t)(int64 nSize);
typedef bool (CUtlBuffer::* UtlBufferOverflowFunc_t)(ssize_t nSize);
// Constructors for growable + external buffers for serialization/unserialization
CUtlBuffer(int64 growSize = 0, int64 initSize = 0, int nFlags = 0);
CUtlBuffer(const void* pBuffer, int64 size, int nFlags = 0);
// This one isn't actually defined so that we catch contructors that are trying to pass a bool in as the third param.
CUtlBuffer(const void* pBuffer, int64 size, bool crap) = delete;
CUtlBuffer(ssize_t growSize = 0, ssize_t initSize = 0, int nFlags = 0);
CUtlBuffer(const void* pBuffer, ssize_t size, int nFlags = 0);
// This one isn't actually defined so that we catch constructors that are trying to pass a bool in as the third param.
CUtlBuffer(const void* pBuffer, ssize_t size, bool crap) = delete;
// UtlBuffer objects should not be copyable; we do a slow copy if you use this but it asserts.
// (REI: I'd like to delete these but we have some python bindings that currently rely on being able to copy these objects)
@ -192,21 +192,21 @@ public:
void SetBufferType(bool bIsText, bool bContainsCRLF);
// Makes sure we've got at least this much memory
void EnsureCapacity(int64 num);
void EnsureCapacity(ssize_t num);
// Access for direct read into buffer
void* AccessForDirectRead(int64 nBytes);
void* AccessForDirectRead(ssize_t nBytes);
// Attaches the buffer to external memory....
void SetExternalBuffer(void* pMemory, int64 nSize, int64 nInitialPut, int nFlags = 0);
void SetExternalBuffer(void* pMemory, ssize_t nSize, ssize_t nInitialPut, int nFlags = 0);
bool IsExternallyAllocated() const;
void AssumeMemory(void* pMemory, int64 nSize, int64 nInitialPut, int nFlags = 0);
void AssumeMemory(void* pMemory, ssize_t nSize, ssize_t nInitialPut, int nFlags = 0);
void* Detach();
void* DetachMemory();
// copies data from another buffer
void CopyBuffer(const CUtlBuffer& buffer);
void CopyBuffer(const void* pubData, int64 cubData);
void CopyBuffer(const void* pubData, ssize_t cubData);
void Swap(CUtlBuffer& buf);
void Swap(CUtlMemory<uint8>& mem);
@ -250,27 +250,27 @@ public:
float GetFloat();
double GetDouble();
void* GetPtr();
void GetString(char* pString, int64 nMaxChars);
bool Get(void* pMem, int64 size);
void GetLine(char* pLine, int64 nMaxChars);
void GetString(char* pString, ssize_t nMaxChars);
bool Get(void* pMem, ssize_t size);
void GetLine(char* pLine, ssize_t nMaxChars);
// Used for getting objects that have a byteswap datadesc defined
template <typename T> void GetObjects(T* dest, int64 count = 1);
template <typename T> void GetObjects(T* dest, ssize_t count = 1);
// This will get at least 1 byte and up to nSize bytes.
// It will return the number of bytes actually read.
int64 GetUpTo(void* pMem, int64 nSize);
ssize_t GetUpTo(void* pMem, ssize_t nSize);
// This version of GetString converts \" to \\ and " to \, etc.
// It also reads a " at the beginning and end of the string
void GetDelimitedString(CUtlCharConversion* pConv, char* pString, int64 nMaxChars = 0);
void GetDelimitedString(CUtlCharConversion* pConv, char* pString, ssize_t nMaxChars = 0);
char GetDelimitedChar(CUtlCharConversion* pConv);
// This will return the # of characters of the string about to be read out
// NOTE: The count will *include* the terminating 0!!
// In binary mode, it's the number of characters until the next 0
// In text mode, it's the number of characters until the next space.
int64 PeekStringLength();
ssize_t PeekStringLength();
// This version of PeekStringLength converts \" to \\ and " to \, etc.
// It also reads a " at the beginning and end of the string
@ -280,11 +280,11 @@ public:
// Specifying false for bActualSize will return the pre-translated number of characters
// including the delimiters and the escape characters. So, \n counts as 2 characters when bActualSize == false
// and only 1 character when bActualSize == true
int64 PeekDelimitedStringLength(CUtlCharConversion* pConv, bool bActualSize = true);
ssize_t PeekDelimitedStringLength(CUtlCharConversion* pConv, bool bActualSize = true);
// Just like scanf, but doesn't work in binary mode
int64 Scanf(SCANF_FORMAT_STRING const char* pFmt, ...);
int64 VaScanf(const char* pFmt, va_list list);
ssize_t Scanf(SCANF_FORMAT_STRING const char* pFmt, ...);
ssize_t VaScanf(const char* pFmt, va_list list);
// Eats white space, advances Get index
void EatWhiteSpace();
@ -298,7 +298,7 @@ public:
// (skipping whitespace that leads + trails both delimiters).
// If successful, the get index is advanced and the function returns true,
// otherwise the index is not advanced and the function returns false.
bool ParseToken(const char* pStartingDelim, const char* pEndingDelim, char* pString, int64 nMaxLen);
bool ParseToken(const char* pStartingDelim, const char* pEndingDelim, char* pString, ssize_t nMaxLen);
// Advance the get index until after the particular string is found
// Do not eat whitespace before starting. Return false if it failed
@ -307,7 +307,7 @@ public:
// Parses the next token, given a set of character breaks to stop at
// Returns the length of the token parsed in bytes (-1 if none parsed)
int64 ParseToken(characterset_t* pBreaks, char* pTokenBuf, int64 nMaxLen, bool bParseComments = true);
ssize_t ParseToken(characterset_t* pBreaks, char* pTokenBuf, ssize_t nMaxLen, bool bParseComments = true);
// Write stuff in
// Binary mode: it'll just write the bits directly in, and strings will be
@ -326,10 +326,10 @@ public:
void PutDouble(double d);
void PutPtr(void*); // Writes the pointer, not the pointed to
void PutString(const char* pString);
void Put(const void* pMem, int64 size);
void Put(const void* pMem, ssize_t size);
// Used for putting objects that have a byteswap datadesc defined
template <typename T> void PutObjects(T* src, int64 count = 1);
template <typename T> void PutObjects(T* src, ssize_t count = 1);
// This version of PutString converts \ to \\ and " to \", etc.
// It also places " at the beginning and end of the string
@ -341,24 +341,24 @@ public:
void VaPrintf(const char* pFmt, va_list list);
// What am I writing (put)/reading (get)?
void* PeekPut(int64 offset = 0);
const void* PeekGet(int64 offset = 0) const;
const void* PeekGet(int64 nMaxSize, int64 nOffset);
void* PeekPut(ssize_t offset = 0);
const void* PeekGet(ssize_t offset = 0) const;
const void* PeekGet(ssize_t nMaxSize, ssize_t nOffset);
// Where am I writing (put)/reading (get)?
int64 TellPut() const;
int64 TellGet() const;
ssize_t TellPut() const;
ssize_t TellGet() const;
// What's the most I've ever written?
int64 TellMaxPut() const;
ssize_t TellMaxPut() const;
// How many bytes remain to be read?
// NOTE: This is not accurate for streaming text files; it overshoots
int64 GetBytesRemaining() const;
ssize_t GetBytesRemaining() const;
// Change where I'm writing (put)/reading (get)
void SeekPut(SeekType_t type, int64 offset);
void SeekGet(SeekType_t type, int64 offset);
void SeekPut(SeekType_t type, ssize_t offset);
void SeekGet(SeekType_t type, ssize_t offset);
// Buffer base
const void* Base() const;
@ -366,7 +366,7 @@ public:
// memory allocation size, does *not* reflect size written or read,
// use TellPut or TellGet for that
int64 Size() const;
ssize_t Size() const;
// Am I a text buffer?
bool IsText() const;
@ -412,17 +412,17 @@ protected:
void SetOverflowFuncs(UtlBufferOverflowFunc_t getFunc, UtlBufferOverflowFunc_t putFunc);
bool OnPutOverflow(int64 nSize);
bool OnGetOverflow(int64 nSize);
bool OnPutOverflow(ssize_t nSize);
bool OnGetOverflow(ssize_t nSize);
protected:
// Checks if a get/put is ok
bool CheckPut(int64 size);
bool CheckGet(int64 size);
bool CheckPut(ssize_t size);
bool CheckGet(ssize_t size);
// NOTE: Pass in nPut here even though it is just a copy of m_Put. This is almost always called immediately
// after modifying m_Put and this lets it stay in a register
void AddNullTermination(int64 nPut);
void AddNullTermination(ssize_t nPut);
// Methods to help with pretty-printing
bool WasLastCharacterCR();
@ -433,24 +433,24 @@ protected:
void PutDelimitedCharInternal(CUtlCharConversion* pConv, char c);
// Default overflow funcs
bool PutOverflow(int64 nSize);
bool GetOverflow(int64 nSize);
bool PutOverflow(ssize_t nSize);
bool GetOverflow(ssize_t nSize);
// Does the next bytes of the buffer match a pattern?
bool PeekStringMatch(int64 nOffset, const char* pString, int64 nLen);
bool PeekStringMatch(ssize_t nOffset, const char* pString, ssize_t nLen);
// Peek size of line to come, check memory bound
int64 PeekLineLength();
ssize_t PeekLineLength();
// How much whitespace should I skip?
int64 PeekWhiteSpace(int64 nOffset);
ssize_t PeekWhiteSpace(ssize_t nOffset);
// Checks if a peek get is ok
bool CheckPeekGet(int64 nOffset, int64 nSize);
bool CheckPeekGet(ssize_t nOffset, ssize_t nSize);
// Call this to peek arbitrarily long into memory. It doesn't fail unless
// it can't read *anything* new
bool CheckArbitraryPeekGet(int64 nOffset, int64& nIncrement);
bool CheckArbitraryPeekGet(ssize_t nOffset, ssize_t& nIncrement);
template <typename T> void GetType(T& dest);
template <typename T> void GetTypeBin(T& dest);
@ -464,8 +464,8 @@ protected:
// be sure to also update the copy constructor
// and SwapCopy() when adding members.
CUtlMemory<unsigned char> m_Memory;
int64 m_Get;
int64 m_Put;
ssize_t m_Get;
ssize_t m_Put;
unsigned char m_Error;
unsigned char m_Flags;
@ -475,8 +475,8 @@ protected:
#endif
int m_nTab;
int64 m_nMaxPut;
int64 m_nOffset;
ssize_t m_nMaxPut;
ssize_t m_nOffset;
UtlBufferOverflowFunc_t m_GetOverflowFunc;
UtlBufferOverflowFunc_t m_PutOverflowFunc;
@ -485,7 +485,7 @@ protected:
void* m_pUnk; // Possibly padding?
const char* m_pName;
int64 m_Count; // Unknown count.
ssize_t m_Count; // Unknown count.
};
static_assert(sizeof(CUtlBuffer) == 0x70);
@ -560,7 +560,7 @@ inline CUtlBuffer& operator<<(CUtlBuffer& b, const Vector2D& v)
class CUtlInplaceBuffer : public CUtlBuffer
{
public:
CUtlInplaceBuffer(int64 growSize = 0, int64 initSize = 0, int nFlags = 0);
CUtlInplaceBuffer(ssize_t growSize = 0, ssize_t initSize = 0, int nFlags = 0);
//
// Routines returning buffer-inplace-pointers
@ -596,7 +596,7 @@ public:
// @returns true if line was successfully read
// false when EOF is reached or error occurs
//
bool InplaceGetLinePtr( /* out */ char** ppszInBufferPtr, /* out */ int64* pnLineLength);
bool InplaceGetLinePtr( /* out */ char** ppszInBufferPtr, /* out */ ssize_t* pnLineLength);
//
// Determines the line length, advances the "get" pointer offset by the line length,
@ -627,7 +627,7 @@ public:
//-----------------------------------------------------------------------------
// Where am I reading?
//-----------------------------------------------------------------------------
inline int64 CUtlBuffer::TellGet() const
inline ssize_t CUtlBuffer::TellGet() const
{
return m_Get;
}
@ -636,7 +636,7 @@ inline int64 CUtlBuffer::TellGet() const
//-----------------------------------------------------------------------------
// How many bytes remain to be read?
//-----------------------------------------------------------------------------
inline int64 CUtlBuffer::GetBytesRemaining() const
inline ssize_t CUtlBuffer::GetBytesRemaining() const
{
return m_nMaxPut - TellGet();
}
@ -645,7 +645,7 @@ inline int64 CUtlBuffer::GetBytesRemaining() const
//-----------------------------------------------------------------------------
// What am I reading?
//-----------------------------------------------------------------------------
inline const void* CUtlBuffer::PeekGet(int64 offset) const
inline const void* CUtlBuffer::PeekGet(ssize_t offset) const
{
return &m_Memory[m_Get + offset - m_nOffset];
}
@ -678,9 +678,9 @@ inline void CUtlBuffer::GetObject(T* dest)
template <typename T>
inline void CUtlBuffer::GetObjects(T* dest, int64 count)
inline void CUtlBuffer::GetObjects(T* dest, ssize_t count)
{
for (int64 i = 0; i < count; ++i, ++dest)
for (ssize_t i = 0; i < count; ++i, ++dest)
{
GetObject<T>(dest);
}
@ -846,7 +846,7 @@ template <typename T>
inline bool CUtlBuffer::GetTypeText(T& value, int nRadix /*= 10*/)
{
// NOTE: This is not bullet-proof; it assumes numbers are < 128 characters
int64 nLength = 128;
ssize_t nLength = 128;
if (!CheckArbitraryPeekGet(0, nLength))
{
value = 0;
@ -857,7 +857,7 @@ inline bool CUtlBuffer::GetTypeText(T& value, int nRadix /*= 10*/)
char* pEnd = pStart;
value = StringToNumber< T >(pStart, &pEnd, nRadix);
int64 nBytesRead = (int64)(pEnd - pStart);
ssize_t nBytesRead = (ssize_t)(pEnd - pStart);
if (nBytesRead == 0)
return false;
@ -1005,7 +1005,7 @@ inline bool CUtlBuffer::IsExternallyAllocated() const
//-----------------------------------------------------------------------------
// Where am I writing?
//-----------------------------------------------------------------------------
inline int64 CUtlBuffer::TellPut() const
inline ssize_t CUtlBuffer::TellPut() const
{
return m_Put;
}
@ -1014,7 +1014,7 @@ inline int64 CUtlBuffer::TellPut() const
//-----------------------------------------------------------------------------
// What's the most I've ever written?
//-----------------------------------------------------------------------------
inline int64 CUtlBuffer::TellMaxPut() const
inline ssize_t CUtlBuffer::TellMaxPut() const
{
return m_nMaxPut;
}
@ -1023,7 +1023,7 @@ inline int64 CUtlBuffer::TellMaxPut() const
//-----------------------------------------------------------------------------
// What am I reading?
//-----------------------------------------------------------------------------
inline void* CUtlBuffer::PeekPut(int64 offset)
inline void* CUtlBuffer::PeekPut(ssize_t offset)
{
return &m_Memory[m_Put + offset - m_nOffset];
}
@ -1053,9 +1053,9 @@ inline void CUtlBuffer::PutObject(T* src)
template <typename T>
inline void CUtlBuffer::PutObjects(T* src, int64 count)
inline void CUtlBuffer::PutObjects(T* src, ssize_t count)
{
for (int64 i = 0; i < count; ++i, ++src)
for (ssize_t i = 0; i < count; ++i, ++src)
{
PutObject<T>(src);
}
@ -1353,7 +1353,7 @@ inline void* CUtlBuffer::Base()
return m_Memory.Base();
}
inline int64 CUtlBuffer::Size() const
inline ssize_t CUtlBuffer::Size() const
{
return m_Memory.NumAllocated();
}
@ -1385,7 +1385,7 @@ inline void CUtlBuffer::Purge()
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
inline void* CUtlBuffer::AccessForDirectRead(int64 nBytes)
inline void* CUtlBuffer::AccessForDirectRead(ssize_t nBytes)
{
Assert(m_Get == 0 && m_Put == 0 && m_nMaxPut == 0);
EnsureCapacity(nBytes);
@ -1439,7 +1439,7 @@ inline void CUtlBuffer::CopyBuffer(const CUtlBuffer& buffer)
CopyBuffer(buffer.Base(), buffer.TellPut());
}
inline void CUtlBuffer::CopyBuffer(const void* pubData, int64 cubData)
inline void CUtlBuffer::CopyBuffer(const void* pubData, ssize_t cubData)
{
Clear();
if (cubData)

View File

@ -39,16 +39,16 @@
// The CUtlMemory class:
// A growable memory class which doubles in size by default.
//-----------------------------------------------------------------------------
template< class T, class I = int64 >
template< class T, class I = ssize_t >
class CUtlMemory
{
template< class A, class B> friend class CUtlVector;
template< class A, size_t B> friend class CUtlVectorFixedGrowableCompat;
public:
// constructor, destructor
CUtlMemory(int64 nGrowSize = 0, int64 nInitSize = 0);
CUtlMemory(T* pMemory, int64 numElements);
CUtlMemory(const T* pMemory, int64 numElements);
CUtlMemory(ssize_t nGrowSize = 0, ssize_t nInitSize = 0);
CUtlMemory(T* pMemory, ssize_t numElements);
CUtlMemory(const T* pMemory, ssize_t numElements);
~CUtlMemory();
CUtlMemory(const CUtlMemory&) = delete;
@ -58,7 +58,7 @@ public:
CUtlMemory& operator=(CUtlMemory&& moveFrom);
// Set the size by which the memory grows
void Init(int64 nGrowSize = 0, int64 nInitSize = 0);
void Init(ssize_t nGrowSize = 0, ssize_t nInitSize = 0);
class Iterator_t
{
@ -94,9 +94,9 @@ public:
const T* Base() const;
// Attaches the buffer to external memory....
void SetExternalBuffer(T* pMemory, int64 numElements);
void SetExternalBuffer(const T* pMemory, int64 numElements);
void AssumeMemory(T* pMemory, int64 nSize);
void SetExternalBuffer(T* pMemory, ssize_t numElements);
void SetExternalBuffer(const T* pMemory, ssize_t numElements);
void AssumeMemory(T* pMemory, ssize_t nSize);
T* Detach();
void* DetachMemory();
@ -105,23 +105,23 @@ public:
// Switches the buffer from an external memory buffer to a reallocatable buffer
// Will copy the current contents of the external buffer to the reallocatable buffer
void ConvertToGrowableMemory(int64 nGrowSize);
void ConvertToGrowableMemory(ssize_t nGrowSize);
// Size
int64 NumAllocated() const;
int64 Count() const;
ssize_t NumAllocated() const;
ssize_t Count() const;
// Grows the memory, so that at least allocated + num elements are allocated
void Grow(int64 num = 1);
void Grow(ssize_t num = 1);
// Makes sure we've got at least this much memory
void EnsureCapacity(int64 num);
void EnsureCapacity(ssize_t num);
// Memory deallocation
void Purge();
// Purge all but the given number of elements
void Purge(int64 numElements);
void Purge(ssize_t numElements);
// is the memory externally allocated?
bool IsExternallyAllocated() const;
@ -130,7 +130,7 @@ public:
bool IsReadOnly() const;
// Set the size by which the memory grows
void SetGrowSize(int64 size);
void SetGrowSize(ssize_t size);
protected:
void ValidateGrowSize()
@ -139,7 +139,7 @@ protected:
if (m_nGrowSize && m_nGrowSize != EXTERNAL_BUFFER_MARKER)
{
// Max grow size at 128 bytes on XBOX
const int64 MAX_GROW = 128;
const ssize_t MAX_GROW = 128;
if (m_nGrowSize * sizeof(T) > MAX_GROW)
{
m_nGrowSize = max(1, MAX_GROW / sizeof(T));
@ -155,8 +155,8 @@ protected:
};
T* m_pMemory;
int64 m_nAllocationCount;
int64 m_nGrowSize;
ssize_t m_nAllocationCount;
ssize_t m_nGrowSize;
};
@ -164,19 +164,19 @@ protected:
// The CUtlMemory class:
// A growable memory class which doubles in size by default.
//-----------------------------------------------------------------------------
template< class T, size_t SIZE, class I = int64 >
template< class T, size_t SIZE, class I = ssize_t >
class CUtlMemoryFixedGrowable : public CUtlMemory< T, I >
{
typedef CUtlMemory< T, I > BaseClass;
public:
CUtlMemoryFixedGrowable(int64 nGrowSize = 0, int64 nInitSize = SIZE) : BaseClass(m_pFixedMemory, SIZE)
CUtlMemoryFixedGrowable(ssize_t nGrowSize = 0, ssize_t nInitSize = SIZE) : BaseClass(m_pFixedMemory, SIZE)
{
Assert(nInitSize == 0 || nInitSize == SIZE);
m_nMallocGrowSize = nGrowSize;
}
void Grow(int64 nCount = 1)
void Grow(ssize_t nCount = 1)
{
if (this->IsExternallyAllocated())
{
@ -185,7 +185,7 @@ public:
BaseClass::Grow(nCount);
}
void EnsureCapacity(int64 num)
void EnsureCapacity(ssize_t num)
{
if (CUtlMemory<T>::m_nAllocationCount >= num)
return;
@ -200,7 +200,7 @@ public:
}
private:
int64 m_nMallocGrowSize;
ssize_t m_nMallocGrowSize;
T m_pFixedMemory[SIZE];
};
@ -208,68 +208,68 @@ private:
// The CUtlMemoryFixed class:
// A fixed memory class
//-----------------------------------------------------------------------------
template< typename T, size_t SIZE, int64 nAlignment = 0 >
template< typename T, size_t SIZE, ssize_t nAlignment = 0 >
class CUtlMemoryFixed
{
public:
// constructor, destructor
CUtlMemoryFixed(int64 nGrowSize = 0, int64 nInitSize = 0) { Assert(nInitSize == 0 || nInitSize == SIZE); }
CUtlMemoryFixed(T* pMemory, int64 numElements) { Assert(0); }
CUtlMemoryFixed(ssize_t nGrowSize = 0, ssize_t nInitSize = 0) { Assert(nInitSize == 0 || nInitSize == SIZE); }
CUtlMemoryFixed(T* pMemory, ssize_t numElements) { Assert(0); }
// Can we use this index?
bool IsIdxValid(int64 i) const { return (i >= 0) && (i < SIZE); }
bool IsIdxValid(ssize_t i) const { return (i >= 0) && (i < SIZE); }
// Specify the invalid ('null') index that we'll only return on failure
static const int64 INVALID_INDEX = -1; // For use with COMPILE_TIME_ASSERT
static int64 InvalidIndex() { return INVALID_INDEX; }
static const ssize_t INVALID_INDEX = -1; // For use with COMPILE_TIME_ASSERT
static ssize_t InvalidIndex() { return INVALID_INDEX; }
// Gets the base address
T* Base() { if (nAlignment == 0) return (T*)(&m_Memory[0]); else return (T*)AlignValue(&m_Memory[0], nAlignment); }
const T* Base() const { if (nAlignment == 0) return (T*)(&m_Memory[0]); else return (T*)AlignValue(&m_Memory[0], nAlignment); }
// element access
T& operator[](int64 i) { Assert(IsIdxValid(i)); return Base()[i]; }
const T& operator[](int64 i) const { Assert(IsIdxValid(i)); return Base()[i]; }
T& Element(int64 i) { Assert(IsIdxValid(i)); return Base()[i]; }
const T& Element(int64 i) const { Assert(IsIdxValid(i)); return Base()[i]; }
T& operator[](ssize_t i) { Assert(IsIdxValid(i)); return Base()[i]; }
const T& operator[](ssize_t i) const { Assert(IsIdxValid(i)); return Base()[i]; }
T& Element(ssize_t i) { Assert(IsIdxValid(i)); return Base()[i]; }
const T& Element(ssize_t i) const { Assert(IsIdxValid(i)); return Base()[i]; }
// Attaches the buffer to external memory....
void SetExternalBuffer(T* pMemory, int64 numElements) { Assert(0); }
void SetExternalBuffer(T* pMemory, ssize_t numElements) { Assert(0); }
// Size
int64 NumAllocated() const { return SIZE; }
int64 Count() const { return SIZE; }
ssize_t NumAllocated() const { return SIZE; }
ssize_t Count() const { return SIZE; }
// Grows the memory, so that at least allocated + num elements are allocated
void Grow(int64 num = 1) { Assert(0); }
void Grow(ssize_t num = 1) { Assert(0); }
// Makes sure we've got at least this much memory
void EnsureCapacity(int64 num) { Assert(num <= SIZE); }
void EnsureCapacity(ssize_t num) { Assert(num <= SIZE); }
// Memory deallocation
void Purge() {}
// Purge all but the given number of elements (NOT IMPLEMENTED IN CUtlMemoryFixed)
void Purge(int64 numElements) { Assert(0); }
void Purge(ssize_t numElements) { Assert(0); }
// is the memory externally allocated?
bool IsExternallyAllocated() const { return false; }
// Set the size by which the memory grows
void SetGrowSize(int64 size) {}
void SetGrowSize(ssize_t size) {}
class Iterator_t
{
public:
Iterator_t(int64 i) : index(i) {}
int64 index;
Iterator_t(ssize_t i) : index(i) {}
ssize_t index;
bool operator==(const Iterator_t it) const { return index == it.index; }
bool operator!=(const Iterator_t it) const { return index != it.index; }
};
Iterator_t First() const { return Iterator_t(IsIdxValid(0) ? 0 : InvalidIndex()); }
Iterator_t Next(const Iterator_t& it) const { return Iterator_t(IsIdxValid(it.index + 1) ? it.index + 1 : InvalidIndex()); }
int64 GetIndex(const Iterator_t& it) const { return it.index; }
bool IsIdxAfter(int64 i, const Iterator_t& it) const { return i > it.index; }
ssize_t GetIndex(const Iterator_t& it) const { return it.index; }
bool IsIdxAfter(ssize_t i, const Iterator_t& it) const { return i > it.index; }
bool IsValidIterator(const Iterator_t& it) const { return IsIdxValid(it.index); }
Iterator_t InvalidIterator() const { return Iterator_t(InvalidIndex()); }
@ -291,32 +291,32 @@ class CUtlMemoryConservative
public:
// constructor, destructor
CUtlMemoryConservative(int64 nGrowSize = 0, int64 nInitSize = 0) : m_pMemory(NULL)
CUtlMemoryConservative(ssize_t nGrowSize = 0, ssize_t nInitSize = 0) : m_pMemory(NULL)
{
#ifdef REMEMBER_ALLOC_SIZE_FOR_VALGRIND
m_nCurAllocSize = 0;
#endif
}
CUtlMemoryConservative(T* pMemory, int64 numElements) { Assert(0); }
CUtlMemoryConservative(T* pMemory, ssize_t numElements) { Assert(0); }
~CUtlMemoryConservative() { if (m_pMemory) free(m_pMemory); }
// Can we use this index?
bool IsIdxValid(int64 i) const { return (IsDebug()) ? (i >= 0 && i < NumAllocated()) : (i >= 0); }
static int64 InvalidIndex() { return -1; }
bool IsIdxValid(ssize_t i) const { return (IsDebug()) ? (i >= 0 && i < NumAllocated()) : (i >= 0); }
static ssize_t InvalidIndex() { return -1; }
// Gets the base address
T* Base() { return m_pMemory; }
const T* Base() const { return m_pMemory; }
// element access
T& operator[](int64 i) { Assert(IsIdxValid(i)); return Base()[i]; }
const T& operator[](int64 i) const { Assert(IsIdxValid(i)); return Base()[i]; }
T& Element(int64 i) { Assert(IsIdxValid(i)); return Base()[i]; }
const T& Element(int64 i) const { Assert(IsIdxValid(i)); return Base()[i]; }
T& operator[](ssize_t i) { Assert(IsIdxValid(i)); return Base()[i]; }
const T& operator[](ssize_t i) const { Assert(IsIdxValid(i)); return Base()[i]; }
T& Element(ssize_t i) { Assert(IsIdxValid(i)); return Base()[i]; }
const T& Element(ssize_t i) const { Assert(IsIdxValid(i)); return Base()[i]; }
// Attaches the buffer to external memory....
void SetExternalBuffer(T* pMemory, int64 numElements) { Assert(0); }
void SetExternalBuffer(T* pMemory, ssize_t numElements) { Assert(0); }
// Size
FORCEINLINE void RememberAllocSize(size_t sz)
@ -335,11 +335,11 @@ public:
#endif
}
int64 NumAllocated() const
ssize_t NumAllocated() const
{
return AllocSize() / sizeof(T);
}
int64 Count() const
ssize_t Count() const
{
return NumAllocated();
}
@ -350,14 +350,14 @@ public:
RememberAllocSize(sz);
}
// Grows the memory, so that at least allocated + num elements are allocated
void Grow(int64 num = 1)
void Grow(ssize_t num = 1)
{
int64 nCurN = NumAllocated();
ssize_t nCurN = NumAllocated();
ReAlloc((nCurN + num) * sizeof(T));
}
// Makes sure we've got at least this much memory
void EnsureCapacity(int64 num)
void EnsureCapacity(ssize_t num)
{
size_t nSize = sizeof(T) * MAX(num, Count());
ReAlloc(nSize);
@ -372,27 +372,27 @@ public:
}
// Purge all but the given number of elements
void Purge(int64 numElements) { ReAlloc(numElements * sizeof(T)); }
void Purge(ssize_t numElements) { ReAlloc(numElements * sizeof(T)); }
// is the memory externally allocated?
bool IsExternallyAllocated() const { return false; }
// Set the size by which the memory grows
void SetGrowSize(int64 size) {}
void SetGrowSize(ssize_t size) {}
class Iterator_t
{
public:
Iterator_t(int64 i, int64 _limit) : index(i), limit(_limit) {}
int64 index;
int64 limit;
Iterator_t(ssize_t i, ssize_t _limit) : index(i), limit(_limit) {}
ssize_t index;
ssize_t limit;
bool operator==(const Iterator_t it) const { return index == it.index; }
bool operator!=(const Iterator_t it) const { return index != it.index; }
};
Iterator_t First() const { int64 limit = NumAllocated(); return Iterator_t(limit ? 0 : InvalidIndex(), limit); }
Iterator_t First() const { ssize_t limit = NumAllocated(); return Iterator_t(limit ? 0 : InvalidIndex(), limit); }
Iterator_t Next(const Iterator_t& it) const { return Iterator_t((it.index + 1 < it.limit) ? it.index + 1 : InvalidIndex(), it.limit); }
int64 GetIndex(const Iterator_t& it) const { return it.index; }
bool IsIdxAfter(int64 i, const Iterator_t& it) const { return i > it.index; }
ssize_t GetIndex(const Iterator_t& it) const { return it.index; }
bool IsIdxAfter(ssize_t i, const Iterator_t& it) const { return i > it.index; }
bool IsValidIterator(const Iterator_t& it) const { return IsIdxValid(it.index) && (it.index < it.limit); }
Iterator_t InvalidIterator() const { return Iterator_t(InvalidIndex(), 0); }
@ -410,7 +410,7 @@ private:
//-----------------------------------------------------------------------------
template< class T, class I >
CUtlMemory<T, I>::CUtlMemory(int64 nGrowSize, int64 nInitAllocationCount) : m_pMemory(0),
CUtlMemory<T, I>::CUtlMemory(ssize_t nGrowSize, ssize_t nInitAllocationCount) : m_pMemory(0),
m_nAllocationCount(nInitAllocationCount), m_nGrowSize(nGrowSize)
{
ValidateGrowSize();
@ -424,7 +424,7 @@ m_nAllocationCount(nInitAllocationCount), m_nGrowSize(nGrowSize)
}
template< class T, class I >
CUtlMemory<T, I>::CUtlMemory(T* pMemory, int64 numElements) : m_pMemory(pMemory),
CUtlMemory<T, I>::CUtlMemory(T* pMemory, ssize_t numElements) : m_pMemory(pMemory),
m_nAllocationCount(numElements)
{
// Special marker indicating externally supplied modifiable memory
@ -432,7 +432,7 @@ m_nAllocationCount(numElements)
}
template< class T, class I >
CUtlMemory<T, I>::CUtlMemory(const T* pMemory, int64 numElements) : m_pMemory((T*)pMemory),
CUtlMemory<T, I>::CUtlMemory(const T* pMemory, ssize_t numElements) : m_pMemory((T*)pMemory),
m_nAllocationCount(numElements)
{
// Special marker indicating externally supplied modifiable memory
@ -466,8 +466,8 @@ CUtlMemory<T, I>& CUtlMemory<T, I>::operator=(CUtlMemory&& moveFrom)
{
// Copy member variables to locals before purge to handle self-assignment
T* pMemory = moveFrom.m_pMemory;
int64 nAllocationCount = moveFrom.m_nAllocationCount;
int64 nGrowSize = moveFrom.m_nGrowSize;
ssize_t nAllocationCount = moveFrom.m_nAllocationCount;
ssize_t nGrowSize = moveFrom.m_nGrowSize;
moveFrom.m_pMemory = nullptr;
moveFrom.m_nAllocationCount = 0;
@ -484,7 +484,7 @@ CUtlMemory<T, I>& CUtlMemory<T, I>::operator=(CUtlMemory&& moveFrom)
}
template< class T, class I >
void CUtlMemory<T, I>::Init(int64 nGrowSize /*= 0*/, int64 nInitSize /*= 0*/)
void CUtlMemory<T, I>::Init(ssize_t nGrowSize /*= 0*/, ssize_t nInitSize /*= 0*/)
{
Purge();
@ -516,7 +516,7 @@ void CUtlMemory<T, I>::Swap(CUtlMemory<T, I>& mem)
// Switches the buffer from an external memory buffer to a reallocatable buffer
//-----------------------------------------------------------------------------
template< class T, class I >
void CUtlMemory<T, I>::ConvertToGrowableMemory(int64 nGrowSize)
void CUtlMemory<T, I>::ConvertToGrowableMemory(ssize_t nGrowSize)
{
if (!IsExternallyAllocated())
return;
@ -527,7 +527,7 @@ void CUtlMemory<T, I>::ConvertToGrowableMemory(int64 nGrowSize)
UTLMEMORY_TRACK_ALLOC();
MEM_ALLOC_CREDIT_CLASS();
int64 nNumBytes = m_nAllocationCount * sizeof(T);
ssize_t nNumBytes = m_nAllocationCount * sizeof(T);
T* pMemory = (T*)malloc(nNumBytes);
memcpy(pMemory, m_pMemory, nNumBytes);
m_pMemory = pMemory;
@ -543,7 +543,7 @@ void CUtlMemory<T, I>::ConvertToGrowableMemory(int64 nGrowSize)
// Attaches the buffer to external memory....
//-----------------------------------------------------------------------------
template< class T, class I >
void CUtlMemory<T, I>::SetExternalBuffer(T* pMemory, int64 numElements)
void CUtlMemory<T, I>::SetExternalBuffer(T* pMemory, ssize_t numElements)
{
// Blow away any existing allocated memory
Purge();
@ -556,7 +556,7 @@ void CUtlMemory<T, I>::SetExternalBuffer(T* pMemory, int64 numElements)
}
template< class T, class I >
void CUtlMemory<T, I>::SetExternalBuffer(const T* pMemory, int64 numElements)
void CUtlMemory<T, I>::SetExternalBuffer(const T* pMemory, ssize_t numElements)
{
// Blow away any existing allocated memory
Purge();
@ -569,7 +569,7 @@ void CUtlMemory<T, I>::SetExternalBuffer(const T* pMemory, int64 numElements)
}
template< class T, class I >
void CUtlMemory<T, I>::AssumeMemory(T* pMemory, int64 numElements)
void CUtlMemory<T, I>::AssumeMemory(T* pMemory, ssize_t numElements)
{
// Blow away any existing allocated memory
Purge();
@ -653,7 +653,7 @@ bool CUtlMemory<T, I>::IsReadOnly() const
template< class T, class I >
void CUtlMemory<T, I>::SetGrowSize(int64 nSize)
void CUtlMemory<T, I>::SetGrowSize(ssize_t nSize)
{
Assert(!IsExternallyAllocated());
Assert(nSize >= 0);
@ -683,13 +683,13 @@ inline const T* CUtlMemory<T, I>::Base() const
// Size
//-----------------------------------------------------------------------------
template< class T, class I >
inline int64 CUtlMemory<T, I>::NumAllocated() const
inline ssize_t CUtlMemory<T, I>::NumAllocated() const
{
return m_nAllocationCount;
}
template< class T, class I >
inline int64 CUtlMemory<T, I>::Count() const
inline ssize_t CUtlMemory<T, I>::Count() const
{
return m_nAllocationCount;
}
@ -703,14 +703,14 @@ inline bool CUtlMemory<T, I>::IsIdxValid(I i) const
{
// GCC warns if I is an unsigned type and we do a ">= 0" against it (since the comparison is always 0).
// We get the warning even if we cast inside the expression. It only goes away if we assign to another variable.
int64 x = i;
ssize_t x = i;
return (x >= 0) && (x < m_nAllocationCount);
}
//-----------------------------------------------------------------------------
// Grows the memory
//-----------------------------------------------------------------------------
inline int64 UtlMemory_CalcNewAllocationCount(int64 nAllocationCount, int64 nGrowSize, int64 nNewSize, int64 nBytesItem)
inline ssize_t UtlMemory_CalcNewAllocationCount(ssize_t nAllocationCount, ssize_t nGrowSize, ssize_t nNewSize, ssize_t nBytesItem)
{
if (nGrowSize)
{
@ -734,7 +734,7 @@ inline int64 UtlMemory_CalcNewAllocationCount(int64 nAllocationCount, int64 nGro
#ifndef _X360
nAllocationCount *= 2;
#else
int64 nNewAllocationCount = (nAllocationCount * 9) / 8; // 12.5 %
ssize_t nNewAllocationCount = (nAllocationCount * 9) / 8; // 12.5 %
if (nNewAllocationCount > nAllocationCount)
nAllocationCount = nNewAllocationCount;
else
@ -747,7 +747,7 @@ inline int64 UtlMemory_CalcNewAllocationCount(int64 nAllocationCount, int64 nGro
}
template< class T, class I >
void CUtlMemory<T, I>::Grow(int64 num)
void CUtlMemory<T, I>::Grow(ssize_t num)
{
Assert(num > 0);
@ -760,28 +760,28 @@ void CUtlMemory<T, I>::Grow(int64 num)
// Make sure we have at least numallocated + num allocations.
// Use the grow rules specified for this memory (in m_nGrowSize)
int64 nAllocationRequested = m_nAllocationCount + num;
ssize_t nAllocationRequested = m_nAllocationCount + num;
UTLMEMORY_TRACK_FREE();
int64 nNewAllocationCount = UtlMemory_CalcNewAllocationCount(m_nAllocationCount, m_nGrowSize, nAllocationRequested, sizeof(T));
ssize_t nNewAllocationCount = UtlMemory_CalcNewAllocationCount(m_nAllocationCount, m_nGrowSize, nAllocationRequested, sizeof(T));
// if m_nAllocationRequested wraps index type I, recalculate
if ((int64)(I)nNewAllocationCount < nAllocationRequested)
if ((ssize_t)(I)nNewAllocationCount < nAllocationRequested)
{
if ((int64)(I)nNewAllocationCount == 0 && (int64)(I)(nNewAllocationCount - 1) >= nAllocationRequested)
if ((ssize_t)(I)nNewAllocationCount == 0 && (ssize_t)(I)(nNewAllocationCount - 1) >= nAllocationRequested)
{
--nNewAllocationCount; // deal w/ the common case of m_nAllocationCount == MAX_USHORT + 1
}
else
{
if ((int64)(I)nAllocationRequested != nAllocationRequested)
if ((ssize_t)(I)nAllocationRequested != nAllocationRequested)
{
// we've been asked to grow memory to a size s.t. the index type can't address the requested amount of memory
Assert(0);
return;
}
while ((int64)(I)nNewAllocationCount < nAllocationRequested)
while ((ssize_t)(I)nNewAllocationCount < nAllocationRequested)
{
nNewAllocationCount = (nNewAllocationCount + nAllocationRequested) / 2;
}
@ -811,7 +811,7 @@ void CUtlMemory<T, I>::Grow(int64 num)
// Makes sure we've got at least this much memory
//-----------------------------------------------------------------------------
template< class T, class I >
inline void CUtlMemory<T, I>::EnsureCapacity(int64 num)
inline void CUtlMemory<T, I>::EnsureCapacity(ssize_t num)
{
if (m_nAllocationCount >= num)
return;
@ -861,7 +861,7 @@ void CUtlMemory<T, I>::Purge()
}
template< class T, class I >
void CUtlMemory<T, I>::Purge(int64 numElements)
void CUtlMemory<T, I>::Purge(ssize_t numElements)
{
Assert(numElements >= 0);
@ -914,31 +914,31 @@ void CUtlMemory<T, I>::Purge(int64 numElements)
// The CUtlMemory class:
// A growable memory class which doubles in size by default.
//-----------------------------------------------------------------------------
template< class T, int64 nAlignment >
template< class T, ssize_t nAlignment >
class CUtlMemoryAligned : public CUtlMemory<T>
{
public:
// constructor, destructor
CUtlMemoryAligned(int64 nGrowSize = 0, int64 nInitSize = 0);
CUtlMemoryAligned(T* pMemory, int64 numElements);
CUtlMemoryAligned(const T* pMemory, int64 numElements);
CUtlMemoryAligned(ssize_t nGrowSize = 0, ssize_t nInitSize = 0);
CUtlMemoryAligned(T* pMemory, ssize_t numElements);
CUtlMemoryAligned(const T* pMemory, ssize_t numElements);
~CUtlMemoryAligned();
// Attaches the buffer to external memory....
void SetExternalBuffer(T* pMemory, int64 numElements);
void SetExternalBuffer(const T* pMemory, int64 numElements);
void SetExternalBuffer(T* pMemory, ssize_t numElements);
void SetExternalBuffer(const T* pMemory, ssize_t numElements);
// Grows the memory, so that at least allocated + num elements are allocated
void Grow(int64 num = 1);
void Grow(ssize_t num = 1);
// Makes sure we've got at least this much memory
void EnsureCapacity(int64 num);
void EnsureCapacity(ssize_t num);
// Memory deallocation
void Purge();
// Purge all but the given number of elements (NOT IMPLEMENTED IN CUtlMemoryAligned)
void Purge(int64 numElements) { Assert(0); }
void Purge(ssize_t numElements) { Assert(0); }
private:
void* Align(const void* pAddr);
@ -948,7 +948,7 @@ private:
//-----------------------------------------------------------------------------
// Aligns a pointer
//-----------------------------------------------------------------------------
template< class T, int64 nAlignment >
template< class T, ssize_t nAlignment >
void* CUtlMemoryAligned<T, nAlignment>::Align(const void* pAddr)
{
size_t nAlignmentMask = nAlignment - 1;
@ -959,8 +959,8 @@ void* CUtlMemoryAligned<T, nAlignment>::Align(const void* pAddr)
//-----------------------------------------------------------------------------
// constructor, destructor
//-----------------------------------------------------------------------------
template< class T, int64 nAlignment >
CUtlMemoryAligned<T, nAlignment>::CUtlMemoryAligned(int64 nGrowSize, int64 nInitAllocationCount)
template< class T, ssize_t nAlignment >
CUtlMemoryAligned<T, nAlignment>::CUtlMemoryAligned(ssize_t nGrowSize, ssize_t nInitAllocationCount)
{
CUtlMemory<T>::m_pMemory = 0;
CUtlMemory<T>::m_nAllocationCount = nInitAllocationCount;
@ -978,27 +978,27 @@ CUtlMemoryAligned<T, nAlignment>::CUtlMemoryAligned(int64 nGrowSize, int64 nInit
}
}
template< class T, int64 nAlignment >
CUtlMemoryAligned<T, nAlignment>::CUtlMemoryAligned(T* pMemory, int64 numElements)
template< class T, ssize_t nAlignment >
CUtlMemoryAligned<T, nAlignment>::CUtlMemoryAligned(T* pMemory, ssize_t numElements)
{
// Special marker indicating externally supplied memory
CUtlMemory<T>::m_nGrowSize = CUtlMemory<T>::EXTERNAL_BUFFER_MARKER;
CUtlMemory<T>::m_pMemory = (T*)Align(pMemory);
CUtlMemory<T>::m_nAllocationCount = ((int64)(pMemory + numElements) - (int64)CUtlMemory<T>::m_pMemory) / sizeof(T);
CUtlMemory<T>::m_nAllocationCount = ((ssize_t)(pMemory + numElements) - (ssize_t)CUtlMemory<T>::m_pMemory) / sizeof(T);
}
template< class T, int64 nAlignment >
CUtlMemoryAligned<T, nAlignment>::CUtlMemoryAligned(const T* pMemory, int64 numElements)
template< class T, ssize_t nAlignment >
CUtlMemoryAligned<T, nAlignment>::CUtlMemoryAligned(const T* pMemory, ssize_t numElements)
{
// Special marker indicating externally supplied memory
CUtlMemory<T>::m_nGrowSize = CUtlMemory<T>::EXTERNAL_CONST_BUFFER_MARKER;
CUtlMemory<T>::m_pMemory = (T*)Align(pMemory);
CUtlMemory<T>::m_nAllocationCount = ((int64)(pMemory + numElements) - (int64)CUtlMemory<T>::m_pMemory) / sizeof(T);
CUtlMemory<T>::m_nAllocationCount = ((ssize_t)(pMemory + numElements) - (ssize_t)CUtlMemory<T>::m_pMemory) / sizeof(T);
}
template< class T, int64 nAlignment >
template< class T, ssize_t nAlignment >
CUtlMemoryAligned<T, nAlignment>::~CUtlMemoryAligned()
{
Purge();
@ -1008,27 +1008,27 @@ CUtlMemoryAligned<T, nAlignment>::~CUtlMemoryAligned()
//-----------------------------------------------------------------------------
// Attaches the buffer to external memory....
//-----------------------------------------------------------------------------
template< class T, int64 nAlignment >
void CUtlMemoryAligned<T, nAlignment>::SetExternalBuffer(T* pMemory, int64 numElements)
template< class T, ssize_t nAlignment >
void CUtlMemoryAligned<T, nAlignment>::SetExternalBuffer(T* pMemory, ssize_t numElements)
{
// Blow away any existing allocated memory
Purge();
CUtlMemory<T>::m_pMemory = (T*)Align(pMemory);
CUtlMemory<T>::m_nAllocationCount = ((int64)(pMemory + numElements) - (int64)CUtlMemory<T>::m_pMemory) / sizeof(T);
CUtlMemory<T>::m_nAllocationCount = ((ssize_t)(pMemory + numElements) - (ssize_t)CUtlMemory<T>::m_pMemory) / sizeof(T);
// Indicate that we don't own the memory
CUtlMemory<T>::m_nGrowSize = CUtlMemory<T>::EXTERNAL_BUFFER_MARKER;
}
template< class T, int64 nAlignment >
void CUtlMemoryAligned<T, nAlignment>::SetExternalBuffer(const T* pMemory, int64 numElements)
template< class T, ssize_t nAlignment >
void CUtlMemoryAligned<T, nAlignment>::SetExternalBuffer(const T* pMemory, ssize_t numElements)
{
// Blow away any existing allocated memory
Purge();
CUtlMemory<T>::m_pMemory = (T*)Align(pMemory);
CUtlMemory<T>::m_nAllocationCount = ((int64)(pMemory + numElements) - (int64)CUtlMemory<T>::m_pMemory) / sizeof(T);
CUtlMemory<T>::m_nAllocationCount = ((ssize_t)(pMemory + numElements) - (ssize_t)CUtlMemory<T>::m_pMemory) / sizeof(T);
// Indicate that we don't own the memory
CUtlMemory<T>::m_nGrowSize = CUtlMemory<T>::EXTERNAL_CONST_BUFFER_MARKER;
@ -1038,8 +1038,8 @@ void CUtlMemoryAligned<T, nAlignment>::SetExternalBuffer(const T* pMemory, int64
//-----------------------------------------------------------------------------
// Grows the memory
//-----------------------------------------------------------------------------
template< class T, int64 nAlignment >
void CUtlMemoryAligned<T, nAlignment>::Grow(int64 num)
template< class T, ssize_t nAlignment >
void CUtlMemoryAligned<T, nAlignment>::Grow(ssize_t num)
{
Assert(num > 0);
@ -1054,7 +1054,7 @@ void CUtlMemoryAligned<T, nAlignment>::Grow(int64 num)
// Make sure we have at least numallocated + num allocations.
// Use the grow rules specified for this memory (in m_nGrowSize)
int64 nAllocationRequested = CUtlMemory<T>::m_nAllocationCount + num;
ssize_t nAllocationRequested = CUtlMemory<T>::m_nAllocationCount + num;
CUtlMemory<T>::m_nAllocationCount = UtlMemory_CalcNewAllocationCount(CUtlMemory<T>::m_nAllocationCount, CUtlMemory<T>::m_nGrowSize, nAllocationRequested, sizeof(T));
@ -1078,8 +1078,8 @@ void CUtlMemoryAligned<T, nAlignment>::Grow(int64 num)
//-----------------------------------------------------------------------------
// Makes sure we've got at least this much memory
//-----------------------------------------------------------------------------
template< class T, int64 nAlignment >
inline void CUtlMemoryAligned<T, nAlignment>::EnsureCapacity(int64 num)
template< class T, ssize_t nAlignment >
inline void CUtlMemoryAligned<T, nAlignment>::EnsureCapacity(ssize_t num)
{
if (CUtlMemory<T>::m_nAllocationCount >= num)
return;
@ -1113,7 +1113,7 @@ inline void CUtlMemoryAligned<T, nAlignment>::EnsureCapacity(int64 num)
//-----------------------------------------------------------------------------
// Memory deallocation
//-----------------------------------------------------------------------------
template< class T, int64 nAlignment >
template< class T, ssize_t nAlignment >
void CUtlMemoryAligned<T, nAlignment>::Purge()
{
if (!this->IsExternallyAllocated())

View File

@ -151,11 +151,11 @@ public:
// Left at growSize = 0, the memory will first allocate 1 element and double in size
// at each increment.
// LessFunc_t is required, but may be set after the constructor using SetLessFunc() below
CUtlRBTree(int64 growSize = 0, int64 initSize = 0, const LessFunc_t& lessfunc = 0);
CUtlRBTree(ssize_t growSize = 0, ssize_t initSize = 0, const LessFunc_t& lessfunc = 0);
CUtlRBTree(const LessFunc_t& lessfunc);
~CUtlRBTree();
void EnsureCapacity(int64 num);
void EnsureCapacity(ssize_t num);
// NOTE: CopyFrom is fast but dangerous! It just memcpy's all nodes - it does NOT run copy constructors, so
// it is not a true deep copy (i.e 'T' must be POD for this to work - e.g CUtlString will not work).
@ -215,7 +215,7 @@ public:
// NOTE: the returned 'index' will be valid as long as the element remains in the tree
// (other elements being added/removed will not affect it)
I Insert(T const& insert);
void Insert(const T* pArray, int64 nItems);
void Insert(const T* pArray, ssize_t nItems);
I InsertIfNotFound(T const& insert);
// Find method
@ -384,7 +384,7 @@ protected:
//-----------------------------------------------------------------------------
template < class T, class I, typename L, class M >
inline CUtlRBTree<T, I, L, M>::CUtlRBTree(int64 growSize, int64 initSize, const LessFunc_t& lessfunc) :
inline CUtlRBTree<T, I, L, M>::CUtlRBTree(ssize_t growSize, ssize_t initSize, const LessFunc_t& lessfunc) :
m_LessFunc(lessfunc),
m_Elements(growSize, initSize),
m_Root(InvalidIndex()),
@ -397,7 +397,7 @@ inline CUtlRBTree<T, I, L, M>::CUtlRBTree(int64 growSize, int64 initSize, const
template < class T, class I, typename L, class M >
inline CUtlRBTree<T, I, L, M>::CUtlRBTree(const LessFunc_t& lessfunc) :
m_Elements((int64)0, (int64)0),
m_Elements((ssize_t)0, (ssize_t)0),
m_LessFunc(lessfunc),
m_Root(InvalidIndex()),
m_NumElements(0),
@ -414,7 +414,7 @@ inline CUtlRBTree<T, I, L, M>::~CUtlRBTree()
}
template < class T, class I, typename L, class M >
inline void CUtlRBTree<T, I, L, M>::EnsureCapacity(int64 num)
inline void CUtlRBTree<T, I, L, M>::EnsureCapacity(ssize_t num)
{
m_Elements.EnsureCapacity(num);
}
@ -1509,7 +1509,7 @@ I CUtlRBTree<T, I, L, M>::Insert(T const& insert)
template < class T, class I, typename L, class M >
void CUtlRBTree<T, I, L, M>::Insert(const T* pArray, int64 nItems)
void CUtlRBTree<T, I, L, M>::Insert(const T* pArray, ssize_t nItems)
{
while (nItems--)
{

View File

@ -24,7 +24,7 @@
class CUtlBinaryBlock
{
public:
CUtlBinaryBlock( int64 growSize = 0, int64 initSize = 0 );
CUtlBinaryBlock( ssize_t growSize = 0, ssize_t initSize = 0 );
~CUtlBinaryBlock()
{
#ifdef _DEBUG
@ -35,8 +35,8 @@ public:
}
// NOTE: nInitialLength indicates how much of the buffer starts full
CUtlBinaryBlock( void* pMemory, int64 nSizeInBytes, int64 nInitialLength );
CUtlBinaryBlock( const void* pMemory, int64 nSizeInBytes );
CUtlBinaryBlock( void* pMemory, ssize_t nSizeInBytes, ssize_t nInitialLength );
CUtlBinaryBlock( const void* pMemory, ssize_t nSizeInBytes );
CUtlBinaryBlock( const CUtlBinaryBlock& src );
CUtlBinaryBlock &operator=( const CUtlBinaryBlock &src );
@ -46,16 +46,16 @@ public:
CUtlBinaryBlock &operator=( CUtlBinaryBlock&& src );
#endif
void Get( void *pValue, int64 nMaxLen ) const;
void Set( const void *pValue, int64 nLen );
void Get( void *pValue, ssize_t nMaxLen ) const;
void Set( const void *pValue, ssize_t nLen );
const void *Get( ) const;
void *Get( );
unsigned char& operator[]( int64 i );
const unsigned char& operator[]( int64 i ) const;
unsigned char& operator[]( ssize_t i );
const unsigned char& operator[]( ssize_t i ) const;
int64 Length() const;
void SetLength( int64 nLength ); // Undefined memory will result
ssize_t Length() const;
void SetLength( ssize_t nLength ); // Undefined memory will result
bool IsEmpty() const;
void Clear();
void Purge();
@ -68,7 +68,7 @@ public:
private:
CUtlMemory<unsigned char> m_Memory;
int64 m_nActualLength;
ssize_t m_nActualLength;
};
@ -86,7 +86,7 @@ inline CUtlBinaryBlock::CUtlBinaryBlock( CUtlBinaryBlock&& src )
inline CUtlBinaryBlock& CUtlBinaryBlock::operator= ( CUtlBinaryBlock&& src )
{
int64 length = src.m_nActualLength;
ssize_t length = src.m_nActualLength;
src.m_nActualLength = 0;
m_Memory = Move( src.m_Memory );
@ -106,17 +106,17 @@ inline void *CUtlBinaryBlock::Get( )
return m_Memory.Base();
}
inline int64 CUtlBinaryBlock::Length() const
inline ssize_t CUtlBinaryBlock::Length() const
{
return m_nActualLength;
}
inline unsigned char& CUtlBinaryBlock::operator[]( int64 i )
inline unsigned char& CUtlBinaryBlock::operator[]( ssize_t i )
{
return m_Memory[i];
}
inline const unsigned char& CUtlBinaryBlock::operator[]( int64 i ) const
inline const unsigned char& CUtlBinaryBlock::operator[]( ssize_t i ) const
{
return m_Memory[i];
}
@ -154,8 +154,8 @@ public:
CUtlString( const char *pString ); // initialize from c-style string
// Attaches the string to external memory. Useful for avoiding a copy
CUtlString( void* pMemory, int64 nSizeInBytes, int64 nInitialLength );
CUtlString( const void* pMemory, int64 nSizeInBytes );
CUtlString( void* pMemory, ssize_t nSizeInBytes, ssize_t nInitialLength );
CUtlString( const void* pMemory, ssize_t nSizeInBytes );
// Copy/move constructor/assignment
// Moves are extremely efficient as the underlying memory is not copied, just the pointers.
@ -185,7 +185,7 @@ public:
const char *String() const { return Get(); }
// Returns strlen
int64 Length() const;
ssize_t Length() const;
bool IsEmpty() const;
// GS - Added for chromehtml
@ -197,7 +197,7 @@ public:
// Sets the length (used to serialize into the buffer )
// Note: If nLen != 0, then this adds an extra byte for a null-terminator.
void Set( const char *pValue );
void SetLength( int64 nLen );
void SetLength( ssize_t nLen );
void Purge();
void Swap(CUtlString &src);
@ -206,7 +206,7 @@ public:
void ToUpper();
void ToLower( );
void Append( const char *pchAddition );
void Append(const char *pchAddition, int64 nMaxChars);
void Append(const char *pchAddition, ssize_t nMaxChars);
void Append(char chAddition) {
char temp[2] = { chAddition, 0 };
Append(temp);
@ -215,8 +215,8 @@ public:
// Strips the trailing slash
void StripTrailingSlash();
char operator[] ( int64 idx ) const;
char& operator[] ( int64 idx );
char operator[] ( ssize_t idx ) const;
char& operator[] ( ssize_t idx );
// Test for equality
bool operator==( const CUtlString &src ) const;
@ -232,11 +232,11 @@ public:
CUtlString &operator+=( const CUtlString &rhs );
CUtlString &operator+=( const char *rhs );
CUtlString &operator+=( char c );
CUtlString &operator+=( int64 rhs );
CUtlString &operator+=( ssize_t rhs );
CUtlString &operator+=( double rhs );
CUtlString operator+( const char *pOther )const;
//CUtlString operator+( int64 rhs )const;
//CUtlString operator+( ssize_t rhs )const;
bool MatchesPattern( const CUtlString &Pattern, int nFlags = 0 ); // case SENSITIVE, use * for wildcard in pattern string
@ -249,7 +249,7 @@ public:
int FormatV( const char *pFormat, va_list marker );
#endif
void SetDirect( const char *pValue, int64 nChars );
void SetDirect( const char *pValue, ssize_t nChars );
// Defining AltArgumentType_t hints that associative container classes should
// also implement Find/Insert/Remove functions that take const char* params.
@ -260,11 +260,11 @@ public:
// Take a piece out of the string.
// If you only specify nStart, it'll go from nStart to the end.
// You can use negative numbers and it'll wrap around to the start.
CUtlString Slice( int64 nStart=0, int64 nEnd=INT_MAX );
CUtlString Slice( ssize_t nStart=0, ssize_t nEnd=INT_MAX );
// Grab a substring starting from the left or the right side.
CUtlString Left( int64 nChars );
CUtlString Right( int64 nChars );
CUtlString Left( ssize_t nChars );
CUtlString Right( ssize_t nChars );
CUtlString Remove( char const *pTextToRemove, bool bCaseSensitive ) const;
@ -319,14 +319,14 @@ public:
static CUtlString PathJoin( const char *pStr1, const char *pStr2 );
// These can be used for utlvector sorts.
static int64 __cdecl SortCaseInsensitive( const CUtlString *pString1, const CUtlString *pString2 );
static int64 __cdecl SortCaseSensitive( const CUtlString *pString1, const CUtlString *pString2 );
static ssize_t __cdecl SortCaseInsensitive( const CUtlString *pString1, const CUtlString *pString2 );
static ssize_t __cdecl SortCaseSensitive( const CUtlString *pString1, const CUtlString *pString2 );
// From Src2
void AppendSlash( char separator = CORRECT_PATH_SEPARATOR )
{
int64 nLength = Length() - 1;
ssize_t nLength = Length() - 1;
if ( nLength > 0 && !PATHSEPARATOR( static_cast< char >( m_Storage[ nLength ] ) ) )
{
Append( separator );
@ -335,7 +335,7 @@ public:
void FixSlashes( char cSeparator = CORRECT_PATH_SEPARATOR )
{
for ( int64 nLength = Length() - 1; nLength >= 0; nLength-- )
for ( ssize_t nLength = Length() - 1; nLength >= 0; nLength-- )
{
char *pname = (char*)&m_Storage[ nLength ];
if ( *pname == INCORRECT_PATH_SEPARATOR || *pname == CORRECT_PATH_SEPARATOR )
@ -397,22 +397,22 @@ inline bool CUtlString::IsEmpty() const
return Length() == 0;
}
inline int64 __cdecl CUtlString::SortCaseInsensitive( const CUtlString *pString1, const CUtlString *pString2 )
inline ssize_t __cdecl CUtlString::SortCaseInsensitive( const CUtlString *pString1, const CUtlString *pString2 )
{
return V_stricmp( pString1->String(), pString2->String() );
}
inline int64 __cdecl CUtlString::SortCaseSensitive( const CUtlString *pString1, const CUtlString *pString2 )
inline ssize_t __cdecl CUtlString::SortCaseSensitive( const CUtlString *pString1, const CUtlString *pString2 )
{
return V_strcmp( pString1->String(), pString2->String() );
}
inline char CUtlString::operator [] ( int64 index ) const
inline char CUtlString::operator [] ( ssize_t index ) const
{
return Get()[index];
}
inline char& CUtlString::operator[] ( int64 index )
inline char& CUtlString::operator[] ( ssize_t index )
{
return Access()[index];
}
@ -625,7 +625,7 @@ public:
void Append(const CUtlStringBuilder &str) { Append(str.String(), str.Length()); }
//void Append( IFillStringFunctor& func );
void AppendChar(char ch) { Append(&ch, 1); }
void AppendRepeat(char ch, int64 cCount);
void AppendRepeat(char ch, ssize_t cCount);
// sets the string
void SetValue(const char *pchString);
@ -1375,7 +1375,7 @@ inline void CUtlStringBuilder::Append(const char *pchAddition, size_t cbLen)
//-----------------------------------------------------------------------------
// Purpose: append a repeated series of a single character
//-----------------------------------------------------------------------------
inline void CUtlStringBuilder::AppendRepeat(char ch, int64 cCount)
inline void CUtlStringBuilder::AppendRepeat(char ch, ssize_t cCount)
{
size_t cbOld = Length();
char *pstrNew = PrepareBuffer(cbOld + cCount, true);

View File

@ -57,7 +57,7 @@ char* V_stristr(char* pStr, char const* pSearch)
//-----------------------------------------------------------------------------
// Finds a string in another string with a case insensitive test w/ length validation
//-----------------------------------------------------------------------------
const char* V_strnistr(const char* pStr, const char* pSearch, int64_t n)
const char* V_strnistr(const char* pStr, const char* pSearch, ssize_t n)
{
Assert(pStr);
Assert(pSearch);
@ -75,7 +75,7 @@ const char* V_strnistr(const char* pStr, const char* pSearch, int64_t n)
// Skip over non-matches
if (FastASCIIToLower(*pLetter) == FastASCIIToLower(*pSearch))
{
int64_t n1 = n - 1;
ssize_t n1 = n - 1;
// Check for match
const char* pMatch = pLetter + 1;
@ -109,7 +109,7 @@ const char* V_strnistr(const char* pStr, const char* pSearch, int64_t n)
return 0;
}
const char* V_strnchr(const char* pStr, char c, int64_t n)
const char* V_strnchr(const char* pStr, char c, ssize_t n)
{
const char* pLetter = pStr;
const char* pLast = pStr + n;
@ -153,7 +153,7 @@ bool V_isspace(int c)
#endif
}
int64_t V_StrTrim(char* pStr)
ssize_t V_StrTrim(char* pStr)
{
char* pSource = pStr;
char* pDest = pStr;

View File

@ -22,10 +22,10 @@
class CUtlCStringConversion : public CUtlCharConversion
{
public:
CUtlCStringConversion(char nEscapeChar, const char* pDelimiter, int64 nCount, ConversionArray_t* pArray);
CUtlCStringConversion(char nEscapeChar, const char* pDelimiter, ssize_t nCount, ConversionArray_t* pArray);
// Finds a conversion for the passed-in string, returns length
virtual char FindConversion(const char* pString, int64* pLength);
virtual char FindConversion(const char* pString, ssize_t* pLength);
private:
char m_pConversion[256];
@ -38,11 +38,11 @@ private:
class CUtlNoEscConversion : public CUtlCharConversion
{
public:
CUtlNoEscConversion(char nEscapeChar, const char* pDelimiter, int64 nCount, ConversionArray_t* pArray) :
CUtlNoEscConversion(char nEscapeChar, const char* pDelimiter, ssize_t nCount, ConversionArray_t* pArray) :
CUtlCharConversion(nEscapeChar, pDelimiter, nCount, pArray) {}
// Finds a conversion for the passed-in string, returns length
virtual char FindConversion(const char* pString, int64* pLength) { *pLength = 0; return 0; }
virtual char FindConversion(const char* pString, ssize_t* pLength) { *pLength = 0; return 0; }
};
@ -85,18 +85,18 @@ public:
//-----------------------------------------------------------------------------
// Constructor
//-----------------------------------------------------------------------------
CUtlCStringConversion::CUtlCStringConversion(char nEscapeChar, const char* pDelimiter, int64 nCount, ConversionArray_t* pArray) :
CUtlCStringConversion::CUtlCStringConversion(char nEscapeChar, const char* pDelimiter, ssize_t nCount, ConversionArray_t* pArray) :
CUtlCharConversion(nEscapeChar, pDelimiter, nCount, pArray)
{
memset(m_pConversion, 0x0, sizeof(m_pConversion));
for (int64 i = 0; i < nCount; ++i)
for (ssize_t i = 0; i < nCount; ++i)
{
m_pConversion[(unsigned char)(pArray[i].m_pReplacementString[0])] = pArray[i].m_nActualChar;
}
}
// Finds a conversion for the passed-in string, returns length
char CUtlCStringConversion::FindConversion(const char* pString, int64* pLength)
char CUtlCStringConversion::FindConversion(const char* pString, ssize_t* pLength)
{
char c = m_pConversion[(unsigned char)(pString[0])];
*pLength = (c != '\0') ? 1 : 0;
@ -108,7 +108,7 @@ char CUtlCStringConversion::FindConversion(const char* pString, int64* pLength)
//-----------------------------------------------------------------------------
// Constructor
//-----------------------------------------------------------------------------
CUtlCharConversion::CUtlCharConversion(char nEscapeChar, const char* pDelimiter, int64 nCount, ConversionArray_t* pArray)
CUtlCharConversion::CUtlCharConversion(char nEscapeChar, const char* pDelimiter, ssize_t nCount, ConversionArray_t* pArray)
{
m_nEscapeChar = nEscapeChar;
m_pDelimiter = pDelimiter;
@ -118,7 +118,7 @@ CUtlCharConversion::CUtlCharConversion(char nEscapeChar, const char* pDelimiter,
memset(m_pReplacements, 0, sizeof(m_pReplacements));
for (int64 i = 0; i < nCount; ++i)
for (ssize_t i = 0; i < nCount; ++i)
{
m_pList[i] = pArray[i].m_nActualChar;
ConversionInfo_t& info = m_pReplacements[(unsigned char)(m_pList[i])];
@ -146,7 +146,7 @@ const char* CUtlCharConversion::GetDelimiter() const
return m_pDelimiter;
}
int64 CUtlCharConversion::GetDelimiterLength() const
ssize_t CUtlCharConversion::GetDelimiterLength() const
{
return m_nDelimiterLength;
}
@ -160,12 +160,12 @@ const char* CUtlCharConversion::GetConversionString(char c) const
return m_pReplacements[(unsigned char)c].m_pReplacementString;
}
int64 CUtlCharConversion::GetConversionLength(char c) const
ssize_t CUtlCharConversion::GetConversionLength(char c) const
{
return m_pReplacements[(unsigned char)c].m_nLength;
}
int64 CUtlCharConversion::MaxConversionLength() const
ssize_t CUtlCharConversion::MaxConversionLength() const
{
return m_nMaxConversionLength;
}
@ -174,9 +174,9 @@ int64 CUtlCharConversion::MaxConversionLength() const
//-----------------------------------------------------------------------------
// Finds a conversion for the passed-in string, returns length
//-----------------------------------------------------------------------------
char CUtlCharConversion::FindConversion(const char* pString, int64* pLength)
char CUtlCharConversion::FindConversion(const char* pString, ssize_t* pLength)
{
for (int64 i = 0; i < m_nCount; ++i)
for (ssize_t i = 0; i < m_nCount; ++i)
{
if (!V_strcmp(pString, m_pReplacements[(unsigned char)(m_pList[i])].m_pReplacementString))
{
@ -193,7 +193,7 @@ char CUtlCharConversion::FindConversion(const char* pString, int64* pLength)
//-----------------------------------------------------------------------------
// constructors
//-----------------------------------------------------------------------------
CUtlBuffer::CUtlBuffer(int64 growSize, int64 initSize, int nFlags) :
CUtlBuffer::CUtlBuffer(ssize_t growSize, ssize_t initSize, int nFlags) :
m_Error(0)
{
//MEM_ALLOC_CREDIT();
@ -215,7 +215,7 @@ CUtlBuffer::CUtlBuffer(int64 growSize, int64 initSize, int nFlags) :
SetOverflowFuncs(&CUtlBuffer::GetOverflow, &CUtlBuffer::PutOverflow);
}
CUtlBuffer::CUtlBuffer(const void* pBuffer, int64 nSize, int nFlags) :
CUtlBuffer::CUtlBuffer(const void* pBuffer, ssize_t nSize, int nFlags) :
m_Memory((unsigned char*)pBuffer, nSize), m_Error(0)
{
Assert(nSize != 0);
@ -388,7 +388,7 @@ void CUtlBuffer::SetBufferType(bool bIsText, bool bContainsCRLF)
//-----------------------------------------------------------------------------
// Attaches the buffer to external memory....
//-----------------------------------------------------------------------------
void CUtlBuffer::SetExternalBuffer(void* pMemory, int64 nSize, int64 nInitialPut, int nFlags)
void CUtlBuffer::SetExternalBuffer(void* pMemory, ssize_t nSize, ssize_t nInitialPut, int nFlags)
{
m_Memory.SetExternalBuffer((unsigned char*)pMemory, nSize);
@ -406,7 +406,7 @@ void CUtlBuffer::SetExternalBuffer(void* pMemory, int64 nSize, int64 nInitialPut
//-----------------------------------------------------------------------------
// Assumes an external buffer but manages its deletion
//-----------------------------------------------------------------------------
void CUtlBuffer::AssumeMemory(void* pMemory, int64 nSize, int64 nInitialPut, int nFlags)
void CUtlBuffer::AssumeMemory(void* pMemory, ssize_t nSize, ssize_t nInitialPut, int nFlags)
{
m_Memory.AssumeMemory((unsigned char*)pMemory, nSize);
@ -440,7 +440,7 @@ void* CUtlBuffer::DetachMemory()
//-----------------------------------------------------------------------------
// Makes sure we've got at least this much memory
//-----------------------------------------------------------------------------
void CUtlBuffer::EnsureCapacity(int64 num)
void CUtlBuffer::EnsureCapacity(ssize_t num)
{
//MEM_ALLOC_CREDIT();
// Add one extra for the null termination
@ -464,7 +464,7 @@ void CUtlBuffer::EnsureCapacity(int64 num)
//-----------------------------------------------------------------------------
// Base get method from which all others derive
//-----------------------------------------------------------------------------
bool CUtlBuffer::Get(void* pMem, int64 size)
bool CUtlBuffer::Get(void* pMem, ssize_t size)
{
if (size > 0 && CheckGet(size))
{
@ -480,7 +480,7 @@ bool CUtlBuffer::Get(void* pMem, int64 size)
// This will get at least 1 byte and up to nSize bytes.
// It will return the number of bytes actually read.
//-----------------------------------------------------------------------------
int64 CUtlBuffer::GetUpTo(void* pMem, int64 nSize)
ssize_t CUtlBuffer::GetUpTo(void* pMem, ssize_t nSize)
{
if (CheckArbitraryPeekGet(0, nSize))
{
@ -539,7 +539,7 @@ bool CUtlBuffer::EatCPPComment()
//-----------------------------------------------------------------------------
// Peeks how much whitespace to eat
//-----------------------------------------------------------------------------
int64 CUtlBuffer::PeekWhiteSpace(int64 nOffset)
ssize_t CUtlBuffer::PeekWhiteSpace(ssize_t nOffset)
{
if (!IsText() || !IsValid())
return 0;
@ -558,23 +558,23 @@ int64 CUtlBuffer::PeekWhiteSpace(int64 nOffset)
//-----------------------------------------------------------------------------
// Peek size of sting to come, check memory bound
//-----------------------------------------------------------------------------
int64 CUtlBuffer::PeekStringLength()
ssize_t CUtlBuffer::PeekStringLength()
{
if (!IsValid())
return 0;
// Eat preceding whitespace
int64 nOffset = 0;
ssize_t nOffset = 0;
if (IsText())
{
nOffset = PeekWhiteSpace(nOffset);
}
int64 nStartingOffset = nOffset;
ssize_t nStartingOffset = nOffset;
do
{
int64 nPeekAmount = 128;
ssize_t nPeekAmount = 128;
// NOTE: Add 1 for the terminating zero!
if (!CheckArbitraryPeekGet(nOffset, nPeekAmount))
@ -588,7 +588,7 @@ int64 CUtlBuffer::PeekStringLength()
if (!IsText())
{
for (int64 i = 0; i < nPeekAmount; ++i)
for (ssize_t i = 0; i < nPeekAmount; ++i)
{
// The +1 here is so we eat the terminating 0
if (pTest[i] == 0)
@ -597,7 +597,7 @@ int64 CUtlBuffer::PeekStringLength()
}
else
{
for (int64 i = 0; i < nPeekAmount; ++i)
for (ssize_t i = 0; i < nPeekAmount; ++i)
{
// The +1 here is so we eat the terminating 0
if (V_isspace((unsigned char)pTest[i]) || (pTest[i] == 0))
@ -614,17 +614,17 @@ int64 CUtlBuffer::PeekStringLength()
//-----------------------------------------------------------------------------
// Peek size of line to come, check memory bound
//-----------------------------------------------------------------------------
int64 CUtlBuffer::PeekLineLength()
ssize_t CUtlBuffer::PeekLineLength()
{
if (!IsValid())
return 0;
int64 nOffset = 0;
int64 nStartingOffset = nOffset;
ssize_t nOffset = 0;
ssize_t nStartingOffset = nOffset;
do
{
int64 nPeekAmount = 128;
ssize_t nPeekAmount = 128;
// NOTE: Add 1 for the terminating zero!
if (!CheckArbitraryPeekGet(nOffset, nPeekAmount))
@ -636,7 +636,7 @@ int64 CUtlBuffer::PeekLineLength()
const char* pTest = (const char*)PeekGet(nOffset);
for (int64 i = 0; i < nPeekAmount; ++i)
for (ssize_t i = 0; i < nPeekAmount; ++i)
{
// The +2 here is so we eat the terminating '\n' and 0
if (pTest[i] == '\n' || pTest[i] == '\r')
@ -655,7 +655,7 @@ int64 CUtlBuffer::PeekLineLength()
//-----------------------------------------------------------------------------
// Does the next bytes of the buffer match a pattern?
//-----------------------------------------------------------------------------
bool CUtlBuffer::PeekStringMatch(int64 nOffset, const char* pString, int64 nLen)
bool CUtlBuffer::PeekStringMatch(ssize_t nOffset, const char* pString, ssize_t nLen)
{
if (!CheckPeekGet(nOffset, nLen))
return false;
@ -667,13 +667,13 @@ bool CUtlBuffer::PeekStringMatch(int64 nOffset, const char* pString, int64 nLen)
// This version of PeekStringLength converts \" to \\ and " to \, etc.
// It also reads a " at the beginning and end of the string
//-----------------------------------------------------------------------------
int64 CUtlBuffer::PeekDelimitedStringLength(CUtlCharConversion* pConv, bool bActualSize)
ssize_t CUtlBuffer::PeekDelimitedStringLength(CUtlCharConversion* pConv, bool bActualSize)
{
if (!IsText() || !pConv)
return PeekStringLength();
// Eat preceding whitespace
int64 nOffset = 0;
ssize_t nOffset = 0;
if (IsText())
{
nOffset = PeekWhiteSpace(nOffset);
@ -683,9 +683,9 @@ int64 CUtlBuffer::PeekDelimitedStringLength(CUtlCharConversion* pConv, bool bAct
return 0;
// Try to read ending ", but don't accept \"
int64 nActualStart = nOffset;
ssize_t nActualStart = nOffset;
nOffset += pConv->GetDelimiterLength();
int64 nLen = 1; // Starts at 1 for the '\0' termination
ssize_t nLen = 1; // Starts at 1 for the '\0' termination
do
{
@ -700,7 +700,7 @@ int64 CUtlBuffer::PeekDelimitedStringLength(CUtlCharConversion* pConv, bool bAct
++nOffset;
if (c == pConv->GetEscapeChar())
{
int64 nLength = pConv->MaxConversionLength();
ssize_t nLength = pConv->MaxConversionLength();
if (!CheckArbitraryPeekGet(nOffset, nLength))
break;
@ -716,7 +716,7 @@ int64 CUtlBuffer::PeekDelimitedStringLength(CUtlCharConversion* pConv, bool bAct
//-----------------------------------------------------------------------------
// Reads a null-terminated string
//-----------------------------------------------------------------------------
void CUtlBuffer::GetString(char* pString, int64 nMaxChars)
void CUtlBuffer::GetString(char* pString, ssize_t nMaxChars)
{
if (!IsValid())
{
@ -732,7 +732,7 @@ void CUtlBuffer::GetString(char* pString, int64 nMaxChars)
// Remember, this *includes* the null character
// It will be 0, however, if the buffer is empty.
int64 nLen = PeekStringLength();
ssize_t nLen = PeekStringLength();
if (IsText())
{
@ -746,7 +746,7 @@ void CUtlBuffer::GetString(char* pString, int64 nMaxChars)
return;
}
const int64 nCharsToRead = Min(nLen, nMaxChars) - 1;
const ssize_t nCharsToRead = Min(nLen, nMaxChars) - 1;
Get(pString, nCharsToRead);
pString[nCharsToRead] = 0;
@ -767,7 +767,7 @@ void CUtlBuffer::GetString(char* pString, int64 nMaxChars)
//-----------------------------------------------------------------------------
// Reads up to and including the first \n
//-----------------------------------------------------------------------------
void CUtlBuffer::GetLine(char* pLine, int64 nMaxChars)
void CUtlBuffer::GetLine(char* pLine, ssize_t nMaxChars)
{
//Assert( IsText() && !ContainsCRLF() );
@ -784,7 +784,7 @@ void CUtlBuffer::GetLine(char* pLine, int64 nMaxChars)
// Remember, this *includes* the null character
// It will be 0, however, if the buffer is empty.
int64 nLen = PeekLineLength();
ssize_t nLen = PeekLineLength();
if (nLen == 0)
{
*pLine = 0;
@ -816,7 +816,7 @@ char CUtlBuffer::GetDelimitedCharInternal(CUtlCharConversion* pConv)
char c = GetChar();
if (c == pConv->GetEscapeChar())
{
int64 nLength = pConv->MaxConversionLength();
ssize_t nLength = pConv->MaxConversionLength();
if (!CheckArbitraryPeekGet(0, nLength))
return '\0';
@ -834,7 +834,7 @@ char CUtlBuffer::GetDelimitedChar(CUtlCharConversion* pConv)
return GetDelimitedCharInternal(pConv);
}
void CUtlBuffer::GetDelimitedString(CUtlCharConversion* pConv, char* pString, int64 nMaxChars)
void CUtlBuffer::GetDelimitedString(CUtlCharConversion* pConv, char* pString, ssize_t nMaxChars)
{
if (!IsText() || !pConv)
{
@ -860,7 +860,7 @@ void CUtlBuffer::GetDelimitedString(CUtlCharConversion* pConv, char* pString, in
// Pull off the starting delimiter
SeekGet(SEEK_CURRENT, pConv->GetDelimiterLength());
int64 nRead = 0;
ssize_t nRead = 0;
while (IsValid())
{
if (PeekStringMatch(0, pConv->GetDelimiter(), pConv->GetDelimiterLength()))
@ -889,7 +889,7 @@ void CUtlBuffer::GetDelimitedString(CUtlCharConversion* pConv, char* pString, in
//-----------------------------------------------------------------------------
// Checks if a get is ok
//-----------------------------------------------------------------------------
bool CUtlBuffer::CheckGet(int64 nSize)
bool CUtlBuffer::CheckGet(ssize_t nSize)
{
if (m_Error & GET_OVERFLOW)
return false;
@ -916,7 +916,7 @@ bool CUtlBuffer::CheckGet(int64 nSize)
//-----------------------------------------------------------------------------
// Checks if a peek get is ok
//-----------------------------------------------------------------------------
bool CUtlBuffer::CheckPeekGet(int64 nOffset, int64 nSize)
bool CUtlBuffer::CheckPeekGet(ssize_t nOffset, ssize_t nSize)
{
if (m_Error & GET_OVERFLOW)
return false;
@ -932,7 +932,7 @@ bool CUtlBuffer::CheckPeekGet(int64 nOffset, int64 nSize)
// Call this to peek arbitrarily long into memory. It doesn't fail unless
// it can't read *anything* new
//-----------------------------------------------------------------------------
bool CUtlBuffer::CheckArbitraryPeekGet(int64 nOffset, int64& nIncrement)
bool CUtlBuffer::CheckArbitraryPeekGet(ssize_t nOffset, ssize_t& nIncrement)
{
if (TellGet() + nOffset >= TellMaxPut())
{
@ -948,7 +948,7 @@ bool CUtlBuffer::CheckArbitraryPeekGet(int64 nOffset, int64& nIncrement)
// NOTE: CheckPeekGet could modify TellMaxPut for streaming files
// We have to call TellMaxPut again here
CheckPeekGet(nOffset, nIncrement);
int64 nMaxGet = TellMaxPut() - TellGet();
ssize_t nMaxGet = TellMaxPut() - TellGet();
if (nMaxGet < nIncrement)
{
nIncrement = nMaxGet;
@ -960,7 +960,7 @@ bool CUtlBuffer::CheckArbitraryPeekGet(int64 nOffset, int64& nIncrement)
//-----------------------------------------------------------------------------
// Peek part of the butt
//-----------------------------------------------------------------------------
const void* CUtlBuffer::PeekGet(int64 nMaxSize, int64 nOffset)
const void* CUtlBuffer::PeekGet(ssize_t nMaxSize, ssize_t nOffset)
{
if (!CheckPeekGet(nOffset, nMaxSize))
return NULL;
@ -971,7 +971,7 @@ const void* CUtlBuffer::PeekGet(int64 nMaxSize, int64 nOffset)
//-----------------------------------------------------------------------------
// Change where I'm reading
//-----------------------------------------------------------------------------
void CUtlBuffer::SeekGet(SeekType_t type, int64 offset)
void CUtlBuffer::SeekGet(SeekType_t type, ssize_t offset)
{
switch (type)
{
@ -1009,13 +1009,13 @@ void CUtlBuffer::SeekGet(SeekType_t type, int64 offset)
#pragma warning ( disable : 4706 )
int64 CUtlBuffer::VaScanf(const char* pFmt, va_list list)
ssize_t CUtlBuffer::VaScanf(const char* pFmt, va_list list)
{
Assert(pFmt);
if (m_Error || !IsText())
return 0;
int64 numScanned = 0;
ssize_t numScanned = 0;
char c;
while ((c = *pFmt++))
{
@ -1190,12 +1190,12 @@ int64 CUtlBuffer::VaScanf(const char* pFmt, va_list list)
#pragma warning ( default : 4706 )
int64 CUtlBuffer::Scanf(const char* pFmt, ...)
ssize_t CUtlBuffer::Scanf(const char* pFmt, ...)
{
va_list args;
va_start(args, pFmt);
int64 count = VaScanf(pFmt, args);
ssize_t count = VaScanf(pFmt, args);
va_end(args);
return count;
@ -1211,22 +1211,22 @@ bool CUtlBuffer::GetToken(const char* pToken)
Assert(pToken);
// Look for the token
int64 nLen = V_strlen(pToken);
ssize_t nLen = V_strlen(pToken);
// First time through on streaming, check what we already have loaded
// if we have enough loaded to do the check
int64 nMaxSize = Size() - (TellGet() - m_nOffset);
ssize_t nMaxSize = Size() - (TellGet() - m_nOffset);
if (nMaxSize <= nLen)
{
nMaxSize = Size();
}
int64 nSizeRemaining = TellMaxPut() - TellGet();
ssize_t nSizeRemaining = TellMaxPut() - TellGet();
int64 nGet = TellGet();
ssize_t nGet = TellGet();
while (nSizeRemaining >= nLen)
{
bool bOverFlow = (nSizeRemaining > nMaxSize);
int64 nSizeToCheck = bOverFlow ? nMaxSize : nSizeRemaining;
ssize_t nSizeToCheck = bOverFlow ? nMaxSize : nSizeRemaining;
if (!CheckPeekGet(0, nSizeToCheck))
break;
@ -1238,7 +1238,7 @@ bool CUtlBuffer::GetToken(const char* pToken)
// we could be looking for 'foo' for example, and find 'foobar'
// if 'foo' happens to be the last 3 characters of the current window
size_t nOffset = (size_t)pFoundEnd - (size_t)pBufStart;
bool bPotentialMismatch = (bOverFlow && ((int64)nOffset == Size() - nLen));
bool bPotentialMismatch = (bOverFlow && ((ssize_t)nOffset == Size() - nLen));
if (!pFoundEnd || bPotentialMismatch)
{
nSizeRemaining -= nSizeToCheck;
@ -1255,7 +1255,7 @@ bool CUtlBuffer::GetToken(const char* pToken)
}
// Seek past the end of the found string
SeekGet(CUtlBuffer::SEEK_CURRENT, (int64)(nOffset + nLen));
SeekGet(CUtlBuffer::SEEK_CURRENT, (ssize_t)(nOffset + nLen));
return true;
}
@ -1274,10 +1274,10 @@ bool CUtlBuffer::GetToken(const char* pToken)
// If successful, the get index is advanced and the function returns true,
// otherwise the index is not advanced and the function returns false.
//-----------------------------------------------------------------------------
bool CUtlBuffer::ParseToken(const char* pStartingDelim, const char* pEndingDelim, char* pString, int64 nMaxLen)
bool CUtlBuffer::ParseToken(const char* pStartingDelim, const char* pEndingDelim, char* pString, ssize_t nMaxLen)
{
int64 nCharsToCopy = 0;
int64 nCurrentGet = 0;
ssize_t nCharsToCopy = 0;
ssize_t nCurrentGet = 0;
size_t nEndingDelimLen;
@ -1292,8 +1292,8 @@ bool CUtlBuffer::ParseToken(const char* pStartingDelim, const char* pEndingDelim
Assert(pEndingDelim && pEndingDelim[0]);
nEndingDelimLen = V_strlen(pEndingDelim);
int64 nStartGet = TellGet();
int64 nTokenStart = -1;
ssize_t nStartGet = TellGet();
ssize_t nTokenStart = -1;
char nCurrChar;
EatWhiteSpace();
while (*pStartingDelim)
@ -1353,7 +1353,7 @@ parseFailed:
//-----------------------------------------------------------------------------
// Parses the next token, given a set of character breaks to stop at
//-----------------------------------------------------------------------------
int64 CUtlBuffer::ParseToken(characterset_t* pBreaks, char* pTokenBuf, int64 nMaxLen, bool bParseComments)
ssize_t CUtlBuffer::ParseToken(characterset_t* pBreaks, char* pTokenBuf, ssize_t nMaxLen, bool bParseComments)
{
Assert(nMaxLen > 0);
pTokenBuf[0] = 0;
@ -1384,7 +1384,7 @@ int64 CUtlBuffer::ParseToken(characterset_t* pBreaks, char* pTokenBuf, int64 nMa
// handle quoted strings specially
if (c == '\"')
{
int64 nLen = 0;
ssize_t nLen = 0;
while (IsValid())
{
c = GetChar();
@ -1415,7 +1415,7 @@ int64 CUtlBuffer::ParseToken(characterset_t* pBreaks, char* pTokenBuf, int64 nMa
}
// parse a regular word
int64 nLen = 0;
ssize_t nLen = 0;
while (true)
{
pTokenBuf[nLen] = c;
@ -1444,7 +1444,7 @@ int64 CUtlBuffer::ParseToken(characterset_t* pBreaks, char* pTokenBuf, int64 nMa
//-----------------------------------------------------------------------------
// Serialization
//-----------------------------------------------------------------------------
void CUtlBuffer::Put(const void* pMem, int64 size)
void CUtlBuffer::Put(const void* pMem, ssize_t size)
{
if (size && CheckPut(size))
{
@ -1466,7 +1466,7 @@ void CUtlBuffer::PutString(const char* pString)
if (pString)
{
// Not text? append a null at the end.
int64 nLen = V_strlen(pString) + 1;
ssize_t nLen = V_strlen(pString) + 1;
Put(pString, nLen * sizeof(char));
return;
}
@ -1477,7 +1477,7 @@ void CUtlBuffer::PutString(const char* pString)
}
else if (pString)
{
int64 nTabCount = (m_Flags & AUTO_TABS_DISABLED) ? 0 : m_nTab;
ssize_t nTabCount = (m_Flags & AUTO_TABS_DISABLED) ? 0 : m_nTab;
if (nTabCount > 0)
{
if (WasLastCharacterCR())
@ -1502,7 +1502,7 @@ void CUtlBuffer::PutString(const char* pString)
}
}
}
int64 nLen = V_strlen(pString);
ssize_t nLen = V_strlen(pString);
if (nLen)
{
Put(pString, nLen * sizeof(char));
@ -1517,7 +1517,7 @@ void CUtlBuffer::PutString(const char* pString)
//-----------------------------------------------------------------------------
inline void CUtlBuffer::PutDelimitedCharInternal(CUtlCharConversion* pConv, char c)
{
int64 l = pConv->GetConversionLength(c);
ssize_t l = pConv->GetConversionLength(c);
if (l == 0)
{
PutChar(c);
@ -1571,7 +1571,7 @@ void CUtlBuffer::PutDelimitedString(CUtlCharConversion* pConv, const char* pStri
void CUtlBuffer::VaPrintf(const char* pFmt, va_list list)
{
char temp[8192];
//int64 nLen = V_vsnprintf(temp, sizeof(temp), pFmt, list);
//ssize_t nLen = V_vsnprintf(temp, sizeof(temp), pFmt, list);
//ErrorIfNot(nLen < sizeof(temp), ("CUtlBuffer::VaPrintf: String overflowed buffer [%d]\n", sizeof(temp)));
PutString(temp);
}
@ -1599,12 +1599,12 @@ void CUtlBuffer::SetOverflowFuncs(UtlBufferOverflowFunc_t getFunc, UtlBufferOver
//-----------------------------------------------------------------------------
// Calls the overflow functions
//-----------------------------------------------------------------------------
bool CUtlBuffer::OnPutOverflow(int64 nSize)
bool CUtlBuffer::OnPutOverflow(ssize_t nSize)
{
return (this->*m_PutOverflowFunc)(nSize);
}
bool CUtlBuffer::OnGetOverflow(int64 nSize)
bool CUtlBuffer::OnGetOverflow(ssize_t nSize)
{
return (this->*m_GetOverflowFunc)(nSize);
}
@ -1613,7 +1613,7 @@ bool CUtlBuffer::OnGetOverflow(int64 nSize)
//-----------------------------------------------------------------------------
// Checks if a put is ok
//-----------------------------------------------------------------------------
bool CUtlBuffer::PutOverflow(int64 nSize)
bool CUtlBuffer::PutOverflow(ssize_t nSize)
{
//MEM_ALLOC_CREDIT();
@ -1633,7 +1633,7 @@ bool CUtlBuffer::PutOverflow(int64 nSize)
return true;
}
bool CUtlBuffer::GetOverflow(int64 nSize)
bool CUtlBuffer::GetOverflow(ssize_t nSize)
{
return false;
}
@ -1642,7 +1642,7 @@ bool CUtlBuffer::GetOverflow(int64 nSize)
//-----------------------------------------------------------------------------
// Checks if a put is ok
//-----------------------------------------------------------------------------
bool CUtlBuffer::CheckPut(int64 nSize)
bool CUtlBuffer::CheckPut(ssize_t nSize)
{
if ((m_Error & PUT_OVERFLOW) || IsReadOnly())
return false;
@ -1658,9 +1658,9 @@ bool CUtlBuffer::CheckPut(int64 nSize)
return true;
}
void CUtlBuffer::SeekPut(SeekType_t type, int64 offset)
void CUtlBuffer::SeekPut(SeekType_t type, ssize_t offset)
{
int64 nNextPut = m_Put;
ssize_t nNextPut = m_Put;
switch (type)
{
case SEEK_HEAD:
@ -1709,7 +1709,7 @@ bool CUtlBuffer::IsBigEndian(void)
// NOTE: Pass in nPut here even though it is just a copy of m_Put. This is almost always called immediately
// after modifying m_Put and this lets it stay in a register and avoid LHS on PPC.
//-----------------------------------------------------------------------------
void CUtlBuffer::AddNullTermination(int64 nPut)
void CUtlBuffer::AddNullTermination(ssize_t nPut)
{
if (nPut > m_nMaxPut)
{
@ -1744,7 +1744,7 @@ bool CUtlBuffer::ConvertCRLF(CUtlBuffer& outBuf)
if (ContainsCRLF() == outBuf.ContainsCRLF())
return false;
int64 nInCount = TellMaxPut();
ssize_t nInCount = TellMaxPut();
outBuf.Purge();
outBuf.EnsureCapacity(nInCount);
@ -1752,10 +1752,10 @@ bool CUtlBuffer::ConvertCRLF(CUtlBuffer& outBuf)
bool bFromCRLF = ContainsCRLF();
// Start reading from the beginning
int64 nGet = TellGet();
int64 nPut = TellPut();
int64 nGetDelta = 0;
int64 nPutDelta = 0;
ssize_t nGet = TellGet();
ssize_t nPut = TellPut();
ssize_t nGetDelta = 0;
ssize_t nPutDelta = 0;
const char* pBase = (const char*)Base();
intptr_t nCurrGet = 0;
@ -1764,7 +1764,7 @@ bool CUtlBuffer::ConvertCRLF(CUtlBuffer& outBuf)
const char* pCurr = &pBase[nCurrGet];
if (bFromCRLF)
{
const char* pNext = V_strnistr(pCurr, "\r\n", (int64)nInCount - (int64)nCurrGet);
const char* pNext = V_strnistr(pCurr, "\r\n", (ssize_t)nInCount - (ssize_t)nCurrGet);
if (!pNext)
{
outBuf.Put(pCurr, nInCount - nCurrGet);
@ -1786,15 +1786,15 @@ bool CUtlBuffer::ConvertCRLF(CUtlBuffer& outBuf)
}
else
{
const char* pNext = V_strnchr(pCurr, '\n', (int64)nInCount - (int64)nCurrGet);
const char* pNext = V_strnchr(pCurr, '\n', (ssize_t)nInCount - (ssize_t)nCurrGet);
if (!pNext)
{
outBuf.Put(pCurr, (int64)nInCount - (int64)nCurrGet);
outBuf.Put(pCurr, (ssize_t)nInCount - (ssize_t)nCurrGet);
break;
}
intptr_t nBytes = (intptr_t)pNext - (intptr_t)pCurr;
outBuf.Put(pCurr, (int64)nBytes);
outBuf.Put(pCurr, (ssize_t)nBytes);
outBuf.PutChar('\r');
outBuf.PutChar('\n');
nCurrGet += nBytes + 1;
@ -1846,16 +1846,16 @@ void CUtlBuffer::Swap(CUtlMemory<uint8>& mem)
// Implementation of CUtlInplaceBuffer
//---------------------------------------------------------------------------
CUtlInplaceBuffer::CUtlInplaceBuffer(int64 growSize /* = 0 */, int64 initSize /* = 0 */, int nFlags /* = 0 */) :
CUtlInplaceBuffer::CUtlInplaceBuffer(ssize_t growSize /* = 0 */, ssize_t initSize /* = 0 */, int nFlags /* = 0 */) :
CUtlBuffer(growSize, initSize, nFlags)
{
}
bool CUtlInplaceBuffer::InplaceGetLinePtr(char** ppszInBufferPtr, int64* pnLineLength)
bool CUtlInplaceBuffer::InplaceGetLinePtr(char** ppszInBufferPtr, ssize_t* pnLineLength)
{
Assert(IsText() && !ContainsCRLF());
int64 nLineLen = PeekLineLength();
ssize_t nLineLen = PeekLineLength();
if (nLineLen <= 1)
{
SeekGet(SEEK_TAIL, 0);
@ -1880,7 +1880,7 @@ bool CUtlInplaceBuffer::InplaceGetLinePtr(char** ppszInBufferPtr, int64* pnLineL
char* CUtlInplaceBuffer::InplaceGetLinePtr(void)
{
char* pszLine = NULL;
int64 nLineLen = 0;
ssize_t nLineLen = 0;
if (InplaceGetLinePtr(&pszLine, &nLineLen))
{

View File

@ -65,7 +65,7 @@ int V_vscprintf(const char *format, va_list params)
//-----------------------------------------------------------------------------
// Base class, containing simple memory management
//-----------------------------------------------------------------------------
CUtlBinaryBlock::CUtlBinaryBlock( int64 growSize, int64 initSize )
CUtlBinaryBlock::CUtlBinaryBlock( ssize_t growSize, ssize_t initSize )
{
//MEM_ALLOC_CREDIT();
m_Memory.Init( growSize, initSize );
@ -73,12 +73,12 @@ CUtlBinaryBlock::CUtlBinaryBlock( int64 growSize, int64 initSize )
m_nActualLength = 0;
}
CUtlBinaryBlock::CUtlBinaryBlock( void* pMemory, int64 nSizeInBytes, int64 nInitialLength ) : m_Memory( (unsigned char*)pMemory, nSizeInBytes )
CUtlBinaryBlock::CUtlBinaryBlock( void* pMemory, ssize_t nSizeInBytes, ssize_t nInitialLength ) : m_Memory( (unsigned char*)pMemory, nSizeInBytes )
{
m_nActualLength = nInitialLength;
}
CUtlBinaryBlock::CUtlBinaryBlock( const void* pMemory, int64 nSizeInBytes ) : m_Memory( (const unsigned char*)pMemory, nSizeInBytes )
CUtlBinaryBlock::CUtlBinaryBlock( const void* pMemory, ssize_t nSizeInBytes ) : m_Memory( (const unsigned char*)pMemory, nSizeInBytes )
{
m_nActualLength = nSizeInBytes;
}
@ -88,7 +88,7 @@ CUtlBinaryBlock::CUtlBinaryBlock( const CUtlBinaryBlock& src )
Set( src.Get(), src.Length() );
}
void CUtlBinaryBlock::Get( void *pValue, int64 nLen ) const
void CUtlBinaryBlock::Get( void *pValue, ssize_t nLen ) const
{
Assert( nLen > 0 );
if ( m_nActualLength < nLen )
@ -102,7 +102,7 @@ void CUtlBinaryBlock::Get( void *pValue, int64 nLen ) const
}
}
void CUtlBinaryBlock::SetLength( int64 nLength )
void CUtlBinaryBlock::SetLength( ssize_t nLength )
{
//MEM_ALLOC_CREDIT();
Assert( !m_Memory.IsReadOnly() );
@ -110,7 +110,7 @@ void CUtlBinaryBlock::SetLength( int64 nLength )
m_nActualLength = nLength;
if ( nLength > m_Memory.NumAllocated() )
{
int64 nOverFlow = nLength - m_Memory.NumAllocated();
ssize_t nOverFlow = nLength - m_Memory.NumAllocated();
m_Memory.Grow( nOverFlow );
// If the reallocation failed, clamp length
@ -129,7 +129,7 @@ void CUtlBinaryBlock::SetLength( int64 nLength )
}
void CUtlBinaryBlock::Set( const void *pValue, int64 nLen )
void CUtlBinaryBlock::Set( const void *pValue, ssize_t nLen )
{
Assert( !m_Memory.IsReadOnly() );
@ -190,11 +190,11 @@ CUtlString::CUtlString( const CUtlString& string )
}
// Attaches the string to external memory. Useful for avoiding a copy
CUtlString::CUtlString( void* pMemory, int64 nSizeInBytes, int64 nInitialLength ) : m_Storage( pMemory, nSizeInBytes, nInitialLength )
CUtlString::CUtlString( void* pMemory, ssize_t nSizeInBytes, ssize_t nInitialLength ) : m_Storage( pMemory, nSizeInBytes, nInitialLength )
{
}
CUtlString::CUtlString( const void* pMemory, int64 nSizeInBytes ) : m_Storage( pMemory, nSizeInBytes )
CUtlString::CUtlString( const void* pMemory, ssize_t nSizeInBytes ) : m_Storage( pMemory, nSizeInBytes )
{
}
@ -202,7 +202,7 @@ CUtlString::CUtlString( const void* pMemory, int64 nSizeInBytes ) : m_Storage( p
//-----------------------------------------------------------------------------
// Purpose: Set directly and don't look for a null terminator in pValue.
//-----------------------------------------------------------------------------
void CUtlString::SetDirect( const char *pValue, int64 nChars )
void CUtlString::SetDirect( const char *pValue, ssize_t nChars )
{
if ( nChars > 0 )
{
@ -220,19 +220,19 @@ void CUtlString::SetDirect( const char *pValue, int64 nChars )
void CUtlString::Set( const char *pValue )
{
Assert( !m_Storage.IsReadOnly() );
int64 nLen = pValue ? Q_strlen(pValue) + 1 : 0;
ssize_t nLen = pValue ? Q_strlen(pValue) + 1 : 0;
m_Storage.Set( pValue, nLen );
}
// Returns strlen
int64 CUtlString::Length() const
ssize_t CUtlString::Length() const
{
return m_Storage.Length() ? m_Storage.Length() - 1 : 0;
}
// Sets the length (used to serialize into the buffer )
void CUtlString::SetLength( int64 nLen )
void CUtlString::SetLength( ssize_t nLen )
{
Assert( !m_Storage.IsReadOnly() );
@ -278,7 +278,7 @@ void CUtlString::Purge()
void CUtlString::ToUpper()
{
for ( int64 nLength = Length() - 1; nLength >= 0; nLength--)
for ( ssize_t nLength = Length() - 1; nLength >= 0; nLength--)
{
m_Storage[nLength] = (unsigned char)toupper( m_Storage[ nLength ] );
}
@ -286,7 +286,7 @@ void CUtlString::ToUpper()
void CUtlString::ToLower()
{
for( int64 nLength = Length() - 1; nLength >= 0; nLength-- )
for( ssize_t nLength = Length() - 1; nLength >= 0; nLength-- )
{
m_Storage[ nLength ] = (unsigned char)tolower( m_Storage[ nLength ] );
}
@ -321,13 +321,13 @@ CUtlString &CUtlString::operator+=( const CUtlString &rhs )
{
Assert( !m_Storage.IsReadOnly() );
const int64 lhsLength( Length() );
const int64 rhsLength( rhs.Length() );
const int64 requestedLength( lhsLength + rhsLength );
const ssize_t lhsLength( Length() );
const ssize_t rhsLength( rhs.Length() );
const ssize_t requestedLength( lhsLength + rhsLength );
SetLength( requestedLength );
const int64 allocatedLength( Length() );
const int64 copyLength( allocatedLength - lhsLength < rhsLength ? allocatedLength - lhsLength : rhsLength );
const ssize_t allocatedLength( Length() );
const ssize_t copyLength( allocatedLength - lhsLength < rhsLength ? allocatedLength - lhsLength : rhsLength );
memcpy( Get() + lhsLength, rhs.Get(), copyLength );
m_Storage[ allocatedLength ] = '\0';
@ -338,13 +338,13 @@ CUtlString &CUtlString::operator+=( const char *rhs )
{
Assert( !m_Storage.IsReadOnly() );
const int64 lhsLength( Length() );
const int64 rhsLength( Q_strlen( rhs ) );
const int64 requestedLength( lhsLength + rhsLength );
const ssize_t lhsLength( Length() );
const ssize_t rhsLength( Q_strlen( rhs ) );
const ssize_t requestedLength( lhsLength + rhsLength );
SetLength( requestedLength );
const int64 allocatedLength( Length() );
const int64 copyLength( allocatedLength - lhsLength < rhsLength ? allocatedLength - lhsLength : rhsLength );
const ssize_t allocatedLength( Length() );
const ssize_t copyLength( allocatedLength - lhsLength < rhsLength ? allocatedLength - lhsLength : rhsLength );
memcpy( Get() + lhsLength, rhs, copyLength );
m_Storage[ allocatedLength ] = '\0';
@ -355,14 +355,14 @@ CUtlString &CUtlString::operator+=( char c )
{
Assert( !m_Storage.IsReadOnly() );
int64 nLength = Length();
ssize_t nLength = Length();
SetLength( nLength + 1 );
m_Storage[ nLength ] = c;
m_Storage[ nLength+1 ] = '\0';
return *this;
}
CUtlString &CUtlString::operator+=( int64 rhs )
CUtlString &CUtlString::operator+=( ssize_t rhs )
{
Assert( !m_Storage.IsReadOnly() );
Assert( sizeof( rhs ) == 4 );
@ -428,7 +428,7 @@ void CUtlString::StripTrailingSlash()
if ( IsEmpty() )
return;
int64 nLastChar = Length() - 1;
ssize_t nLastChar = Length() - 1;
char c = m_Storage[ nLastChar ];
if ( PATHSEPARATOR( c ) )
@ -444,7 +444,7 @@ ptrdiff_t CUtlString::Find(const char* szTarget) const
return IndexOf( szTarget, Get() );
}
CUtlString CUtlString::Slice( int64 nStart, int64 nEnd )
CUtlString CUtlString::Slice( ssize_t nStart, ssize_t nEnd )
{
if ( nStart < 0 )
nStart = Length() - (-nStart % Length());
@ -474,12 +474,12 @@ CUtlString CUtlString::Slice( int64 nStart, int64 nEnd )
}
// Grab a substring starting from the left or the right side.
CUtlString CUtlString::Left( int64 nChars )
CUtlString CUtlString::Left( ssize_t nChars )
{
return Slice( 0, nChars );
}
CUtlString CUtlString::Right( int64 nChars )
CUtlString CUtlString::Right( ssize_t nChars )
{
return Slice( -nChars );
}
@ -489,7 +489,7 @@ CUtlString CUtlString::Right( int64 nChars )
CUtlString CUtlString::Remove( char const *pTextToRemove, bool bCaseSensitive ) const
{
int64 nTextToRemoveLength = pTextToRemove ? V_strlen( pTextToRemove ) : 0;
ssize_t nTextToRemoveLength = pTextToRemove ? V_strlen( pTextToRemove ) : 0;
CUtlString outputString;
const char *pSrc = Get();
if ( pSrc )
@ -504,7 +504,7 @@ CUtlString CUtlString::Remove( char const *pTextToRemove, bool bCaseSensitive )
break;
}
int64 nNumCharsToCopy = pNextOccurrence - pSrc;
ssize_t nNumCharsToCopy = pNextOccurrence - pSrc;
if ( nNumCharsToCopy )
{
// append up to the undesired substring
@ -528,7 +528,7 @@ CUtlString CUtlString::Replace( char const *pchFrom, const char *pchTo, bool bCa
return Remove( pchFrom, bCaseSensitive );
}
int64 nTextToReplaceLength = pchFrom ? V_strlen( pchFrom ) : 0;
ssize_t nTextToReplaceLength = pchFrom ? V_strlen( pchFrom ) : 0;
CUtlString outputString;
const char *pSrc = Get();
if ( pSrc )
@ -543,7 +543,7 @@ CUtlString CUtlString::Replace( char const *pchFrom, const char *pchTo, bool bCa
break;
}
int64 nNumCharsToCopy = pNextOccurrence - pSrc;
ssize_t nNumCharsToCopy = pNextOccurrence - pSrc;
if ( nNumCharsToCopy )
{
// append up to the undesired substring
@ -569,8 +569,8 @@ CUtlString CUtlString::Replace( char const *pchFrom, const char *pchTo, bool bCa
CUtlString CUtlString::Replace( char cFrom, char cTo )
{
CUtlString ret = *this;
int64 len = ret.Length();
for ( int64 i=0; i < len; i++ )
ssize_t len = ret.Length();
for ( ssize_t i=0; i < len; i++ )
{
if ( ret.m_Storage[i] == cFrom )
ret.m_Storage[i] = cTo;
@ -628,7 +628,7 @@ CUtlString CUtlString::StripExtension() const
CUtlString CUtlString::StripFilename( bool bStripTrailingSlash ) const
{
const char *pFilename = V_UnqualifiedFileName( Get() ); // NOTE: returns 'Get()' on failure, never NULL
int64 nCharsToCopy = pFilename - Get();
ssize_t nCharsToCopy = pFilename - Get();
CUtlString result;
result.SetDirect( Get(), nCharsToCopy );
@ -669,9 +669,9 @@ void CUtlString::Append( const char *pchAddition )
(*this) += pchAddition;
}
void CUtlString::Append(const char *pchAddition, int64 nMaxChars)
void CUtlString::Append(const char *pchAddition, ssize_t nMaxChars)
{
const int64 nLen = V_strlen(pchAddition);
const ssize_t nLen = V_strlen(pchAddition);
if (nMaxChars < 0 || nLen <= nMaxChars)
{
Append(pchAddition);
@ -730,8 +730,8 @@ void CUtlString::TrimLeft( const char *szTargets )
void CUtlString::TrimRight( const char *szTargets )
{
const int64 nLastCharIndex = Length() - 1;
int64 i;
const ssize_t nLastCharIndex = Length() - 1;
ssize_t i;
char* pSrc = Get();
@ -1103,7 +1103,7 @@ size_t CUtlStringBuilder::TrimWhitespace()
return 0;
char *pchString = m_data.Access();
int64 cChars = V_StrTrim(pchString);
ssize_t cChars = V_StrTrim(pchString);
if (cChars)
m_data.SetLength(cChars);

View File

@ -312,7 +312,7 @@ void CPackedStore::BuildManifest(const CUtlVector<VPKEntryBlock_t>& entryBlocks,
CUtlString outPath;
outPath.Format("%s%s%s.txt", workspacePath.Get(), "manifest/", manifestName.Get());
CUtlBuffer outBuf(int64_t(0), 0, CUtlBuffer::TEXT_BUFFER);
CUtlBuffer outBuf(ssize_t(0), 0, CUtlBuffer::TEXT_BUFFER);
kv.RecursiveSaveToFile(outBuf, 0);
FileSystem()->CreateDirHierarchy(outPath.DirName().Get(), "PLATFORM");