pkgrecords.cc 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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),
  20. Files(Cache.HeaderP->PackageFileCount)
  21. {
  22. for (pkgCache::PkgFileIterator I = Cache.FileBegin();
  23. I.end() == false; I++)
  24. {
  25. const pkgIndexFile::Type *Type = pkgIndexFile::Type::GetType(I.IndexType());
  26. if (Type == 0)
  27. {
  28. _error->Error(_("Index file type '%s' is not supported"),I.IndexType());
  29. return;
  30. }
  31. Files[I->ID] = Type->CreatePkgParser(I);
  32. if (Files[I->ID] == 0)
  33. return;
  34. }
  35. }
  36. /*}}}*/
  37. // Records::~pkgRecords - Destructor /*{{{*/
  38. // ---------------------------------------------------------------------
  39. /* */
  40. pkgRecords::~pkgRecords()
  41. {
  42. for ( vector<Parser*>::iterator it = Files.begin();
  43. it != Files.end();
  44. ++it)
  45. {
  46. delete *it;
  47. }
  48. }
  49. /*}}}*/
  50. // Records::Lookup - Get a parser for the package version file /*{{{*/
  51. // ---------------------------------------------------------------------
  52. /* */
  53. pkgRecords::Parser &pkgRecords::Lookup(pkgCache::VerFileIterator const &Ver)
  54. {
  55. Files[Ver.File()->ID]->Jump(Ver);
  56. return *Files[Ver.File()->ID];
  57. }
  58. /*}}}*/
  59. // Records::Lookup - Get a parser for the package description file /*{{{*/
  60. // ---------------------------------------------------------------------
  61. /* */
  62. pkgRecords::Parser &pkgRecords::Lookup(pkgCache::DescFileIterator const &Desc)
  63. {
  64. Files[Desc.File()->ID]->Jump(Desc);
  65. return *Files[Desc.File()->ID];
  66. }
  67. /*}}}*/