]> git.saurik.com Git - apt.git/blob - apt-pkg/pkgrecords.cc
Random fixes..
[apt.git] / apt-pkg / pkgrecords.cc
1 // -*- mode: cpp; mode: fold -*-
2 // Description /*{{{*/
3 // $Id: pkgrecords.cc,v 1.5 1999/02/22 03:30:06 jgg 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/debrecords.h>
17 #include <apt-pkg/error.h>
18 #include <apt-pkg/configuration.h>
19 /*}}}*/
20
21 // Records::pkgRecords - Constructor /*{{{*/
22 // ---------------------------------------------------------------------
23 /* This will create the necessary structures to access the status files */
24 pkgRecords::pkgRecords(pkgCache &Cache) : Cache(Cache), Files(0)
25 {
26 Files = new PkgFile[Cache.HeaderP->PackageFileCount];
27 for (pkgCache::PkgFileIterator I = Cache.FileBegin();
28 I.end() == false; I++)
29 {
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
38 Files[I->ID].File = new FileFd(I.FileName(),FileFd::ReadOnly);
39 if (_error->PendingError() == true)
40 return;
41
42 // Create the parser
43 Files[I->ID].Parse = new debRecordParser(*Files[I->ID].File,Cache);
44 if (_error->PendingError() == true)
45 return;
46 }
47 }
48 /*}}}*/
49 // Records::~pkgRecords - Destructor /*{{{*/
50 // ---------------------------------------------------------------------
51 /* */
52 pkgRecords::~pkgRecords()
53 {
54 delete [] Files;
55 }
56 /*}}}*/
57 // Records::Lookup - Get a parser for the package version file /*{{{*/
58 // ---------------------------------------------------------------------
59 /* */
60 pkgRecords::Parser &pkgRecords::Lookup(pkgCache::VerFileIterator const &Ver)
61 {
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 /* */
71 pkgRecords::PkgFile::~PkgFile()
72 {
73 delete Parse;
74 delete File;
75 }
76 /*}}}*/