summaryrefslogtreecommitdiff
path: root/utils/dx_proxy/filememcache.h
diff options
context:
space:
mode:
authorFluorescentCIAAfricanAmerican <[email protected]>2020-04-22 12:56:21 -0400
committerFluorescentCIAAfricanAmerican <[email protected]>2020-04-22 12:56:21 -0400
commit3bf9df6b2785fa6d951086978a3e66f49427166a (patch)
tree2c0f1f0c63c4832882bc93814ebd2c2b1c6224e5 /utils/dx_proxy/filememcache.h
downloadarchived-source-engine-2018-hl2-src-master.tar.xz
archived-source-engine-2018-hl2-src-master.zip
Diffstat (limited to 'utils/dx_proxy/filememcache.h')
-rw-r--r--utils/dx_proxy/filememcache.h76
1 files changed, 76 insertions, 0 deletions
diff --git a/utils/dx_proxy/filememcache.h b/utils/dx_proxy/filememcache.h
new file mode 100644
index 0000000..36d5bf7
--- /dev/null
+++ b/utils/dx_proxy/filememcache.h
@@ -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