Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
1.5 KiB

  1. //====== Copyright c 1996-2007, Valve Corporation, All rights reserved. =======//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. #ifndef FILEMEMCACHE_H
  9. #define FILEMEMCACHE_H
  10. #ifdef _WIN32
  11. #pragma once
  12. #endif
  13. #include "tier0/platform.h"
  14. #include "tier0/basetypes.h"
  15. #define _SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS
  16. #include <hash_map>
  17. #pragma warning ( disable : 4200 )
  18. class CachedFileData
  19. {
  20. friend class FileCache;
  21. protected: // Constructed by FileCache
  22. CachedFileData() {}
  23. static CachedFileData *Create( char const *szFilename );
  24. void Free( void );
  25. public:
  26. static CachedFileData *GetByDataPtr( void const *pvDataPtr );
  27. char const * GetFileName() const;
  28. void const * GetDataPtr() const;
  29. int GetDataLen() const;
  30. int UpdateRefCount( int iDeltaRefCount ) { return m_numRefs += iDeltaRefCount; }
  31. bool IsValid() const;
  32. protected:
  33. enum { eHeaderSize = 256 };
  34. char m_chFilename[256 - 12];
  35. int m_numRefs;
  36. int m_numDataBytes;
  37. int m_signature;
  38. unsigned char m_data[0]; // file data spans further
  39. };
  40. class FileCache
  41. {
  42. public:
  43. FileCache();
  44. ~FileCache() { Clear(); }
  45. public:
  46. CachedFileData *Get( char const *szFilename );
  47. void Clear( void );
  48. protected:
  49. struct icmp { bool operator()( char const *x, char const *y ) const { return _stricmp( x, y ) < 0; } };
  50. typedef stdext::hash_map< char const *, CachedFileData *, stdext::hash_compare< char const *, icmp > > Mapping;
  51. Mapping m_map;
  52. };
  53. #endif // #ifndef FILEMEMCACHE_H