00001
00011 #ifndef _BUFFER_H
00012 #define _BUFFER_H
00013
00014 #include <list>
00015
00016 #include <utility>
00017
00018
00019 #include "config.h"
00020
00021 #include "parser.h"
00022
00023 #include "stats.h"
00024
00025 namespace ace {
00026
00032 typedef std::pair<words_store_t::const_iterator, words_store_t::const_iterator> words_range_t;
00033
00040 class Buffer {
00041
00045 typedef std::pair<size_t, size_t> sentence_index_t;
00049 typedef std::list<sentence_index_t> sentences_indices_t;
00050
00053 Parser& _parser;
00056 words_store_t _words;
00059 sentences_indices_t _sentences;
00063 sentences_indices_t::iterator _current;
00066 const ContextWindow _context_window;
00069 DataFileStats _stats;
00074 inline size_t _index_of(words_store_t::const_iterator iter) const { return iter - _words.begin(); }
00078 void _init(void);
00082 size_t _pop(void);
00089 void _push(size_t needed = 1, ContextWindow::Mode context_window_mode = ContextWindow::SENTENCE_MODE);
00090
00091 public:
00097 Buffer(Parser& parser, ContextWindow context_window): _parser(parser), _words(), _sentences(), _current(), _context_window(context_window), _stats() {
00098 _init();
00099 }
00102 inline words_range_t context_range(void) const { return words_range_t(_words.begin(), _words.end()); }
00107 inline words_range_t context_range(words_store_t::const_iterator head) const { return context_range(head, head); }
00113 words_range_t context_range(words_store_t::const_iterator left, words_store_t::const_iterator right) const;
00116 inline bool empty(void) const { return _words.empty(); }
00121 bool next(void);
00124 words_range_t current(void) const;
00127 inline DataFileStats stats(void) const { return _stats; }
00128 };
00129
00130 }
00131
00132 #endif