Stock.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /* Copyright (c) 2002-2012 Croteam Ltd.
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of version 2 of the GNU General Public License as published by
  4. the Free Software Foundation
  5. This program is distributed in the hope that it will be useful,
  6. but WITHOUT ANY WARRANTY; without even the implied warranty of
  7. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8. GNU General Public License for more details.
  9. You should have received a copy of the GNU General Public License along
  10. with this program; if not, write to the Free Software Foundation, Inc.,
  11. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
  12. #if !defined(TYPE) || !defined(CStock_TYPE) || !defined(CNameTable_TYPE)
  13. #error
  14. #endif
  15. #include <Engine/Templates/DynamicContainer.h>
  16. /*
  17. * Template for stock of some kind of objects that can be saved and loaded.
  18. */
  19. class CStock_TYPE {
  20. public:
  21. CDynamicContainer<TYPE> st_ctObjects; // objects on stock
  22. CNameTable_TYPE st_ntObjects; // name table for fast lookup
  23. public:
  24. /* Default constructor. */
  25. CStock_TYPE(void);
  26. /* Destructor. */
  27. ~CStock_TYPE(void);
  28. /* Obtain an object from stock - loads if not loaded. */
  29. ENGINE_API TYPE *Obtain_t(const CTFileName &fnmFileName); // throw char *
  30. /* Release an object when not needed any more. */
  31. ENGINE_API void Release(TYPE *ptObject);
  32. // free all unused elements of the stock
  33. ENGINE_API void FreeUnused(void);
  34. // calculate amount of memory used by all objects in the stock
  35. SLONG CalculateUsedMemory(void);
  36. // dump memory usage report to a file
  37. void DumpMemoryUsage_t(CTStream &strm); // throw char *
  38. // get number of total elements in stock
  39. INDEX GetTotalCount(void);
  40. // get number of used elements in stock
  41. INDEX GetUsedCount(void);
  42. };