Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

SimpleBufferedDFDecoder.hpp

Go to the documentation of this file.
00001 #ifndef SimpleBufferedDFDecoder_HPP
00002 #define SimpleBufferedDFDecoder_HPP
00003 
00008 #include "io/output/BufferedOutput.hpp"  
00009 #include "io/codec/decoder/SimpleDecoderBase.hpp"  
00010 #include "util/Formatter.hpp"  
00011 #include "io/FDRepr.hpp"  
00012 
00013 template <class FR = FDRepr>
00014 class SimpleBufferedDFDecoder : 
00015    public SimpleDecoderBase< BufferedOutput<FR> >
00016 {
00017    protected:
00018       typedef SimpleDecoderBase< BufferedOutput<FR> > PARENT;
00019    public:
00020       typedef typename SimpleDecoderBase< BufferedOutput<FR> >::params_t params_t;
00021       SimpleBufferedDFDecoder(const params_t* par)
00022          : PARENT(par)
00023       {positions.push(0);}
00024 
00025       static bool DINLINE isDFO()
00026       {
00027          return true;
00028       }  
00029 
00030       void pushItem(const item_t item);
00031 
00032       void write(counter_t support);
00033 
00034       void pushItemWithWrite(item_t item, counter_t support)
00035       {
00036          pushItem(item);
00037          write(support);            
00038       }
00039          
00040       void pushItemWithPrevSupport(item_t item)
00041       {
00042          pushItemWithWrite(item, last_support);
00043       }
00044          
00045       void popItem()
00046       {
00047          assert(!positions.empty());
00048          positions.pop();
00049       }
00050       void popAll()
00051       {
00052          while( !positions.empty() )
00053             positions.pop();
00054          positions.push(0);
00055       }
00056 
00057    private:
00058       std::stack<std::streamsize> positions;
00059       counter_t last_support;
00060 
00061 };
00062 template <class FR> inline void
00063 SimpleBufferedDFDecoder<FR>::pushItem(const item_t item)
00064 {
00065    register std::streamsize pos = positions.top();
00066    Formatter::IntToStringFront(PARENT::code_inverse[item], PARENT::buffer, pos);
00067    PARENT::buffer[pos++] = ' ';
00068    positions.push(pos);
00069 }
00070 template <class FR> inline void
00071 SimpleBufferedDFDecoder<FR>::write(counter_t support)
00072 {
00073    last_support = support;
00074    register std::streamsize pos = positions.top();
00075    PARENT::buffer[pos++] = '(';
00076    Formatter::IntToStringFront(support, PARENT::buffer, pos);
00077    PARENT::buffer[pos++] = ')';
00078    PARENT::buffer[pos++] = '\n';
00079    writeToFile( PARENT::buffer, pos );
00080 }
00081 #endif

Generated on Sun Sep 17 17:50:39 2006 for FIM environment by  doxygen 1.4.4