init
This commit is contained in:
17
public/tier1/commandline.h
Normal file
17
public/tier1/commandline.h
Normal file
@@ -0,0 +1,17 @@
|
||||
#include "tier0/platform.h"
|
||||
|
||||
interface ICommandLine
|
||||
{
|
||||
public:
|
||||
static void CreateCommandLine( int argc, char **argv );
|
||||
|
||||
static bool CheckParam( char *psz );
|
||||
static char *ParamValue( const char* psz );
|
||||
|
||||
static void AddParam( char *psz );
|
||||
static void RemoveParam( char *psz );
|
||||
|
||||
static int ParamCount();
|
||||
static int FindParam( const char *psz );
|
||||
static const char *GetParam(int nIndex);
|
||||
};
|
||||
350
public/tier1/utlbuffer.h
Normal file
350
public/tier1/utlbuffer.h
Normal file
@@ -0,0 +1,350 @@
|
||||
#ifndef TIER1_UTL_BUFFER_H
|
||||
#define TIER1_UTL_BUFFER_H
|
||||
|
||||
|
||||
#include "tier0/mem.h"
|
||||
#include "tier0/platform.h"
|
||||
#include "tier0/lib.h"
|
||||
|
||||
template <typename T>
|
||||
class CUtlBuffer;
|
||||
template <typename T>
|
||||
class CUtlResizableBuffer;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// This buffer contains static data allocated on heap.
|
||||
//-----------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
class CUtlBuffer
|
||||
{
|
||||
public:
|
||||
CUtlBuffer( void );
|
||||
CUtlBuffer( size_t nSize );
|
||||
CUtlBuffer( const CUtlBuffer<T>& buffer );
|
||||
CUtlBuffer( const CUtlResizableBuffer<T>& buffer );
|
||||
|
||||
size_t GetSize( void ) const;
|
||||
void* GetMemory(void) const;
|
||||
|
||||
operator T*( void ) const;
|
||||
T& operator []( const size_t nIndex );
|
||||
T operator []( const size_t nIndex ) const;
|
||||
CUtlBuffer<T>& operator=(const CUtlBuffer<T>& other);
|
||||
private:
|
||||
T* m_pData;
|
||||
size_t m_nSize;
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Constructor.
|
||||
//-----------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
CUtlBuffer<T>::CUtlBuffer() : m_nSize(0)
|
||||
{
|
||||
m_pData = 0;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Constructor.
|
||||
//-----------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
CUtlBuffer<T>::CUtlBuffer( size_t nSize ) : m_nSize(nSize)
|
||||
{
|
||||
if ( nSize == 0 )
|
||||
nSize = 1;
|
||||
m_pData = (T*)V_malloc(sizeof(T)*nSize);
|
||||
V_memset(m_pData, 0, sizeof(T)*nSize);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Constructor.
|
||||
//-----------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
CUtlBuffer<T>::CUtlBuffer( const CUtlBuffer<T>& buffer ) : m_nSize(buffer.m_nSize)
|
||||
{
|
||||
m_pData = (T*)V_malloc(sizeof(T)*buffer.m_nSize);
|
||||
V_memcpy(m_pData,buffer.m_pData,sizeof(T)*buffer.m_nSize);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Constructor.
|
||||
//-----------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
CUtlBuffer<T>::CUtlBuffer( const CUtlResizableBuffer<T>& buffer ) : m_nSize(buffer.m_nSize)
|
||||
{
|
||||
m_pData = (T*)V_malloc(sizeof(T)*buffer.nSize);
|
||||
V_memcpy(m_pData,buffer.pData,sizeof(T)*buffer.nSize);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Gets memory size.
|
||||
//-----------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
size_t CUtlBuffer<T>::GetSize( void ) const
|
||||
{
|
||||
return m_nSize;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Gets memory address.
|
||||
//-----------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
void* CUtlBuffer<T>::GetMemory( void ) const
|
||||
{
|
||||
return m_pData;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Gets memory address using casting.
|
||||
//-----------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
CUtlBuffer<T>::operator T*( void ) const
|
||||
{
|
||||
return m_pData;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Indexes buffer for writing.
|
||||
//-----------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
T& CUtlBuffer<T>::operator []( const size_t nIndex )
|
||||
{
|
||||
if ( m_pData == 0)
|
||||
Plat_FatalErrorFunc("Buffer was not initialized");
|
||||
|
||||
if ( nIndex >= m_nSize )
|
||||
Plat_FatalErrorFunc("Out of bounds indexing: size is %lu and index is %lu", m_nSize/sizeof(T), nIndex);
|
||||
|
||||
return m_pData[nIndex];
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Indexes buffer for reading.
|
||||
//-----------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
T CUtlBuffer<T>::operator []( const size_t nIndex ) const
|
||||
{
|
||||
if ( nIndex >= m_nSize )
|
||||
Plat_FatalErrorFunc("Out of bounds indexing: size is %lu and index is %lu",m_nSize, nIndex);
|
||||
return m_pData[nIndex];
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Assigns buffer.
|
||||
//-----------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
CUtlBuffer<T>& CUtlBuffer<T>::operator=(const CUtlBuffer<T>& other)
|
||||
{
|
||||
if ( this != &other )
|
||||
{
|
||||
if ( m_pData != 0)
|
||||
V_free(m_pData);
|
||||
m_pData = (T*)V_malloc(sizeof(T)*other.m_nSize);
|
||||
V_memcpy(m_pData, other.m_pData, sizeof(T)*other.m_nSize);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// This buffer contains static data allocated on heap which can be resized.
|
||||
//-----------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
class CUtlResizableBuffer
|
||||
{
|
||||
public:
|
||||
CUtlResizableBuffer( void );
|
||||
CUtlResizableBuffer( size_t nSize );
|
||||
CUtlResizableBuffer( const CUtlBuffer<T>& buffer );
|
||||
CUtlResizableBuffer( const CUtlResizableBuffer<T>& buffer );
|
||||
|
||||
size_t GetSize() const;
|
||||
size_t GetRealSize() const;
|
||||
void Resize( size_t nSize );
|
||||
void* GetMemory(void) const;
|
||||
|
||||
operator T*( void ) const;
|
||||
T& operator []( const size_t nIndex );
|
||||
T operator []( const size_t nIndex ) const;
|
||||
CUtlResizableBuffer<T>& operator=(const CUtlResizableBuffer<T>& other);
|
||||
private:
|
||||
size_t CalculateMemorySize(size_t nSize);
|
||||
T* m_pData;
|
||||
size_t m_nSize;
|
||||
size_t m_nAllocatedSize;
|
||||
};
|
||||
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Constructor.
|
||||
//-----------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
CUtlResizableBuffer<T>::CUtlResizableBuffer() : m_nSize(1)
|
||||
{
|
||||
m_pData = (T*)V_malloc(1);
|
||||
m_nAllocatedSize = 1;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Constructor.
|
||||
//-----------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
CUtlResizableBuffer<T>::CUtlResizableBuffer( size_t nSize ) : m_nSize(nSize)
|
||||
{
|
||||
if ( nSize == 0 )
|
||||
nSize = 1;
|
||||
size_t nAllocSize = CalculateMemorySize(sizeof(T)*nSize);
|
||||
m_pData = (T*)V_malloc(nAllocSize);
|
||||
m_nAllocatedSize = nAllocSize;
|
||||
V_memset(m_pData, 0, sizeof(T)*nSize);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Constructor.
|
||||
//-----------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
CUtlResizableBuffer<T>::CUtlResizableBuffer( const CUtlBuffer<T>& buffer ) : m_nSize(buffer.nSize)
|
||||
{
|
||||
size_t nAllocSize = CalculateMemorySize(sizeof(T)*buffer.nSize);
|
||||
m_pData = (T*)V_malloc(nAllocSize);
|
||||
m_nAllocatedSize = nAllocSize;
|
||||
V_memcpy(m_pData,buffer.m_pData,sizeof(T)*buffer.nSize);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Constructor.
|
||||
//-----------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
CUtlResizableBuffer<T>::CUtlResizableBuffer( const CUtlResizableBuffer<T>& buffer ) : m_nSize(buffer.m_nSize)
|
||||
{
|
||||
m_pData = (T*)V_malloc(sizeof(T)*buffer.m_nAllocatedSize);
|
||||
m_nAllocatedSize = buffer.m_nAllocatedSize;
|
||||
V_memcpy(m_pData,buffer.m_pData,sizeof(T)*buffer.m_nSize);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Gets memory size.
|
||||
//-----------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
size_t CUtlResizableBuffer<T>::GetSize( void ) const
|
||||
{
|
||||
return m_nSize;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Gets memory size.
|
||||
//-----------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
size_t CUtlResizableBuffer<T>::GetRealSize( void ) const
|
||||
{
|
||||
return m_nAllocatedSize;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Resizes memory.
|
||||
//-----------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
void CUtlResizableBuffer<T>::Resize( size_t nSize )
|
||||
{
|
||||
if ( nSize == 0 )
|
||||
nSize = 1;
|
||||
|
||||
|
||||
if ( m_pData == 0 )
|
||||
m_pData = (T*)V_malloc(CalculateMemorySize(sizeof(T)*nSize));
|
||||
else
|
||||
{
|
||||
size_t nAllocSize = CalculateMemorySize(sizeof(T)*nSize);
|
||||
if (nAllocSize!=m_nAllocatedSize)
|
||||
{
|
||||
// not ideal
|
||||
T* pData = (T*)V_malloc(nAllocSize);
|
||||
V_memcpy(pData, m_pData, m_nAllocatedSize>nAllocSize ? nAllocSize : m_nAllocatedSize );
|
||||
m_nAllocatedSize = nAllocSize;
|
||||
V_free(m_pData);
|
||||
m_pData = pData;
|
||||
}
|
||||
}
|
||||
m_nSize = nSize;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Gets memory address.
|
||||
//-----------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
void* CUtlResizableBuffer<T>::GetMemory( void ) const
|
||||
{
|
||||
return m_pData;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Gets memory address using casting.
|
||||
//-----------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
CUtlResizableBuffer<T>::operator T*( void ) const
|
||||
{
|
||||
return m_pData;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Indexes buffer for writing.
|
||||
//-----------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
T& CUtlResizableBuffer<T>::operator []( const size_t nIndex )
|
||||
{
|
||||
if ( m_pData == 0)
|
||||
Plat_FatalErrorFunc("Buffer was not initialized");
|
||||
|
||||
if ( nIndex >= m_nSize )
|
||||
Plat_FatalErrorFunc("Out of bounds indexing: size is %lu and index is %lu",m_nSize, nIndex);
|
||||
|
||||
return m_pData[nIndex];
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Indexes buffer for reading.
|
||||
//-----------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
T CUtlResizableBuffer<T>::operator []( const size_t nIndex ) const
|
||||
{
|
||||
if ( nIndex >= m_nSize )
|
||||
Plat_FatalErrorFunc("Out of bounds indexing: size is %lu and index is %lu",m_nSize, nIndex);
|
||||
return m_pData[nIndex];
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Assigns buffer.
|
||||
//-----------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
CUtlResizableBuffer<T>& CUtlResizableBuffer<T>::operator=(const CUtlResizableBuffer<T>& other)
|
||||
{
|
||||
if ( this != &other )
|
||||
{
|
||||
V_free(m_pData);
|
||||
m_pData = (T*)V_malloc(other.m_nAllocatedSize);
|
||||
V_memcpy(m_pData, other.m_pData, sizeof(T)*other.m_nSize);
|
||||
m_nAllocatedSize = other.m_nAllocatedSize;
|
||||
m_nSize = other.m_nSize;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Calculates memory size that is
|
||||
//-----------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
size_t CUtlResizableBuffer<T>::CalculateMemorySize(size_t nSize)
|
||||
{
|
||||
size_t x = nSize;
|
||||
if (x == 0) return 1;
|
||||
x--;
|
||||
x |= x >> 1;
|
||||
x |= x >> 2;
|
||||
x |= x >> 4;
|
||||
x |= x >> 8;
|
||||
x |= x >> 16;
|
||||
x |= x >> 32;
|
||||
return x + 1;
|
||||
}
|
||||
|
||||
#endif
|
||||
6
public/tier1/utlmap.h
Normal file
6
public/tier1/utlmap.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#ifndef TIER1_UTL_STRING_H
|
||||
#define TIER1_UTL_STRING_H
|
||||
|
||||
#include "tier1/utlvector.h"
|
||||
|
||||
#endif
|
||||
30
public/tier1/utlstring.h
Normal file
30
public/tier1/utlstring.h
Normal file
@@ -0,0 +1,30 @@
|
||||
#ifndef TIER1_UTL_STRING_H
|
||||
#define TIER1_UTL_STRING_H
|
||||
|
||||
#include "tier1/utlvector.h"
|
||||
|
||||
class CUtlString {
|
||||
public:
|
||||
CUtlString( void );
|
||||
CUtlString( const char *psz, ... );
|
||||
|
||||
void AppendTail( const char *psz );
|
||||
void AppendHead( const char *psz );
|
||||
void AppendAt( size_t nPosition, const char *psz );
|
||||
|
||||
void RemoveTail( size_t nCount );
|
||||
void RemoveHead( size_t nCount );
|
||||
void RemoveAt( size_t nPosition, size_t nCount );
|
||||
|
||||
char *GetString( void );
|
||||
size_t GetLenght( void );
|
||||
operator char*( void );
|
||||
bool operator==(const char* psz);
|
||||
bool operator!=(const char* psz);
|
||||
bool operator==(CUtlString& string);
|
||||
bool operator!=(CUtlString& string);
|
||||
private:
|
||||
CUtlVector<char> m_data;
|
||||
};
|
||||
|
||||
#endif
|
||||
323
public/tier1/utlvector.h
Normal file
323
public/tier1/utlvector.h
Normal file
@@ -0,0 +1,323 @@
|
||||
#ifndef TIER1_UTL_VECTOR_H
|
||||
#define TIER1_UTL_VECTOR_H
|
||||
|
||||
#include "tier1/utlbuffer.h"
|
||||
#include "tier0/lib.h"
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Basic vector implementation. There isn't much in them.
|
||||
//-----------------------------------------------------------------------------
|
||||
template<typename T>
|
||||
class CUtlVector
|
||||
{
|
||||
public:
|
||||
CUtlVector( void );
|
||||
CUtlVector( size_t nSize );
|
||||
|
||||
void AppendHead( const T &data );
|
||||
void AppendHead( const T *pData, size_t n );
|
||||
void AppendTail( const T &data );
|
||||
void AppendTail( const T *data, size_t n );
|
||||
void AppendAt( size_t nIndex, const T &data );
|
||||
void AppendAt( size_t nIndex, const T *data, size_t n );
|
||||
|
||||
void RemoveHead();
|
||||
void RemoveTail();
|
||||
void RemoveAt( size_t nIndex );
|
||||
|
||||
T *GetData( void );
|
||||
size_t GetSize( void );
|
||||
void Resize( size_t nSize );
|
||||
void Reserve( size_t nSize );
|
||||
|
||||
T &operator[]( size_t nIndex );
|
||||
T &operator[]( size_t nIndex ) const;
|
||||
|
||||
// Iterator stuff
|
||||
struct Iterator {
|
||||
T *m_pCurrent;
|
||||
Iterator( T *pCurrent ) : m_pCurrent(pCurrent) {}
|
||||
T& operator*( void ) const { return *m_pCurrent;}
|
||||
Iterator& operator++( void ) {
|
||||
++m_pCurrent;
|
||||
return *this;
|
||||
}
|
||||
bool operator!=( const Iterator& other ) const
|
||||
{
|
||||
return m_pCurrent != other.m_pCurrent;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Iterator begin( void ) const
|
||||
{
|
||||
return Iterator((T*)m_data.GetMemory());
|
||||
}
|
||||
Iterator end( void ) const
|
||||
{
|
||||
return Iterator((T*)m_data.GetMemory()+m_nSize);
|
||||
}
|
||||
|
||||
private:
|
||||
size_t m_nSize = 0;
|
||||
CUtlResizableBuffer<T> m_data;
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// Constructor
|
||||
//----------------------------------------------------------------------------
|
||||
template<typename T>
|
||||
CUtlVector<T>::CUtlVector( void )
|
||||
{
|
||||
m_data.Resize(0);
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// Constructor
|
||||
//----------------------------------------------------------------------------
|
||||
template<typename T>
|
||||
CUtlVector<T>::CUtlVector( size_t nSize )
|
||||
{
|
||||
m_data.Resize(nSize);
|
||||
m_nSize = nSize;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
void CUtlVector<T>::AppendHead( const T &data )
|
||||
{
|
||||
AppendHead(&data,1);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void CUtlVector<T>::AppendHead( const T *pData, size_t n )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void CUtlVector<T>::AppendTail( const T &data )
|
||||
{
|
||||
AppendTail(&data,1);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void CUtlVector<T>::AppendTail( const T *pData, size_t n )
|
||||
{
|
||||
m_data.Resize(m_data.GetSize()+n);
|
||||
V_memcpy(m_data+m_nSize,pData,sizeof(T)*n);
|
||||
m_nSize+=n;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void CUtlVector<T>::AppendAt( size_t nIndex, const T &data )
|
||||
{
|
||||
AppendAt(nIndex, &data, 1);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void CUtlVector<T>::AppendAt( size_t nIndex, const T *pData, size_t n )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void CUtlVector<T>::RemoveHead()
|
||||
{
|
||||
m_nSize--;
|
||||
}
|
||||
template<typename T>
|
||||
void CUtlVector<T>::RemoveTail()
|
||||
{
|
||||
m_nSize--;
|
||||
}
|
||||
template<typename T>
|
||||
void CUtlVector<T>::RemoveAt( size_t nIndex )
|
||||
{
|
||||
m_nSize--;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T *CUtlVector<T>::GetData( void )
|
||||
{
|
||||
return (T*)m_data.GetMemory();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
size_t CUtlVector<T>::GetSize( void )
|
||||
{
|
||||
return m_nSize;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void CUtlVector<T>::Resize( size_t nSize )
|
||||
{
|
||||
m_nSize = nSize;
|
||||
}
|
||||
template<typename T>
|
||||
void CUtlVector<T>::Reserve( size_t nSize )
|
||||
{
|
||||
m_data.Resize(nSize);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T &CUtlVector<T>::operator[]( size_t nIndex )
|
||||
{
|
||||
return m_data[nIndex];
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T &CUtlVector<T>::operator[]( size_t nIndex ) const
|
||||
{
|
||||
return m_data[nIndex];
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Self referencing arrays are quite cool.
|
||||
// They allow to append stuff in head and tail of the array and use less memory
|
||||
// copying. Downside is their indexing is O(n/2)
|
||||
//
|
||||
// Implements the same stuff as CUtlVector does.
|
||||
//-----------------------------------------------------------------------------
|
||||
template<typename T>
|
||||
class CUtlSelfReferencingVector
|
||||
{
|
||||
private:
|
||||
template<typename A>
|
||||
struct SelfData_t;
|
||||
public:
|
||||
CUtlSelfReferencingVector();
|
||||
~CUtlSelfReferencingVector();
|
||||
|
||||
void AppendHead( const T& data );
|
||||
void AppendTail( const T& data );
|
||||
void AppendAt( size_t nIndex, const T& data );
|
||||
|
||||
void RemoveHead( void );
|
||||
void RemoveTail( void );
|
||||
void RemoveAt( size_t nIndex );
|
||||
|
||||
size_t GetSize();
|
||||
|
||||
T operator[]( size_t nIndex );
|
||||
T& operator[]( size_t nIndex ) const;
|
||||
|
||||
|
||||
// Iterator stuff
|
||||
struct Iterator {
|
||||
SelfData_t<T> *m_pCurrent;
|
||||
Iterator( SelfData_t<T> *pCurrent ) : m_pCurrent(pCurrent) {}
|
||||
T& operator*( void ) const { return m_pCurrent->data;}
|
||||
Iterator& operator++( void ) {
|
||||
if (m_pCurrent) m_pCurrent = m_pCurrent->pNext;
|
||||
return *this;
|
||||
}
|
||||
bool operator!=( const Iterator& other ) const
|
||||
{
|
||||
return m_pCurrent != other.m_pCurrent;
|
||||
}
|
||||
};
|
||||
|
||||
Iterator begin( void ) const
|
||||
{
|
||||
return Iterator(m_pHead);
|
||||
}
|
||||
Iterator end( void ) const
|
||||
{
|
||||
return Iterator(NULL);
|
||||
}
|
||||
|
||||
private:
|
||||
size_t m_nSize = 0;
|
||||
|
||||
template<typename A>
|
||||
struct SelfData_t
|
||||
{
|
||||
SelfData_t *pNext = NULL;
|
||||
SelfData_t *pPrev = NULL;
|
||||
A data;
|
||||
};
|
||||
SelfData_t<T> *m_pTail = NULL;
|
||||
SelfData_t<T> *m_pHead = NULL;
|
||||
};
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// Constructor
|
||||
//----------------------------------------------------------------------------
|
||||
template<typename T>
|
||||
CUtlSelfReferencingVector<T>::CUtlSelfReferencingVector()
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// Destructor
|
||||
//----------------------------------------------------------------------------
|
||||
template<typename T>
|
||||
CUtlSelfReferencingVector<T>::~CUtlSelfReferencingVector()
|
||||
{
|
||||
SelfData_t<T> *pNext = NULL;
|
||||
for (SelfData_t<T> *pCurrent = m_pHead; pCurrent; pCurrent=pNext)
|
||||
{
|
||||
pNext = pCurrent->pNext;
|
||||
delete pCurrent;
|
||||
}
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// Inserts new element in the start of the vector.
|
||||
//----------------------------------------------------------------------------
|
||||
template<typename T>
|
||||
void CUtlSelfReferencingVector<T>::AppendHead( const T& data )
|
||||
{
|
||||
SelfData_t<T>* pData = new SelfData_t<T>;
|
||||
pData->data = data;
|
||||
pData->pNext = m_pHead;
|
||||
if (m_pHead)
|
||||
m_pHead->pPrev = pData;
|
||||
pData->pPrev = 0;
|
||||
m_pHead = pData;
|
||||
if (m_pTail == 0)
|
||||
m_pTail = m_pHead;
|
||||
m_nSize++;
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// Inserts new element in the end of the vector.
|
||||
//----------------------------------------------------------------------------
|
||||
template<typename T>
|
||||
void CUtlSelfReferencingVector<T>::AppendTail( const T& data )
|
||||
{
|
||||
SelfData_t<T>* pData = new SelfData_t<T>;
|
||||
pData->data = data;
|
||||
if (m_pTail)
|
||||
m_pTail->pNext = pData;
|
||||
pData->pPrev = m_pTail;
|
||||
m_pTail = pData;
|
||||
if (m_pHead == 0)
|
||||
m_pHead = m_pTail;
|
||||
|
||||
m_nSize++;
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// Removes element in the start of the vector.
|
||||
//----------------------------------------------------------------------------
|
||||
template<typename T>
|
||||
void CUtlSelfReferencingVector<T>::RemoveHead( void )
|
||||
{
|
||||
if (m_pHead == m_pTail)
|
||||
m_pHead = 0;
|
||||
};
|
||||
//----------------------------------------------------------------------------
|
||||
// Removes element in the end of the vector.
|
||||
//----------------------------------------------------------------------------
|
||||
template<typename T>
|
||||
void CUtlSelfReferencingVector<T>::RemoveTail( void )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user