pkgsystem.cc 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: pkgsystem.cc,v 1.3 2004/02/27 00:43:16 mdz Exp $
  4. /* ######################################################################
  5. System - Abstraction for running on different systems.
  6. Basic general structure..
  7. ##################################################################### */
  8. /*}}}*/
  9. // Include Files /*{{{*/
  10. #include<config.h>
  11. #include <apt-pkg/debsystem.h>
  12. #include <apt-pkg/pkgsystem.h>
  13. #include <apt-pkg/macros.h>
  14. #include <map>
  15. #include <cassert>
  16. #include <cstring>
  17. /*}}}*/
  18. pkgSystem *_system = 0;
  19. static pkgSystem *SysList[10];
  20. pkgSystem **pkgSystem::GlobalList = SysList;
  21. unsigned long pkgSystem::GlobalListLen = 0;
  22. class APT_HIDDEN pkgSystemPrivate /*{{{*/
  23. {
  24. public:
  25. typedef decltype(pkgCache::Version::ID) idtype;
  26. std::map<idtype,idtype> idmap;
  27. pkgSystemPrivate() {}
  28. };
  29. /*}}}*/
  30. // System::pkgSystem - Constructor /*{{{*/
  31. // ---------------------------------------------------------------------
  32. /* Add it to the global list.. */
  33. pkgSystem::pkgSystem(char const * const label, pkgVersioningSystem * const vs) :
  34. Label(label), VS(vs), d(new pkgSystemPrivate())
  35. {
  36. assert(GlobalListLen < sizeof(SysList)/sizeof(*SysList));
  37. SysList[GlobalListLen] = this;
  38. ++GlobalListLen;
  39. }
  40. /*}}}*/
  41. // System::GetSystem - Get the named system /*{{{*/
  42. // ---------------------------------------------------------------------
  43. /* */
  44. APT_PURE pkgSystem *pkgSystem::GetSystem(const char *Label)
  45. {
  46. for (unsigned I = 0; I != GlobalListLen; I++)
  47. if (strcmp(SysList[I]->Label,Label) == 0)
  48. return SysList[I];
  49. return 0;
  50. }
  51. /*}}}*/
  52. bool pkgSystem::MultiArchSupported() const /*{{{*/
  53. {
  54. debSystem const * const deb = dynamic_cast<debSystem const *>(this);
  55. if (deb != NULL)
  56. return deb->SupportsMultiArch();
  57. return true;
  58. }
  59. /*}}}*/
  60. std::vector<std::string> pkgSystem::ArchitecturesSupported() const /*{{{*/
  61. {
  62. debSystem const * const deb = dynamic_cast<debSystem const *>(this);
  63. if (deb != NULL)
  64. return deb->SupportedArchitectures();
  65. return {};
  66. }
  67. /*}}}*/
  68. // pkgSystem::Set/GetVersionMapping - for internal/external communcation/*{{{*/
  69. void pkgSystem::SetVersionMapping(map_id_t const in, map_id_t const out)
  70. {
  71. if (in == out)
  72. return;
  73. d->idmap.emplace(in, out);
  74. }
  75. map_id_t pkgSystem::GetVersionMapping(map_id_t const in) const
  76. {
  77. auto const o = d->idmap.find(in);
  78. return (o == d->idmap.end()) ? in : o->second;
  79. }
  80. /*}}}*/
  81. pkgSystem::~pkgSystem() {}