/search.css" rel="stylesheet" type="text/css"/> /search.js">
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

DataBuffer.h
Go to the documentation of this file.
00001 #ifndef LAF_DATA_BUFFER_H
00002 #define LAF_DATA_BUFFER_H
00003 
00004 #include <deque>
00005 #include <algorithm>
00006 
00007 template<typename Data>
00008 class DataBuffer
00009 {
00010     public :
00011 
00012         typedef typename std::deque<Data*>::iterator Iterator;
00013 
00014         DataBuffer();
00015         virtual ~DataBuffer();
00016 
00017         inline Iterator begin();
00018         inline Iterator current();
00019         inline Iterator end();
00020 
00021         //Return the Iterator that corresponding to the data pointer
00022         inline Iterator find(const Data* data);
00023         //current()+pos, the pos can be positive or negtive
00024         inline Iterator seek(int pos);
00025 
00026         inline Data*    curEvt();
00027         inline Data*    seekEvt(int pos);
00028 
00029         inline int      totalSize();
00030         inline int      forwardSize();
00031         inline int      backwardSize();
00032 
00033         void            clear();
00034 
00035     protected :
00036 
00037         unsigned int       m_iCur;
00038         std::deque<Data*>  m_dBuf;
00039 
00040 
00041     private :
00042         // following interfaces are not supported
00043         DataBuffer(const DataBuffer&);
00044         DataBuffer& operator=(const DataBuffer&);
00045 };
00046 
00047 template<typename Data>
00048 DataBuffer<Data>::DataBuffer()
00049     : m_iCur(0xFFFFFFFF)
00050 {
00051 }
00052 
00053 template<typename Data>
00054 DataBuffer<Data>::~DataBuffer()
00055 {
00056     clear();
00057 }
00058 
00059 template<typename Data>
00060 typename DataBuffer<Data>::Iterator DataBuffer<Data>::begin()
00061 {
00062     return m_dBuf.begin();
00063 }
00064 
00065 template<typename Data>
00066 typename DataBuffer<Data>::Iterator DataBuffer<Data>::current()
00067 {
00068     return (m_dBuf.begin()+m_iCur);
00069 }
00070 
00071 template<typename Data>
00072 typename DataBuffer<Data>::Iterator DataBuffer<Data>::end()
00073 {
00074     return m_dBuf.end();
00075 }
00076 
00077 template<typename Data>
00078 typename DataBuffer<Data>::Iterator DataBuffer<Data>::find(const Data* data)
00079 {
00080     return std::find(m_dBuf.begin(), m_dBuf.end(), data);
00081 }
00082 
00083 template<typename Data>
00084 typename DataBuffer<Data>::Iterator DataBuffer<Data>::seek(int pos)
00085 {
00086     return (m_dBuf.begin()+(int(m_iCur)+pos));
00087 }
00088 
00089 template<typename Data>
00090 Data* DataBuffer<Data>::curEvt()
00091 {
00092     if ( !m_dBuf.empty() ) {
00093         return m_dBuf[m_iCur];
00094     }
00095     return (Data*)0;
00096 }
00097 
00098 template<typename Data>
00099 Data* DataBuffer<Data>::seekEvt(int pos)
00100 {
00101     return m_dBuf.at(m_iCur+pos);
00102 }
00103 
00104 template<typename Data>
00105 int DataBuffer<Data>::totalSize()
00106 {
00107     return m_dBuf.size();
00108 }
00109 
00110 template<typename Data>
00111 int DataBuffer<Data>::forwardSize()
00112 {
00113     return (m_dBuf.size()-m_iCur-1);
00114 }
00115 
00116 template<typename Data>
00117 int DataBuffer<Data>::backwardSize()
00118 {
00119     return m_iCur;
00120 }
00121 
00122 template<typename Data>
00123 void DataBuffer<Data>::clear()
00124 {
00125     for(typename std::deque<Data*>::iterator it=m_dBuf.begin(); it!=m_dBuf.end(); ++it) {
00126         delete (*it);
00127     }
00128     m_dBuf.clear();
00129 }
00130 
00131 #endif
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Fri May 16 2014 09:50:18 for LafKernel by doxygen 1.7.4