xref: /haiku/headers/os/package/PackageVersion.h (revision 02354704729d38c3b078c696adc1bbbd33cbcf72)
1 /*
2  * Copyright 2011, Haiku, Inc.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef _PACKAGE__PACKAGE_VERSION_H_
6 #define _PACKAGE__PACKAGE_VERSION_H_
7 
8 
9 #include <String.h>
10 
11 
12 namespace BPackageKit {
13 
14 
15 namespace BHPKG {
16 	struct BPackageVersionData;
17 }
18 using BHPKG::BPackageVersionData;
19 
20 
21 class BPackageVersion {
22 public:
23 								BPackageVersion();
24 								BPackageVersion(
25 									const BPackageVersionData& data);
26 	explicit					BPackageVersion(const BString& versionString,
27 									bool revisionIsOptional = true);
28 								BPackageVersion(const BString& major,
29 									const BString& minor, const BString& micro,
30 									const BString& preRelease, uint32 revision);
31 
32 			status_t			InitCheck() const;
33 
34 			const BString&		Major() const;
35 			const BString&		Minor() const;
36 			const BString&		Micro() const;
37 			const BString&		PreRelease() const;
38 									// "alpha3", "beta2", "rc1" or "" if final
39 			uint32				Revision() const;
40 
41 			BString				ToString() const;
42 
43 			void				SetTo(const BString& major,
44 									const BString& minor, const BString& micro,
45 									const BString& preRelease, uint32 revision);
46 			status_t			SetTo(const BString& versionString,
47 									bool revisionIsOptional = true);
48 			void				Clear();
49 
50 			int					Compare(const BPackageVersion& other) const;
51 									// does a natural compare over major, minor
52 									// and micro, finally comparing revision
53 
54 	inline	bool				operator==(const BPackageVersion& other) const;
55 	inline	bool				operator!=(const BPackageVersion& other) const;
56 	inline	bool				operator<(const BPackageVersion& other) const;
57 	inline	bool				operator>(const BPackageVersion& other) const;
58 	inline	bool				operator<=(const BPackageVersion& other) const;
59 	inline	bool				operator>=(const BPackageVersion& other) const;
60 
61 private:
62 			BString				fMajor;
63 			BString				fMinor;
64 			BString				fMicro;
65 			BString				fPreRelease;
66 			uint32				fRevision;
67 };
68 
69 
70 inline bool
71 BPackageVersion::operator==(const BPackageVersion& other) const
72 {
73 	return Compare(other) == 0;
74 }
75 
76 
77 inline bool
78 BPackageVersion::operator!=(const BPackageVersion& other) const
79 {
80 	return Compare(other) != 0;
81 }
82 
83 
84 inline bool
85 BPackageVersion::operator<(const BPackageVersion& other) const
86 {
87 	return Compare(other) < 0;
88 }
89 
90 
91 inline bool
92 BPackageVersion::operator>(const BPackageVersion& other) const
93 {
94 	return Compare(other) > 0;
95 }
96 
97 
98 inline bool
99 BPackageVersion::operator<=(const BPackageVersion& other) const
100 {
101 	return Compare(other) <= 0;
102 }
103 
104 
105 inline bool
106 BPackageVersion::operator>=(const BPackageVersion& other) const
107 {
108 	return Compare(other) >= 0;
109 }
110 
111 
112 }	// namespace BPackageKit
113 
114 
115 #endif	// _PACKAGE__PACKAGE_VERSION_H_
116