#ifndef ROC_ITERATOR_H #define ROC_ITERATOR_H #include "roc/Message.h" #include "roc/Board.h" namespace roc { class Iterator { protected: enum { MaxGet4=16 }; int fFormat; // format identifier void* fBuffer; // assigned buffer uint32_t fBufferLen; // length of assigned buffer uint32_t fBufferPos; // current position uint32_t fMsgSize; // size of single message Message fMsg; // current read message uint32_t fEpoch; // current epoch uint32_t fEpoch2[MaxGet4]; // current epoch2 for each Get4 base::Board* fBoard; // board instance, which delivers buffers bool fOwner; // owner of board instance public: Iterator(int fmt = formatNormal); Iterator(base::Board* brd, bool owner = false); Iterator(const Iterator& src); Iterator(const char* filename); virtual ~Iterator(); void setFormat(int fmt); int getFormat() const { return fFormat; } bool isFile() const; void setRocNumber(uint16_t rocnum = 0); uint32_t getMsgSize() const { return fMsgSize; } bool assign(void* buf, uint32_t len); bool nextBuffer(base::Board* brd, double tmout = 1.); void resetEpochs(); inline bool next(double tmout = 1.) { if ((fBuffer==0) || (fBufferPos>=fBufferLen)) if (!nextBuffer(fBoard, tmout)) return false; if (fMsg.assign((uint8_t*) fBuffer + fBufferPos, fFormat)) { fBufferPos += fMsgSize; switch (fMsg.getMessageType()) { case MSG_EPOCH: fEpoch = fMsg.getEpochNumber(); break; case MSG_EPOCH2: if (fMsg.getEpoch2ChipNumber() < MaxGet4) fEpoch2[fMsg.getEpoch2ChipNumber()] = fMsg.getEpoch2Number(); break; } return true; } fBufferPos = fBufferLen; return false; } // returns true is last message was extracted from the buffer inline bool islast() const { return fBufferPos >= fBufferLen; } // can be used only inside buffer, not with board source inline bool last() { if ((fBuffer==0) || (fBufferLen