pkgrecords.cc 2.2 KB

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