]> git.mxchange.org Git - simgear.git/blob - simgear/package/Package.hxx
Lots more work on package support.
[simgear.git] / simgear / package / Package.hxx
1 // Copyright (C) 2013  James Turner - zakalawe@mac.com
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Library General Public
5 // License as published by the Free Software Foundation; either
6 // version 2 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Library General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
16 //
17
18 #ifndef SG_PACKAGE_PACKAGE_HXX
19 #define SG_PACKAGE_PACKAGE_HXX
20
21 #include <set>
22 #include <vector>
23
24 #include <simgear/props/props.hxx>
25 #include <simgear/misc/strutils.hxx>
26
27 typedef std::set<std::string> string_set;
28
29 namespace simgear
30 {
31     
32 namespace pkg
33 {
34
35 // forward decls
36 class Install;
37 class Catalog;
38 class Package;
39
40 typedef std::vector<Package*> PackageList;
41     
42 class Package
43 {
44 public:
45     /**
46      * get or create an install for the package
47      */
48     Install* install();
49     
50     bool isInstalled() const;
51     
52     std::string id() const;
53     
54     /**
55      * syntactic sugar to get the localised description
56      */
57     std::string description() const;
58     
59     /**
60      * access the raw property data in the package
61      */
62     SGPropertyNode* properties() const;
63     
64     /**
65      * hex-encoded MD5 sum of the download files
66      */
67     std::string md5() const;
68     
69     std::string getLocalisedProp(const std::string& aName) const;
70
71     unsigned int revision() const;
72     
73     Catalog* catalog() const
74         { return m_catalog; }
75     
76     bool matches(const SGPropertyNode* aFilter) const;
77     
78     /**
79      * download URLs for the package
80      */
81     string_list downloadUrls() const;
82     
83     string_list thumbnailUrls() const;
84     
85     /**
86      * Packages we depend upon.
87      * If the dependency list cannot be satisifed for some reason,
88      * this will raise an sg_exception.
89      */
90     PackageList dependencies() const;
91 private:
92     friend class Catalog;
93     
94     Package(const SGPropertyNode* aProps, Catalog* aCatalog);
95     
96     void initWithProps(const SGPropertyNode* aProps);
97     
98     std::string getLocalisedString(const SGPropertyNode* aRoot, const char* aName) const;
99     
100     SGPropertyNode_ptr m_props;
101     string_set m_tags;
102     Catalog* m_catalog;
103 };
104
105
106
107
108 } // of namespace pkg
109
110 } // of namespace simgear
111
112 #endif // of SG_PACKAGE_PACKAGE_HXX
113