]> git.saurik.com Git - apt.git/blame - apt-pkg/pkgrecords.cc
* renamed Trust-CDROM to TrustCDROM to make it consistent with ubuntu
[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 /*{{{*/
12#ifdef __GNUG__
13#pragma implementation "apt-pkg/pkgrecords.h"
14#endif
15#include <apt-pkg/pkgrecords.h>
b2e465d6 16#include <apt-pkg/indexfile.h>
f55ece0e 17#include <apt-pkg/error.h>
3164dff9 18#include <apt-pkg/configuration.h>
b2e465d6
AL
19
20#include <apti18n.h>
f55ece0e
AL
21 /*}}}*/
22
23// Records::pkgRecords - Constructor /*{{{*/
24// ---------------------------------------------------------------------
25/* This will create the necessary structures to access the status files */
26pkgRecords::pkgRecords(pkgCache &Cache) : Cache(Cache), Files(0)
27{
b2e465d6
AL
28 Files = new Parser *[Cache.HeaderP->PackageFileCount];
29 memset(Files,0,sizeof(*Files)*Cache.HeaderP->PackageFileCount);
30
f55ece0e
AL
31 for (pkgCache::PkgFileIterator I = Cache.FileBegin();
32 I.end() == false; I++)
33 {
b2e465d6
AL
34 const pkgIndexFile::Type *Type = pkgIndexFile::Type::GetType(I.IndexType());
35 if (Type == 0)
3164dff9 36 {
b2e465d6 37 _error->Error(_("Index file type '%s' is not supported"),I.IndexType());
3164dff9
AL
38 return;
39 }
b2e465d6
AL
40
41 Files[I->ID] = Type->CreatePkgParser(I);
42 if (Files[I->ID] == 0)
f55ece0e
AL
43 return;
44 }
14cd494a
MV
45 // We store that to make sure that the destructor won't segfault,
46 // even if the Cache object was destructed before this instance.
47 PackageFileCount = Cache.HeaderP->PackageFileCount;
f55ece0e
AL
48}
49 /*}}}*/
50// Records::~pkgRecords - Destructor /*{{{*/
51// ---------------------------------------------------------------------
52/* */
53pkgRecords::~pkgRecords()
54{
14cd494a 55 for (unsigned I = 0; I != PackageFileCount; I++)
b2e465d6 56 delete Files[I];
f55ece0e
AL
57 delete [] Files;
58}
59 /*}}}*/
60// Records::Lookup - Get a parser for the package version file /*{{{*/
61// ---------------------------------------------------------------------
62/* */
03e39e59
AL
63pkgRecords::Parser &pkgRecords::Lookup(pkgCache::VerFileIterator const &Ver)
64{
b2e465d6
AL
65 Files[Ver.File()->ID]->Jump(Ver);
66 return *Files[Ver.File()->ID];
f55ece0e
AL
67}
68 /*}}}*/