home *** CD-ROM | disk | FTP | other *** search
/ Windows Graphics Programming / Feng_Yuan_Win32_GDI_DirectX.iso / Samples / Chapt_16 / EMF / Cache.cpp next >
Encoding:
C/C++ Source or Header  |  2000-05-16  |  1.4 KB  |  41 lines

  1. //-----------------------------------------------------------------------------------//
  2. //              Windows Graphics Programming: Win32 GDI and DirectDraw               //
  3. //                             ISBN  0-13-086985-6                                   //
  4. //                                                                                   //
  5. //  Written            by  Yuan, Feng                             www.fengyuan.com   //
  6. //  Copyright (c) 2000 by  Hewlett-Packard Company                www.hp.com         //
  7. //  Published          by  Prentice Hall PTR, Prentice-Hall, Inc. www.phptr.com      //
  8. //                                                                                   //
  9. //  FileName   : cache.cpp                                                             //
  10. //  Description: KCache class: remove duplication                                     //
  11. //  Version    : 1.00.000, May 31, 2000                                              //
  12. //-----------------------------------------------------------------------------------//
  13.  
  14. #define STRICT
  15. #define WIN32_LEAN_AND_MEAN
  16.  
  17. #include <windows.h>
  18. #include <assert.h>
  19. #include <memory.h>
  20.  
  21. #include "Cache.h"
  22.  
  23.  
  24. bool KCache::Match(long size, const void * data, long & rslt)
  25. {
  26.     for (int i=0; i<CacheSize; i++)
  27.     {
  28.         rslt = m_Cache[i].Match(size, data);
  29.         
  30.         if ( rslt>=0 )
  31.             return true;
  32.     }
  33.  
  34.     rslt = m_total ++;
  35.     
  36.     m_Cache[rslt % CacheSize].Set(size, data, rslt);
  37.  
  38.     return false;
  39. }
  40.  
  41.