#ifndef __CandleCache_h_ #define __CandleCache_h_ #include "SingleCandle.h" #include "GridReaderBase.h" class CandleCache { public: // Candle Start Time --> Possible Row. typedef std::map< time_t, int > Requests; private: static __thread CandleCache *_instance; void const *const _owner; std::map< int, SingleCandle > _values; CandleCache(Requests const &requests, SingleCandle::ByStartTime const &byStartTime, void const *owner); void get(int possibleRow, bool &inCache, SingleCandle &value) const; public: static void getAllRows(GridDataProviderContext *context, Requests &requests, AllRowTimes &allRowTimes); // Some caching is active in this thread. static bool active() { return _instance; } // Store this in the cache. The cache for this thread should be empty before // this call. We can only cache one thing per thread and you have to // explicitly call release() when you are done with that. static void start(Requests const &requests, SingleCandle::ByStartTime const &data, void const *owner); // If nothing is being cached, this always returns not in cache. It // something is being cached, but not the given object, then this returns // not in cache. That second case probably shouldn't happen, but this seems // like a clean interface. That's how a cache works. It a cache contains // something other than what you're looking for, that's not an error. static void get(void const *owner, int possibleRow, bool &inCache, SingleCandle &value); // If the given object is not being cached, that's not an error. We allow // that to make cleanup simpler. A destructor or a try block might call // this just to be safe. static void release(void const *owner); }; #endif