pkgrecords.cc 2.3 KB

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