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