]> cygwin.com Git - cygwin-apps/setup.git/blob - package_meta.h
2002-01-27 Robert Collins <rbtcollins@hotmail.com>
[cygwin-apps/setup.git] / package_meta.h
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
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
30 class packageversion;
31 class packagemeta;
32 class category;
33
34 /* Required to parse this completely */
35 #include "list.h"
36 #include "strings.h"
37 #include "category.h"
38
39 /*
40 For cleanliness this may need to be put in its own file later. */
41 class CategoryPackage
42 {
43 public:
44 CategoryPackage (Category & cat):key (cat), pkg (0)
45 {
46 next = cat.packages;
47 cat.packages = this;
48 };
49 Category & key;
50 CategoryPackage *next; /* The next package pointer in the list */
51 packagemeta *pkg;
52 };
53
54
55 /* NOTE: A packagemeta without 1 packageversion is invalid! */
56 class packagemeta
57 {
58 public:
59 packagemeta (char const *pkgname):installed_from (0),
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)
64 {
65 name = new char[strlen (pkgname) + 1];
66 strcpy (name, pkgname);
67 key = name;
68 };
69
70 packagemeta (char const *pkgname,
71 char const *installedfrom):installed_from (0),
72 //versions (0), versioncount (0), versionspace (0),
73
74 installed (0), prev (0), prevtimestamp (0), curr (0), currtimestamp (0),
75 exp (0), exptimestamp (0), desired (0)
76 {
77 name = new char[strlen (pkgname) + 1];
78 key = name;
79 strcpy (name, pkgname);
80 installed_from = new char[strlen (installedfrom) + 1];
81 strcpy (installed_from, installedfrom);
82 };
83
84 ~packagemeta ()
85 {
86 delete[] name;
87 if (installed_from)
88 delete[] installed_from;
89 };
90
91 void add_version (packageversion &);
92 void set_installed (packageversion &);
93
94 class _actions
95 {
96 public:
97 _actions ():_value (0) {};
98 _actions (int aInt) {
99 _value = aInt;
100 if (_value < 0 || _value > 3)
101 _value = 0;
102 }
103 _actions & operator ++ ();
104 bool operator == (_actions const &rhs) { return _value == rhs._value; }
105 bool operator != (_actions const &rhs) { return _value != rhs._value; }
106 const char *caption ();
107 private:
108 int _value;
109 };
110 static const _actions Default_action;
111 static const _actions Install_action;
112 static const _actions Reinstall_action;
113 static const _actions Uninstall_action;
114 void set_action (packageversion *default_version);
115 void set_action (_actions, packageversion * default_version);
116 void uninstall ();
117 int set_requirements (trusts deftrust = TRUST_CURR, size_t depth = 0);
118
119 char const *action_caption ();
120 packageversion * trustp (trusts const t) const
121 {
122 return t == TRUST_PREV ? (prev ? prev : (curr ? curr : installed))
123 : t == TRUST_CURR ? (curr ? curr : installed)
124 : exp;
125 }
126
127 char *name; /* package name, like "cygwin" */
128 char *key;
129 /* legacy variable used to output data for installed.db versions <= 2 */
130 char *installed_from;
131 /* SDesc is global in theory, across all package versions.
132 LDesc is not: it can be different per version */
133 char const *SDesc () const;
134 /* what categories does this package belong in. Note that if multiple versions
135 * of a package disagree.... the first one read in will take precedence.
136 */
137 void add_category (Category &);
138 list < CategoryPackage, Category &, Categorycmp > Categories;
139
140 list < packageversion, char const *, strcasecmp > versions;
141 /* which one is installed. */
142 packageversion *installed;
143 /* which one is listed as "prev" in our available packages db */
144 packageversion *prev;
145 /* And what was the timestamp of the ini it was found from */
146 unsigned int prevtimestamp;
147 /* ditto for current - stable */
148 packageversion *curr;
149 unsigned int currtimestamp;
150 /* and finally the experimental version */
151 packageversion *exp;
152 unsigned int exptimestamp;
153 /* Now for the user stuff :] */
154 /* What version does the user want ? */
155 packageversion *desired;
156
157 protected:
158 packagemeta (packagemeta const &);
159 packagemeta &operator= (packagemeta const &);
160 };
161
162 #endif /* _PACKAGE_META_H_ */
This page took 0.043581 seconds and 5 git commands to generate.