Leaked source code of windows server 2003
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.

79 lines
2.9 KiB

  1. //------------------------------------------------------------------------------
  2. // File: Cache.h
  3. //
  4. // Desc: DirectShow base classes - efines a non-MFC generic cache class.
  5. //
  6. //@@BEGIN_MSINTERNAL
  7. //
  8. // January 1995
  9. //
  10. //@@END_MSINTERNAL
  11. // Copyright (c) 1992-2001 Microsoft Corporation. All rights reserved.
  12. //------------------------------------------------------------------------------
  13. /* This class implements a simple cache. A cache object is instantiated
  14. with the number of items it is to hold. An item is a pointer to an
  15. object derived from CBaseObject (helps reduce memory leaks). The cache
  16. can then have objects added to it and removed from it. The cache size
  17. is fixed at construction time and may therefore run out or be flooded.
  18. If it runs out it returns a NULL pointer, if it fills up it also returns
  19. a NULL pointer instead of a pointer to the object just inserted */
  20. /* Making these classes inherit from CBaseObject does nothing for their
  21. functionality but it allows us to check there are no memory leaks */
  22. /* WARNING Be very careful when using this class, what it lets you do is
  23. store and retrieve objects so that you can minimise object creation
  24. which in turns improves efficiency. However the object you store is
  25. exactly the same as the object you get back which means that it short
  26. circuits the constructor initialisation phase. This means any class
  27. variables the object has (eg pointers) are highly likely to be invalid.
  28. Therefore ensure you reinitialise the object before using it again */
  29. #ifndef __CACHE__
  30. #define __CACHE__
  31. class CCache : CBaseObject {
  32. /* Make copy constructor and assignment operator inaccessible */
  33. CCache(const CCache &refCache);
  34. CCache &operator=(const CCache &refCache);
  35. private:
  36. /* These are initialised in the constructor. The first variable points to
  37. an array of pointers, each of which points to a CBaseObject derived
  38. object. The m_iCacheSize is the static fixed size for the cache and the
  39. m_iUsed defines the number of places filled with objects at any time.
  40. We fill the array of pointers from the start (ie m_ppObjects[0] first)
  41. and then only add and remove objects from the end position, so in this
  42. respect the array of object pointers should be treated as a stack */
  43. CBaseObject **m_ppObjects;
  44. const INT m_iCacheSize;
  45. INT m_iUsed;
  46. public:
  47. CCache(TCHAR *pName,INT iItems);
  48. virtual ~CCache();
  49. /* Add an item to the cache */
  50. CBaseObject *AddToCache(CBaseObject *pObject);
  51. /* Remove an item from the cache */
  52. CBaseObject *RemoveFromCache();
  53. /* Delete all the objects held in the cache */
  54. void RemoveAll(void);
  55. /* Return the cache size which is set during construction */
  56. INT GetCacheSize(void) const {return m_iCacheSize;};
  57. };
  58. #endif /* __CACHE__ */