pkgrecords.cc 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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<config.h>
  11. #include <apt-pkg/pkgrecords.h>
  12. #include <apt-pkg/indexfile.h>
  13. #include <apt-pkg/error.h>
  14. #include <apt-pkg/pkgcache.h>
  15. #include <apt-pkg/cacheiterators.h>
  16. #include <stddef.h>
  17. #include <vector>
  18. #include <apti18n.h>
  19. /*}}}*/
  20. // Records::pkgRecords - Constructor /*{{{*/
  21. // ---------------------------------------------------------------------
  22. /* This will create the necessary structures to access the status files */
  23. pkgRecords::pkgRecords(pkgCache &aCache) : d(NULL), Cache(aCache),
  24. Files(Cache.HeaderP->PackageFileCount)
  25. {
  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. }
  40. /*}}}*/
  41. // Records::~pkgRecords - Destructor /*{{{*/
  42. // ---------------------------------------------------------------------
  43. /* */
  44. pkgRecords::~pkgRecords()
  45. {
  46. for ( std::vector<Parser*>::iterator it = Files.begin();
  47. it != Files.end();
  48. ++it)
  49. {
  50. delete *it;
  51. }
  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. /*}}}*/
  63. // Records::Lookup - Get a parser for the package description file /*{{{*/
  64. // ---------------------------------------------------------------------
  65. /* */
  66. pkgRecords::Parser &pkgRecords::Lookup(pkgCache::DescFileIterator const &Desc)
  67. {
  68. Files[Desc.File()->ID]->Jump(Desc);
  69. return *Files[Desc.File()->ID];
  70. }
  71. /*}}}*/
  72. pkgRecords::Parser::Parser() : d(NULL) {}
  73. pkgRecords::Parser::~Parser() {}