]>
Commit | Line | Data |
---|---|---|
7939f6d1 RC |
1 | /* |
2 | * Copyright (c) 2001, Robert Collins. | |
3 | * | |
4 | * This program is free software; you can redistribute it and/or modify | |
5 | * it under the terms of the GNU General Public License as published by | |
6 | * the Free Software Foundation; either version 2 of the License, or | |
7 | * (at your option) any later version. | |
8 | * | |
9 | * A copy of the GNU General Public License can be found at | |
10 | * http://www.gnu.org/ | |
11 | * | |
12 | * Written by Robert Collins <rbtcollins@hotmail.com> | |
13 | * | |
14 | */ | |
15 | ||
16 | #ifndef _PACKAGE_META_H_ | |
17 | #define _PACKAGE_META_H_ | |
18 | ||
97647369 RC |
19 | /* Used for selecting a given 'trust' level */ |
20 | typedef enum | |
21 | { | |
22 | TRUST_UNKNOWN, | |
23 | TRUST_PREV, | |
24 | TRUST_CURR, | |
25 | TRUST_TEST, | |
26 | NTRUST | |
27 | } | |
28 | trusts; | |
29 | ||
fa0c0d10 | 30 | class packageversion; |
bb849dbd | 31 | class packagemeta; |
4fe323f9 | 32 | class category; |
7939f6d1 | 33 | |
bb849dbd | 34 | /* Required to parse this completely */ |
bb849dbd | 35 | #include "list.h" |
3c054baf | 36 | #include "String++.h" |
4fe323f9 | 37 | #include "category.h" |
bb849dbd RC |
38 | |
39 | /* | |
40 | For cleanliness this may need to be put in its own file later. */ | |
41 | class CategoryPackage | |
42 | { | |
43 | public: | |
4fe323f9 | 44 | CategoryPackage (Category & cat):key (cat), pkg (0) |
bb849dbd | 45 | { |
4fe323f9 RC |
46 | next = cat.packages; |
47 | cat.packages = this; | |
bb849dbd | 48 | }; |
4fe323f9 | 49 | Category & key; |
bb849dbd | 50 | CategoryPackage *next; /* The next package pointer in the list */ |
4fe323f9 | 51 | packagemeta *pkg; |
bb849dbd RC |
52 | }; |
53 | ||
54 | ||
55 | /* NOTE: A packagemeta without 1 packageversion is invalid! */ | |
7939f6d1 RC |
56 | class packagemeta |
57 | { | |
58 | public: | |
3c054baf | 59 | packagemeta (String const &pkgname):name (pkgname), key(pkgname), installed_from (0), |
bb849dbd RC |
60 | //versions (0), |
61 | // versioncount (0), versionspace (0), | |
62 | installed (0), prev (0), prevtimestamp (0), curr (0), currtimestamp (0), | |
63 | exp (0), exptimestamp (0), desired (0) | |
7939f6d1 | 64 | { |
3c054baf | 65 | } |
fa0c0d10 | 66 | |
3c054baf RC |
67 | packagemeta (String const &pkgname, |
68 | String const &installedfrom):name (pkgname), key(pkgname), | |
69 | installed_from (installedfrom), | |
bb849dbd RC |
70 | //versions (0), versioncount (0), versionspace (0), |
71 | ||
72 | installed (0), prev (0), prevtimestamp (0), curr (0), currtimestamp (0), | |
73 | exp (0), exptimestamp (0), desired (0) | |
fa0c0d10 | 74 | { |
fa0c0d10 RC |
75 | }; |
76 | ||
7939f6d1 RC |
77 | ~packagemeta () |
78 | { | |
7939f6d1 RC |
79 | }; |
80 | ||
fa0c0d10 RC |
81 | void add_version (packageversion &); |
82 | void set_installed (packageversion &); | |
7e8fc33c RC |
83 | |
84 | class _actions | |
85 | { | |
86 | public: | |
87 | _actions ():_value (0) {}; | |
88 | _actions (int aInt) { | |
89 | _value = aInt; | |
90 | if (_value < 0 || _value > 3) | |
91 | _value = 0; | |
92 | } | |
93 | _actions & operator ++ (); | |
94 | bool operator == (_actions const &rhs) { return _value == rhs._value; } | |
95 | bool operator != (_actions const &rhs) { return _value != rhs._value; } | |
96 | const char *caption (); | |
97 | private: | |
98 | int _value; | |
99 | }; | |
100 | static const _actions Default_action; | |
101 | static const _actions Install_action; | |
102 | static const _actions Reinstall_action; | |
103 | static const _actions Uninstall_action; | |
cbfc4215 | 104 | void set_action (packageversion *default_version); |
7e8fc33c | 105 | void set_action (_actions, packageversion * default_version); |
fa0c0d10 | 106 | void uninstall (); |
97647369 | 107 | int set_requirements (trusts deftrust = TRUST_CURR, size_t depth = 0); |
7939f6d1 | 108 | |
3c054baf | 109 | String action_caption (); |
97647369 RC |
110 | packageversion * trustp (trusts const t) const |
111 | { | |
112 | return t == TRUST_PREV ? (prev ? prev : (curr ? curr : installed)) | |
113 | : t == TRUST_CURR ? (curr ? curr : installed) | |
114 | : exp; | |
115 | } | |
cbfc4215 | 116 | |
3c054baf RC |
117 | String name; /* package name, like "cygwin" */ |
118 | String key; | |
fa0c0d10 | 119 | /* legacy variable used to output data for installed.db versions <= 2 */ |
3c054baf | 120 | String installed_from; |
bb849dbd RC |
121 | /* SDesc is global in theory, across all package versions. |
122 | LDesc is not: it can be different per version */ | |
3c054baf | 123 | String const SDesc () const; |
bb849dbd RC |
124 | /* what categories does this package belong in. Note that if multiple versions |
125 | * of a package disagree.... the first one read in will take precedence. | |
126 | */ | |
bb849dbd | 127 | void add_category (Category &); |
4fe323f9 | 128 | list < CategoryPackage, Category &, Categorycmp > Categories; |
fa0c0d10 | 129 | |
3c054baf | 130 | list < packageversion, String, String::casecompare > versions; |
7939f6d1 | 131 | /* which one is installed. */ |
fa0c0d10 | 132 | packageversion *installed; |
7939f6d1 | 133 | /* which one is listed as "prev" in our available packages db */ |
fa0c0d10 | 134 | packageversion *prev; |
bb849dbd RC |
135 | /* And what was the timestamp of the ini it was found from */ |
136 | unsigned int prevtimestamp; | |
7939f6d1 | 137 | /* ditto for current - stable */ |
fa0c0d10 | 138 | packageversion *curr; |
bb849dbd | 139 | unsigned int currtimestamp; |
7939f6d1 | 140 | /* and finally the experimental version */ |
fa0c0d10 | 141 | packageversion *exp; |
bb849dbd RC |
142 | unsigned int exptimestamp; |
143 | /* Now for the user stuff :] */ | |
144 | /* What version does the user want ? */ | |
145 | packageversion *desired; | |
7e8fc33c | 146 | |
cbfc4215 RC |
147 | protected: |
148 | packagemeta (packagemeta const &); | |
149 | packagemeta &operator= (packagemeta const &); | |
7939f6d1 RC |
150 | }; |
151 | ||
152 | #endif /* _PACKAGE_META_H_ */ |