1 // Copyright (C) 2013 James Turner - zakalawe@mac.com
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.
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.
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.
18 #ifndef SG_PACKAGE_PACKAGE_HXX
19 #define SG_PACKAGE_PACKAGE_HXX
24 #include <simgear/props/props.hxx>
25 #include <simgear/misc/strutils.hxx>
27 #include <simgear/structure/SGReferenced.hxx>
28 #include <simgear/structure/SGSharedPtr.hxx>
30 typedef std::set<std::string> string_set;
43 typedef SGSharedPtr<Package> PackageRef;
44 typedef SGSharedPtr<Catalog> CatalogRef;
45 typedef SGSharedPtr<Install> InstallRef;
47 typedef std::vector<PackageRef> PackageList;
49 class Package : public SGReferenced
53 * get or create an install for the package
57 InstallRef existingInstall() const;
59 bool isInstalled() const;
61 std::string id() const;
64 * Variant IDs. Note the primary ID will always be included as
65 * variants()[0], to simplify enumerating all variants
67 string_list variants() const;
70 * Fully-qualified ID, including our catalog'd ID
72 std::string qualifiedId() const;
75 * human-readable name - note this is probably not localised,
76 * although this is not ruled out for the future.
78 std::string name() const;
81 * Human readable name of a variant
83 std::string nameForVariant(const std::string& vid) const;
86 * syntactic sugar to get the localised description
88 std::string description() const;
91 * access the raw property data in the package
93 SGPropertyNode* properties() const;
96 * hex-encoded MD5 sum of the download files
98 std::string md5() const;
100 std::string getLocalisedProp(const std::string& aName) const;
102 unsigned int revision() const;
104 size_t fileSizeBytes() const;
106 CatalogRef catalog() const
107 { return m_catalog; }
109 bool matches(const SGPropertyNode* aFilter) const;
112 * download URLs for the package
114 string_list downloadUrls() const;
116 string_list thumbnailUrls() const;
119 * Packages we depend upon.
120 * If the dependency list cannot be satisifed for some reason,
121 * this will raise an sg_exception.
123 PackageList dependencies() const;
125 SGPath pathOnDisk() const;
127 friend class Catalog;
129 Package(const SGPropertyNode* aProps, CatalogRef aCatalog);
131 void initWithProps(const SGPropertyNode* aProps);
133 void updateFromProps(const SGPropertyNode* aProps);
135 std::string getLocalisedString(const SGPropertyNode* aRoot, const char* aName) const;
137 SGPropertyNode_ptr m_props;
140 CatalogRef m_catalog;
146 } // of namespace pkg
148 } // of namespace simgear
150 #endif // of SG_PACKAGE_PACKAGE_HXX