libept
pkgid.h
Go to the documentation of this file.
1 // -*- mode: c++; tab-width: 4; indent-tabs-mode: t -*-
2 #ifndef EPT_DEBTAGS_PKGID_H
3 #define EPT_DEBTAGS_PKGID_H
4 
10 /*
11  * Copyright (C) 2003-2007 Enrico Zini <enrico@debian.org>
12  *
13  * This program is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation; either version 2 of the License, or
16  * (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software
25  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26  */
27 
28 #include <tagcoll/diskindex/mmap.h>
29 #include <string>
30 
31 namespace ept {
32 namespace debtags {
33 
40 class PkgId : public tagcoll::diskindex::MMap
41 {
42  tagcoll::diskindex::MasterMMap mastermmap;
43  time_t m_timestamp;
44 
45 public:
46  PkgId();
47  PkgId(const tagcoll::diskindex::MasterMMap& master, size_t idx);
48  PkgId(const char* buf, int size);
49 
51  time_t timestamp() const { return m_timestamp; }
52 
54  size_t size() const { return m_buf ? *(int*)m_buf / sizeof(int) : 0; }
55 
61  int byName(const std::string& name) const;
62 
68  std::string byID(int id) const
69  {
70  if (id >= 0 || static_cast<unsigned>(id) < size())
71  return std::string(m_buf + ((int*)m_buf)[id]);
72  return std::string();
73  }
74 
76  int size(int id) const
77  {
78  if (id < 0 || (unsigned)id >= size())
79  return 0;
80  if ((unsigned)id == size() - 1)
81  return m_size - ((int*)m_buf)[id] - 1;
82  else
83  return ((int*)m_buf)[id + 1] - ((int*)m_buf)[id] - 1;
84  }
85 };
86 
87 }
88 }
89 
90 // vim:set ts=4 sw=4:
91 #endif