Few more stats
[ntk/apt.git] / apt-pkg / pkgrecords.cc
CommitLineData
f55ece0e
AL
1// -*- mode: cpp; mode: fold -*-
2// Description /*{{{*/
03e39e59 3// $Id: pkgrecords.cc,v 1.4 1998/11/13 04:23:34 jgg 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>
16#include <apt-pkg/debrecords.h>
17#include <apt-pkg/error.h>
3164dff9 18#include <apt-pkg/configuration.h>
f55ece0e
AL
19 /*}}}*/
20
21// Records::pkgRecords - Constructor /*{{{*/
22// ---------------------------------------------------------------------
23/* This will create the necessary structures to access the status files */
24pkgRecords::pkgRecords(pkgCache &Cache) : Cache(Cache), Files(0)
25{
03e39e59 26 Files = new PkgFile[Cache.HeaderP->PackageFileCount];
f55ece0e
AL
27 for (pkgCache::PkgFileIterator I = Cache.FileBegin();
28 I.end() == false; I++)
29 {
3164dff9
AL
30 // We can not initialize if the cache is out of sync.
31 if (I.IsOk() == false)
32 {
33 _error->Error("Package file %s is out of sync.",I.FileName());
34 return;
35 }
36
37 // Create the file
03e39e59 38 Files[I->ID].File = new FileFd(I.FileName(),FileFd::ReadOnly);
f55ece0e
AL
39 if (_error->PendingError() == true)
40 return;
3164dff9
AL
41
42 // Create the parser
f55ece0e
AL
43 Files[I->ID].Parse = new debRecordParser(*Files[I->ID].File);
44 if (_error->PendingError() == true)
45 return;
46 }
47}
48 /*}}}*/
49// Records::~pkgRecords - Destructor /*{{{*/
50// ---------------------------------------------------------------------
51/* */
52pkgRecords::~pkgRecords()
53{
54 delete [] Files;
55}
56 /*}}}*/
57// Records::Lookup - Get a parser for the package version file /*{{{*/
58// ---------------------------------------------------------------------
59/* */
03e39e59
AL
60pkgRecords::Parser &pkgRecords::Lookup(pkgCache::VerFileIterator const &Ver)
61{
f55ece0e
AL
62 PkgFile &File = Files[Ver.File()->ID];
63 File.Parse->Jump(Ver);
64
65 return *File.Parse;
66}
67 /*}}}*/
68// Records::Pkgfile::~PkgFile - Destructor /*{{{*/
69// ---------------------------------------------------------------------
70/* */
71pkgRecords::PkgFile::~PkgFile()
72{
73 delete Parse;
74 delete File;
75}
76 /*}}}*/