MMapIndex.h

Go to the documentation of this file.
00001 #ifndef TAGCOLL_MMAPINDEX_H
00002 #define TAGCOLL_MMAPINDEX_H
00003 
00008 /*
00009  * Copyright (C) 2006  Enrico Zini <enrico@debian.org>
00010  *
00011  * This program is free software; you can redistribute it and/or modify
00012  * it under the terms of the GNU General Public License as published by
00013  * the Free Software Foundation; either version 2 of the License, or
00014  * (at your option) any later version.
00015  *
00016  * This program is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU General Public License
00022  * along with this program; if not, write to the Free Software
00023  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00024  */
00025 
00026 #include <tagcoll/Exception.h>
00027 #include <vector>
00028 #include <set>
00029 
00030 namespace Tagcoll
00031 {
00032 
00033 class MMapIndex;
00034 
00046 class MasterMMapIndex
00047 {
00048 protected:
00049     std::string m_filename;
00050     size_t m_size;
00051     int m_fd;
00052     const char* m_buf;
00053 
00054 public:
00055     MasterMMapIndex();
00056     MasterMMapIndex(const std::string& filename);
00057     ~MasterMMapIndex();
00058 
00059     void init(const std::string& filename);
00060     
00061     friend class MMapIndex;
00062 };
00063 
00064 class MMapIndex
00065 {
00066 protected:
00067     const MasterMMapIndex* m_master;
00068     const char* m_buf;
00069     size_t m_size;
00070 
00071 public:
00072     MMapIndex();
00073     MMapIndex(const char* buf, int size);
00074     MMapIndex(const MasterMMapIndex& master, size_t idx);
00075 
00076     void init(const char* buf, int size);
00077     void init(const MasterMMapIndex& master, size_t idx);
00078 
00080     template<class INT>
00081     static inline INT align(INT val)
00082     {
00083         return (val + sizeof(int) - 1) & ~(sizeof(int) - 1);
00084     }
00085 };
00086 
00090 class MMapIndexer
00091 {
00092 public:
00093     virtual ~MMapIndexer() {}
00094 
00096     virtual int encodedSize() const = 0;
00097 
00100     virtual void encode(char* buf) const = 0;
00101 };
00102 
00108 class MasterMMapIndexer
00109 {
00110 protected:
00111     std::string finalname;
00112     std::string tmpname;
00113     int fd;
00114 
00115 public:
00116     MasterMMapIndexer(const std::string& filename);
00117     ~MasterMMapIndexer();
00118 
00120     void commit();
00121 
00123     void append(const MMapIndexer& idx);
00124 };
00125 
00126 
00127 };
00128 
00129 // vim:set ts=4 sw=4:
00130 #endif

Generated on Sat Jan 17 03:28:53 2009 for libtagcoll by  doxygen 1.5.1