]> git.saurik.com Git - apt.git/blob - apt-pkg/pkgrecords.cc
a7dec76a7a82ba16d6670064f30c2b41f7d24fda
[apt.git] / apt-pkg / pkgrecords.cc
1 // -*- mode: cpp; mode: fold -*-
2 // Description /*{{{*/
3 // $Id: pkgrecords.cc,v 1.7 2003/09/02 04:46:18 mdz Exp $
4 /* ######################################################################
5
6 Package Records - Allows access to complete package description records
7 directly from the file.
8
9 ##################################################################### */
10 /*}}}*/
11 // Include Files /*{{{*/
12 #ifdef __GNUG__
13 #pragma implementation "apt-pkg/pkgrecords.h"
14 #endif
15 #include <apt-pkg/pkgrecords.h>
16 #include <apt-pkg/indexfile.h>
17 #include <apt-pkg/error.h>
18 #include <apt-pkg/configuration.h>
19
20 #include <apti18n.h>
21 /*}}}*/
22
23 // Records::pkgRecords - Constructor /*{{{*/
24 // ---------------------------------------------------------------------
25 /* This will create the necessary structures to access the status files */
26 pkgRecords::pkgRecords(pkgCache &Cache) : Cache(Cache), Files(0)
27 {
28 Files = new Parser *[Cache.HeaderP->PackageFileCount];
29 memset(Files,0,sizeof(*Files)*Cache.HeaderP->PackageFileCount);
30
31 for (pkgCache::PkgFileIterator I = Cache.FileBegin();
32 I.end() == false; I++)
33 {
34 const pkgIndexFile::Type *Type = pkgIndexFile::Type::GetType(I.IndexType());
35 if (Type == 0)
36 {
37 _error->Error(_("Index file type '%s' is not supported"),I.IndexType());
38 return;
39 }
40
41 Files[I->ID] = Type->CreatePkgParser(I);
42 if (Files[I->ID] == 0)
43 return;
44 }
45
46 // We store this to make sure that the destructor won't segfault,
47 // even if the Cache object was destructed before this instance.
48 PackageFileCount = Cache.HeaderP->PackageFileCount;
49 }
50 /*}}}*/
51 // Records::~pkgRecords - Destructor /*{{{*/
52 // ---------------------------------------------------------------------
53 /* */
54 pkgRecords::~pkgRecords()
55 {
56 for (unsigned I = 0; I != PackageFileCount; I++)
57 delete Files[I];
58 delete [] Files;
59 }
60 /*}}}*/
61 // Records::Lookup - Get a parser for the package version file /*{{{*/
62 // ---------------------------------------------------------------------
63 /* */
64 pkgRecords::Parser &pkgRecords::Lookup(pkgCache::VerFileIterator const &Ver)
65 {
66 Files[Ver.File()->ID]->Jump(Ver);
67 return *Files[Ver.File()->ID];
68 }
69 /*}}}*/