CachedData.h 560 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #ifndef CACHEDDATAH
  2. #define CACHEDDATAH
  3. template <class DataType>
  4. class CachedData
  5. {
  6. public:
  7. CachedData() : cached(false)
  8. {
  9. }
  10. CachedData(DataType _data) : cached(true), data(_data)
  11. {
  12. }
  13. operator DataType()
  14. {
  15. return data;
  16. }
  17. bool IsCached()
  18. {
  19. return cached;
  20. }
  21. void ClearCache()
  22. {
  23. cached=false;
  24. }
  25. DataType *operator &()
  26. {
  27. if (cached)
  28. return &data;
  29. else
  30. return 0;
  31. }
  32. template <class FromType>
  33. bool operator =(FromType from)
  34. {
  35. data = from;
  36. cached=true;
  37. return cached;
  38. }
  39. private:
  40. bool cached;
  41. DataType data;
  42. };
  43. #endif