]> git.mxchange.org Git - simgear.git/blob - simgear/package/Package.hxx
Update package classes ownership model.
[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 #include <simgear/structure/SGReferenced.hxx>
28 #include <simgear/structure/SGSharedPtr.hxx>
29
30 typedef std::set<std::string> string_set;
31
32 namespace simgear
33 {
34     
35 namespace pkg
36 {
37
38 // forward decls
39 class Install;
40 class Catalog;
41 class Package;
42   
43 typedef SGSharedPtr<Package> PackageRef;
44 typedef SGSharedPtr<Catalog> CatalogRef;
45 typedef SGSharedPtr<Install> InstallRef;
46
47 typedef std::vector<PackageRef> PackageList;
48     
49   class Package : public SGReferenced
50 {
51 public:
52     /**
53      * get or create an install for the package
54      */
55     InstallRef install();
56     
57     bool isInstalled() const;
58     
59     std::string id() const;
60     
61     /**
62      * human-readable name - note this is probably not localised,
63      * although this is not ruled out for the future.
64      */
65     std::string name() const;
66     
67     /**
68      * syntactic sugar to get the localised description
69      */
70     std::string description() const;
71     
72     /**
73      * access the raw property data in the package
74      */
75     SGPropertyNode* properties() const;
76     
77     /**
78      * hex-encoded MD5 sum of the download files
79      */
80     std::string md5() const;
81     
82     std::string getLocalisedProp(const std::string& aName) const;
83
84     unsigned int revision() const;
85     
86     CatalogRef catalog() const
87         { return m_catalog; }
88     
89     bool matches(const SGPropertyNode* aFilter) const;
90     
91     /**
92      * download URLs for the package
93      */
94     string_list downloadUrls() const;
95     
96     string_list thumbnailUrls() const;
97     
98     /**
99      * Packages we depend upon.
100      * If the dependency list cannot be satisifed for some reason,
101      * this will raise an sg_exception.
102      */
103     PackageList dependencies() const;
104 private:
105     friend class Catalog;
106     
107     Package(const SGPropertyNode* aProps, CatalogRef aCatalog);
108     
109     void initWithProps(const SGPropertyNode* aProps);
110     
111     std::string getLocalisedString(const SGPropertyNode* aRoot, const char* aName) const;
112     
113     SGPropertyNode_ptr m_props;
114     string_set m_tags;
115     CatalogRef m_catalog;
116 };
117
118
119
120
121 } // of namespace pkg
122
123 } // of namespace simgear
124
125 #endif // of SG_PACKAGE_PACKAGE_HXX
126