• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

pkgid.h

Go to the documentation of this file.
00001 // -*- mode: c++; tab-width: 4; indent-tabs-mode: t -*-
00002 #ifndef EPT_DEBTAGS_PKGID_H
00003 #define EPT_DEBTAGS_PKGID_H
00004 
00010 /*
00011  * Copyright (C) 2003-2007  Enrico Zini <enrico@debian.org>
00012  *
00013  * This program is free software; you can redistribute it and/or modify
00014  * it under the terms of the GNU General Public License as published by
00015  * the Free Software Foundation; either version 2 of the License, or
00016  * (at your option) any later version.
00017  *
00018  * This program is distributed in the hope that it will be useful,
00019  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00020  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00021  * GNU General Public License for more details.
00022  *
00023  * You should have received a copy of the GNU General Public License
00024  * along with this program; if not, write to the Free Software
00025  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00026  */
00027 
00028 #include <tagcoll/diskindex/mmap.h>
00029 #include <string>
00030 
00031 namespace ept {
00032 namespace debtags {
00033 
00040 class PkgId : public tagcoll::diskindex::MMap
00041 {
00042     tagcoll::diskindex::MasterMMap mastermmap;
00043     time_t m_timestamp;
00044 
00045 public:
00046     PkgId();
00047     PkgId(const tagcoll::diskindex::MasterMMap& master, size_t idx);
00048     PkgId(const char* buf, int size);
00049 
00051     time_t timestamp() const { return m_timestamp; }
00052 
00054     size_t size() const { return m_buf ? *(int*)m_buf / sizeof(int) : 0; }
00055 
00061     int byName(const std::string& name) const;
00062 
00068     std::string byID(int id) const
00069     {
00070         if (id >= 0 || static_cast<unsigned>(id) < size())
00071             return std::string(m_buf + ((int*)m_buf)[id]);
00072         return std::string();
00073     }
00074 
00076     int size(int id) const
00077     {
00078         if (id < 0 || (unsigned)id >= size())
00079             return 0;
00080         if ((unsigned)id == size() - 1)
00081             return m_size - ((int*)m_buf)[id] - 1;
00082         else
00083             return ((int*)m_buf)[id + 1] - ((int*)m_buf)[id] - 1;
00084     }
00085 };
00086 
00087 }
00088 }
00089 
00090 // vim:set ts=4 sw=4:
00091 #endif

Generated on Fri Oct 14 2011 17:41:02 for libept by  doxygen 1.7.1