]> git.saurik.com Git - apt.git/blame - apt-pkg/pkgrecords.cc
* cmdline/apt-get.cc:
[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 */
23pkgRecords::pkgRecords(pkgCache &Cache) : Cache(Cache), Files(0)
24{
b2e465d6
AL
25 Files = new Parser *[Cache.HeaderP->PackageFileCount];
26 memset(Files,0,sizeof(*Files)*Cache.HeaderP->PackageFileCount);
27
f55ece0e
AL
28 for (pkgCache::PkgFileIterator I = Cache.FileBegin();
29 I.end() == false; I++)
30 {
b2e465d6
AL
31 const pkgIndexFile::Type *Type = pkgIndexFile::Type::GetType(I.IndexType());
32 if (Type == 0)
3164dff9 33 {
b2e465d6 34 _error->Error(_("Index file type '%s' is not supported"),I.IndexType());
3164dff9
AL
35 return;
36 }
b2e465d6
AL
37
38 Files[I->ID] = Type->CreatePkgParser(I);
39 if (Files[I->ID] == 0)
f55ece0e
AL
40 return;
41 }
42}
43 /*}}}*/
44// Records::~pkgRecords - Destructor /*{{{*/
45// ---------------------------------------------------------------------
46/* */
47pkgRecords::~pkgRecords()
48{
960d4d24 49 for (unsigned I = 0; I != Cache.HeaderP->PackageFileCount; I++)
b2e465d6 50 delete Files[I];
f55ece0e
AL
51 delete [] Files;
52}
53 /*}}}*/
54// Records::Lookup - Get a parser for the package version file /*{{{*/
55// ---------------------------------------------------------------------
56/* */
03e39e59
AL
57pkgRecords::Parser &pkgRecords::Lookup(pkgCache::VerFileIterator const &Ver)
58{
b2e465d6
AL
59 Files[Ver.File()->ID]->Jump(Ver);
60 return *Files[Ver.File()->ID];
f55ece0e
AL
61}
62 /*}}}*/
a52f938b
OS
63// Records::Lookup - Get a parser for the package description file /*{{{*/
64// ---------------------------------------------------------------------
65/* */
66pkgRecords::Parser &pkgRecords::Lookup(pkgCache::DescFileIterator const &Desc)
67{
68 Files[Desc.File()->ID]->Jump(Desc);
69 return *Files[Desc.File()->ID];
70}
71 /*}}}*/