diff options
| author | Jørgen P. Tjernø <[email protected]> | 2013-12-02 19:31:46 -0800 |
|---|---|---|
| committer | Jørgen P. Tjernø <[email protected]> | 2013-12-02 19:46:31 -0800 |
| commit | f56bb35301836e56582a575a75864392a0177875 (patch) | |
| tree | de61ddd39de3e7df52759711950b4c288592f0dc /sp/src/public/tier1/utlallocation.h | |
| parent | Mark some more files as text. (diff) | |
| download | source-sdk-2013-f56bb35301836e56582a575a75864392a0177875.tar.xz source-sdk-2013-f56bb35301836e56582a575a75864392a0177875.zip | |
Fix line endings. WHAMMY.
Diffstat (limited to 'sp/src/public/tier1/utlallocation.h')
| -rw-r--r-- | sp/src/public/tier1/utlallocation.h | 268 |
1 files changed, 134 insertions, 134 deletions
diff --git a/sp/src/public/tier1/utlallocation.h b/sp/src/public/tier1/utlallocation.h index c0116b08..65416bcf 100644 --- a/sp/src/public/tier1/utlallocation.h +++ b/sp/src/public/tier1/utlallocation.h @@ -1,134 +1,134 @@ -//========= Copyright Valve Corporation, All rights reserved. ============//
-//
-// Purpose:
-// The CUtlAllocation class:
-// A single allocation in the style of CUtlMemory/CUtlString/CUtlBuffer
-// as compact as possible, no virtuals or extraneous data
-// to be used primarily to replace CUtlBuffer
-//=============================================================================
-
-#ifndef UTLALLOCATION_H
-#define UTLALLOCATION_H
-#ifdef _WIN32
-#pragma once
-#endif
-
-#include "tier1/utlmemory.h"
-
-class CUtlAllocation
-{
-public:
-
- // constructor, destructor
- CUtlAllocation()
- {
- m_pMemory = NULL;
- }
-
- CUtlAllocation( const void *pMemory, int cub )
- {
- m_pMemory = NULL;
- Copy( pMemory, cub );
- }
-
- CUtlAllocation( CUtlAllocation const &src )
- {
- m_pMemory = NULL;
- Copy( src );
- }
-
- ~CUtlAllocation()
- {
- Purge();
- }
-
- CUtlAllocation &operator=( CUtlAllocation const &src )
- {
- Copy( src );
- return *this;
- }
-
- bool operator==( CUtlAllocation const &src )
- {
- if ( Count() != src.Count() )
- return false;
- return Q_memcmp( Base(), src.Base(), Count() ) == 0;
- }
-
- void Copy( const void *pMemory, int cub )
- {
- if ( cub == 0 || pMemory == NULL )
- {
- Purge();
- return;
- }
- if ( cub != Count() )
- {
- Purge();
- m_pMemory = (ActualMemory_t *)malloc( cub + sizeof( int ) );
- m_pMemory->cub = cub;
- }
- Q_memcpy( Base(), pMemory, cub );
- }
-
- // Gets the base address
- uint8* Base()
- {
- if ( m_pMemory == NULL )
- return NULL;
- return m_pMemory->rgub;
- }
-
- const uint8* Base() const
- {
- if ( m_pMemory == NULL )
- return NULL;
- return m_pMemory->rgub;
- }
-
- // Size
- int Count() const
- {
- if ( m_pMemory == NULL )
- return 0;
- return m_pMemory->cub;
- }
-
- // Memory deallocation
- void Purge()
- {
- if ( m_pMemory )
- free(m_pMemory);
- m_pMemory = NULL;
- }
-
- void Copy( const CUtlAllocation &alloc )
- {
- Copy( alloc.Base(), alloc.Count() );
- }
-
- void Swap( CUtlAllocation &alloc )
- {
- ActualMemory_t *pTemp = m_pMemory;
- m_pMemory = alloc.m_pMemory;
- alloc.m_pMemory = pTemp;
- }
-
- void Alloc( int cub )
- {
- Purge();
- m_pMemory = (ActualMemory_t *)malloc( cub + sizeof( int ) );
- m_pMemory->cub = cub;
- }
-
-private:
- struct ActualMemory_t
- {
- int cub;
- uint8 rgub[4]; // i'd prefer to make this 0 but the compiler whines when i do
- };
-
- ActualMemory_t *m_pMemory;
-};
-
-#endif // UTLALLOCATION_H
+//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// The CUtlAllocation class: +// A single allocation in the style of CUtlMemory/CUtlString/CUtlBuffer +// as compact as possible, no virtuals or extraneous data +// to be used primarily to replace CUtlBuffer +//============================================================================= + +#ifndef UTLALLOCATION_H +#define UTLALLOCATION_H +#ifdef _WIN32 +#pragma once +#endif + +#include "tier1/utlmemory.h" + +class CUtlAllocation +{ +public: + + // constructor, destructor + CUtlAllocation() + { + m_pMemory = NULL; + } + + CUtlAllocation( const void *pMemory, int cub ) + { + m_pMemory = NULL; + Copy( pMemory, cub ); + } + + CUtlAllocation( CUtlAllocation const &src ) + { + m_pMemory = NULL; + Copy( src ); + } + + ~CUtlAllocation() + { + Purge(); + } + + CUtlAllocation &operator=( CUtlAllocation const &src ) + { + Copy( src ); + return *this; + } + + bool operator==( CUtlAllocation const &src ) + { + if ( Count() != src.Count() ) + return false; + return Q_memcmp( Base(), src.Base(), Count() ) == 0; + } + + void Copy( const void *pMemory, int cub ) + { + if ( cub == 0 || pMemory == NULL ) + { + Purge(); + return; + } + if ( cub != Count() ) + { + Purge(); + m_pMemory = (ActualMemory_t *)malloc( cub + sizeof( int ) ); + m_pMemory->cub = cub; + } + Q_memcpy( Base(), pMemory, cub ); + } + + // Gets the base address + uint8* Base() + { + if ( m_pMemory == NULL ) + return NULL; + return m_pMemory->rgub; + } + + const uint8* Base() const + { + if ( m_pMemory == NULL ) + return NULL; + return m_pMemory->rgub; + } + + // Size + int Count() const + { + if ( m_pMemory == NULL ) + return 0; + return m_pMemory->cub; + } + + // Memory deallocation + void Purge() + { + if ( m_pMemory ) + free(m_pMemory); + m_pMemory = NULL; + } + + void Copy( const CUtlAllocation &alloc ) + { + Copy( alloc.Base(), alloc.Count() ); + } + + void Swap( CUtlAllocation &alloc ) + { + ActualMemory_t *pTemp = m_pMemory; + m_pMemory = alloc.m_pMemory; + alloc.m_pMemory = pTemp; + } + + void Alloc( int cub ) + { + Purge(); + m_pMemory = (ActualMemory_t *)malloc( cub + sizeof( int ) ); + m_pMemory->cub = cub; + } + +private: + struct ActualMemory_t + { + int cub; + uint8 rgub[4]; // i'd prefer to make this 0 but the compiler whines when i do + }; + + ActualMemory_t *m_pMemory; +}; + +#endif // UTLALLOCATION_H |