#ifndef __SingleCandle_h_ #define __SingleCandle_h_ #include #include "../shared/MiscSupport.h" struct SingleCandle { double open, high, low, close; int64_t volume; bool operator ==(SingleCandle const &other) const; bool operator !=(SingleCandle const &other) const; void clear() { open = high = low = close = 0.0; volume = 0; } bool empty() const { return open == 0.0; } void add(double price, int64_t size); void operator +=(SingleCandle const &other); void preAppend(SingleCandle const &other); SingleCandle() { clear(); } TclList debugDump() const; void marshal(time_t startTime, std::string &destination) const; typedef std::map< time_t, SingleCandle > ByStartTime; // This will add to or replace what's in the destination. This does not // clear the old data from the destination. static bool unmarshal(std::string const &source, ByStartTime &destination); }; struct SingleCandleWithTime { time_t startTime; SingleCandle candle; struct Comp { // Compare two of these objects. Great for sorting a list of these // objects. bool operator() (SingleCandleWithTime const &a, SingleCandleWithTime const &b) const { return a.startTime < b.startTime; } // Compare one of these objects to a time_t. If you have a // std::vector, and you want to find the candle // associated with a time, it will use this function. bool operator() (SingleCandleWithTime const &a, time_t b) const { return a.startTime < b; } }; }; // Returns NULL if not found. Does a binary search, assumes the list is // sorted. SingleCandle const *findCandle(std::vector< SingleCandleWithTime > const &list, time_t time); // RowTimes and AllRowTimes originally came from CandleCache.h. They are most // useful if they are used in a lot of places, not just the cache. A lot of // things don't directly know about the cache, but this data structure gets // passed from one place to the next. struct RowTimes { time_t start; time_t end; RowTimes() { } RowTimes(time_t start, time_t end) : start(start), end(end) { } }; typedef std::vector< RowTimes > AllRowTimes; #endif