hl2_src-leak-2017/src/utils/dx_proxy/filememcache.h
BotoX 60f625f414 import hl2_src from full.7z
source: magnet:?xt=urn:btih:21DDA6847DDE983F2F8063739249D2D1D09A5DDA
2020-12-25 16:26:23 +01:00

77 lines
1.5 KiB
C++

//========= 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