00001
00002
00003
00004 #ifndef AITOOLS_INVERTEDINDEX_POSTLIST_READER_HPP
00005 #define AITOOLS_INVERTEDINDEX_POSTLIST_READER_HPP
00006
00007 #include "Iterator.hpp"
00008 #include "NonCopyable.hpp"
00009 #include <boost/shared_ptr.hpp>
00010 #include <climits>
00011
00012 namespace bfs = boost::filesystem;
00013
00014 namespace aitools {
00015 namespace invertedindex {
00016
00026 class PostlistReader : public NonCopyable {
00027
00028 public:
00029
00030 typedef boost::shared_ptr<PostlistReader> shared_pointer;
00031
00032 private:
00033
00034 static const size_t sizeof_value_size_t = Iterator::sizeof_value_size_t;
00035
00036 public:
00037
00041 PostlistReader();
00042
00046 PostlistReader(const bfs::path& path) throw (std::invalid_argument);
00047
00051 ~PostlistReader();
00052
00053 public:
00054
00055 void close();
00056
00057 inline bool is_open() const
00058 {
00059 return file_ != NULL;
00060 }
00061
00062 void open(const bfs::path& path)
00063 throw (std::runtime_error, std::invalid_argument);
00064
00065 Iterator::SharedPointer read(size_t length = INT_MAX)
00066 throw (std::runtime_error);
00067
00068 const bfs::path& path() const;
00069
00070 inline bool ready() const
00071 {
00072 return is_open() && std::feof(file_) == 0;
00073 }
00074
00075 void rewind();
00076
00077 void seek(size_t offset);
00078
00079 size_t tell();
00080
00081 private:
00082
00083 FILE* file_;
00084 bfs::path path_;
00085
00086 };
00087
00088 }
00089 }
00090
00091 #endif // AITOOLS_INVERTEDINDEX_POSTLIST_READER_HPP