mirror of
https://github.com/nillerusr/source-engine.git
synced 2026-08-10 02:39:35 +00:00
1
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//=============================================================================//
|
||||
|
||||
#ifndef FILEMEMCACHE_H
|
||||
#define FILEMEMCACHE_H
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "tier0/platform.h"
|
||||
#include "tier1/generichash.h"
|
||||
#include <unordered_map>
|
||||
|
||||
#pragma warning ( disable : 4200 )
|
||||
|
||||
class CachedFileData
|
||||
{
|
||||
friend class FileCache;
|
||||
|
||||
protected: // Constructed by FileCache
|
||||
CachedFileData() {}
|
||||
static CachedFileData *Create( char const *szFilename );
|
||||
void Free( void );
|
||||
|
||||
public:
|
||||
static CachedFileData *GetByDataPtr( void const *pvDataPtr );
|
||||
|
||||
char const * GetFileName() const;
|
||||
void const * GetDataPtr() const;
|
||||
int GetDataLen() const;
|
||||
|
||||
int UpdateRefCount( int iDeltaRefCount ) { return m_numRefs += iDeltaRefCount; }
|
||||
|
||||
bool IsValid() const;
|
||||
|
||||
protected:
|
||||
enum { eHeaderSize = 256 };
|
||||
char m_chFilename[256 - 12];
|
||||
int m_numRefs;
|
||||
int m_numDataBytes;
|
||||
int m_signature;
|
||||
unsigned char m_data[0]; // file data spans further
|
||||
};
|
||||
|
||||
class FileCache
|
||||
{
|
||||
public:
|
||||
FileCache();
|
||||
~FileCache() { Clear(); }
|
||||
|
||||
public:
|
||||
CachedFileData *Get( char const *szFilename );
|
||||
void Clear( void );
|
||||
|
||||
protected:
|
||||
struct eqstr {
|
||||
inline size_t operator()( const char *s ) const {
|
||||
if ( !s )
|
||||
return 0;
|
||||
return HashString( s );
|
||||
}
|
||||
inline bool operator()( const char *s1, const char *s2 ) const {
|
||||
return _stricmp( s1, s2 ) < 0;
|
||||
}
|
||||
};
|
||||
|
||||
typedef std::unordered_map< const char *, CachedFileData *, eqstr, eqstr > Mapping;
|
||||
Mapping m_map;
|
||||
};
|
||||
|
||||
#endif // #ifndef FILEMEMCACHE_H
|
||||
Reference in New Issue
Block a user