• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

include/roc/Iterator.h (r4864/r4162)

Go to the documentation of this file.
00001 #ifndef ROC_ITERATOR_H
00002 #define ROC_ITERATOR_H
00003 
00004 #include "roc/Message.h"
00005 
00006 #include "roc/Board.h"
00007 
00008 namespace roc {
00009 
00010    class Iterator {
00011       protected:
00012          enum { MaxGet4=16 };
00013       
00014          int           fFormat;     // format identifier
00015          void*         fBuffer;     // assigned buffer
00016          uint32_t      fBufferLen;  // length of assigned buffer
00017          uint32_t      fBufferPos;  // current position
00018          uint32_t      fMsgSize;    // size of single message
00019          Message       fMsg;        // current read message
00020          uint32_t      fEpoch;      // current epoch
00021          uint32_t      fEpoch2[MaxGet4];  // current epoch2 for each Get4
00022          base::Board*  fBoard;      // board instance, which delivers buffers
00023          bool          fOwner;      // owner of board instance
00024 
00025       public:
00026          Iterator(int fmt = formatNormal);
00027 
00028          Iterator(base::Board* brd, bool owner = false);
00029 
00030          Iterator(const Iterator& src);
00031 
00032          Iterator(const char* filename);
00033 
00034          virtual ~Iterator();
00035 
00036          void setFormat(int fmt);
00037          int getFormat() const { return fFormat; }
00038 
00039          bool isFile() const;
00040 
00041          void setRocNumber(uint16_t rocnum = 0);
00042 
00043          uint32_t getMsgSize() const { return fMsgSize; }
00044 
00045          bool assign(void* buf, uint32_t len);
00046 
00047          bool nextBuffer(base::Board* brd, double tmout = 1.);
00048 
00049          void resetEpochs();
00050 
00051          inline bool next(double tmout = 1.)
00052          {
00053             if ((fBuffer==0) || (fBufferPos>=fBufferLen))
00054                if (!nextBuffer(fBoard, tmout)) return false;
00055             if (fMsg.assign((uint8_t*) fBuffer + fBufferPos, fFormat)) {
00056                fBufferPos += fMsgSize;
00057                switch (fMsg.getMessageType()) {
00058                   case MSG_EPOCH:  fEpoch = fMsg.getEpochNumber(); break;
00059                   case MSG_EPOCH2:
00060                      if (fMsg.getEpoch2ChipNumber() < MaxGet4) fEpoch2[fMsg.getEpoch2ChipNumber()] = fMsg.getEpoch2Number();
00061                      break;
00062                }
00063                return true;
00064             }
00065             fBufferPos = fBufferLen;
00066             return false;
00067          }
00068 
00069          // returns true is last message was extracted from the buffer
00070          inline bool islast() const { return  fBufferPos >= fBufferLen; }
00071 
00072          // can be used only inside buffer, not with board source
00073          inline bool last()
00074          {
00075             if ((fBuffer==0) || (fBufferLen<fMsgSize)) return false;
00076 
00077             fBufferPos = (fBufferLen - fMsgSize) / fMsgSize * fMsgSize;
00078 
00079             return next(0.);
00080          }
00081 
00082          // can be used only inside buffer, not with board source
00083          inline bool prev()
00084          {
00085             if ((fBuffer==0) || (fBufferPos<fMsgSize*2)) return false;
00086 
00087             fBufferPos -= fMsgSize*2;
00088 
00089             return next(0.);
00090          }
00091 
00092          uint32_t getLastEpoch() const { return fEpoch; }
00093 
00094          uint32_t getLastEpoch2(unsigned n=0) const { return n<MaxGet4 ? fEpoch2[n] : 0; }
00095 
00096          inline Message& msg() { return fMsg; }
00097 
00098          inline uint32_t getMsgEpoch() const 
00099          {
00100             switch(fMsg.getMessageType()) {
00101                case MSG_EPOCH2:
00102 //               return (fMsg.getEpoch2ChipNumber() < MaxGet4) ? fEpoch2[fMsg.getEpoch2ChipNumber()] : 0;
00103                   return fMsg.getEpoch2Number();
00104                case MSG_GET4:
00105                   return (fMsg.getGet4Number() < MaxGet4) ? fEpoch2[fMsg.getGet4Number()] : 0;
00106             }
00107             return fEpoch;
00108          }
00109 
00110          inline uint64_t getMsgFullTime() const
00111          {
00112             return fMsg.getMsgFullTime(getMsgEpoch());
00113          }
00114 
00115          inline double getMsgFullTimeD() const
00116          {
00117             return fMsg.getMsgFullTimeD(getMsgEpoch());
00118          }
00119 
00120          void printMessage(unsigned kind = msg_print_Prefix | msg_print_Data);
00121 
00122          void printMessages(unsigned cnt = 100, unsigned kind = msg_print_Prefix | msg_print_Data);
00123    };
00124 }
00125 
00126 
00127 #endif

Generated on Tue Dec 10 2013 04:52:22 for ROCsoft by  doxygen 1.7.1