]> git.saurik.com Git - apt.git/blame - apt-pkg/pkgrecords.cc
* merged from main
[apt.git] / apt-pkg / pkgrecords.cc
CommitLineData
f55ece0e
AL
1// -*- mode: cpp; mode: fold -*-
2// Description /*{{{*/
f50d1cfa 3// $Id: pkgrecords.cc,v 1.8 2003/09/02 04:52:16 mdz Exp $
f55ece0e
AL
4/* ######################################################################
5
6 Package Records - Allows access to complete package description records
7 directly from the file.
8
9 ##################################################################### */
10 /*}}}*/
11// Include Files /*{{{*/
f55ece0e 12#include <apt-pkg/pkgrecords.h>
b2e465d6 13#include <apt-pkg/indexfile.h>
f55ece0e 14#include <apt-pkg/error.h>
3164dff9 15#include <apt-pkg/configuration.h>
b2e465d6
AL
16
17#include <apti18n.h>
f55ece0e
AL
18 /*}}}*/
19
20// Records::pkgRecords - Constructor /*{{{*/
21// ---------------------------------------------------------------------
22/* This will create the necessary structures to access the status files */
d715b9c9
MV
23pkgRecords::pkgRecords(pkgCache &Cache) : Cache(Cache),
24 Files(Cache.HeaderP->PackageFileCount)
f55ece0e 25{
f55ece0e
AL
26 for (pkgCache::PkgFileIterator I = Cache.FileBegin();
27 I.end() == false; I++)
28 {
b2e465d6
AL
29 const pkgIndexFile::Type *Type = pkgIndexFile::Type::GetType(I.IndexType());
30 if (Type == 0)
3164dff9 31 {
b2e465d6 32 _error->Error(_("Index file type '%s' is not supported"),I.IndexType());
3164dff9
AL
33 return;
34 }
b2e465d6
AL
35
36 Files[I->ID] = Type->CreatePkgParser(I);
37 if (Files[I->ID] == 0)
f55ece0e
AL
38 return;
39 }
40}
41 /*}}}*/
42// Records::~pkgRecords - Destructor /*{{{*/
43// ---------------------------------------------------------------------
44/* */
45pkgRecords::~pkgRecords()
46{
d715b9c9
MV
47 for ( vector<Parser*>::iterator it = Files.begin();
48 it != Files.end();
49 ++it)
50 {
51 delete *it;
52 }
53
f55ece0e
AL
54}
55 /*}}}*/
56// Records::Lookup - Get a parser for the package version file /*{{{*/
57// ---------------------------------------------------------------------
58/* */
03e39e59
AL
59pkgRecords::Parser &pkgRecords::Lookup(pkgCache::VerFileIterator const &Ver)
60{
b2e465d6
AL
61 Files[Ver.File()->ID]->Jump(Ver);
62 return *Files[Ver.File()->ID];
f55ece0e
AL
63}
64 /*}}}*/
a52f938b
OS
65// Records::Lookup - Get a parser for the package description file /*{{{*/
66// ---------------------------------------------------------------------
67/* */
68pkgRecords::Parser &pkgRecords::Lookup(pkgCache::DescFileIterator const &Desc)
69{
70 Files[Desc.File()->ID]->Jump(Desc);
71 return *Files[Desc.File()->ID];
72}
73 /*}}}*/