pkgrecords.cc 2.3 KB

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