#ifndef __VolumeWeightedData_h_ #define __VolumeWeightedData_h_ #include #include #include #include "../misc_framework/DataNodes.h" // Somewhat arbitrary, just to keep us from running // out of memory killing the process. #define MAX_VOLUME_BLOCKS 2048 struct VolumeBlock { // In practice, no one uses extremeHigh, middle, or extremeLow except for // debugging and development. // High is the 75th percentile. // Low is the 25th percentile. double high, low; time_t startTime, endTime; }; typedef std::vector< VolumeBlock > VolumeBlocks; class VolumeBlockFactory { private: bool _overflow; DataNode::Integer _groupBy; VolumeBlocks _volumeBlocks; std::map< double, DataNode::Integer > _inProcessList; DataNode::Integer _inProcessShares; time_t _inProcessStart, _inProcessEnd; void addToBlock(double price, DataNode::Integer size, time_t time); void initBlock(); void nextBlock(); void signalOverflow(); // This is purposely undefined. This avoids certain errors I saw where the // wrong type was converted to an integer. VolumeBlockFactory(bool _groupBy); public: VolumeBlockFactory(DataNode::Integer groupBy); void initializeWith(VolumeBlocks const &volumeBlocks); void initializeWith(std::string const &encoded); void addPrint(double price, DataNode::Integer size, time_t time); VolumeBlocks const &getBlocks() const { return _volumeBlocks; } VolumeBlocks::size_type getBlockCount() const { return getBlocks().size(); } bool overflow() const { return _overflow; } DataNode::Integer getGroupBy() const { return _groupBy; } }; std::string volumeBlockToString(VolumeBlock const &volumeBlock); std::string volumeBlocksToString(VolumeBlocks volumeBlocks, bool reverse); // These will throw an exception if the input cannot be decoded. VolumeBlock volumeBlockFromString(std::string s); void volumeBlocksFromString(std::string const &s, VolumeBlocks &volumeBlocks); #endif