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
12namespace BPackageKit {
13
14
15namespace BHPKG {
16	struct BPackageVersionData;
17}
18using BHPKG::BPackageVersionData;
19
20
21class BPackageVersion {
22public:
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
61private:
62			BString				fMajor;
63			BString				fMinor;
64			BString				fMicro;
65			BString				fPreRelease;
66			uint32				fRevision;
67};
68
69
70inline bool
71BPackageVersion::operator==(const BPackageVersion& other) const
72{
73	return Compare(other) == 0;
74}
75
76
77inline bool
78BPackageVersion::operator!=(const BPackageVersion& other) const
79{
80	return Compare(other) != 0;
81}
82
83
84inline bool
85BPackageVersion::operator<(const BPackageVersion& other) const
86{
87	return Compare(other) < 0;
88}
89
90
91inline bool
92BPackageVersion::operator>(const BPackageVersion& other) const
93{
94	return Compare(other) > 0;
95}
96
97
98inline bool
99BPackageVersion::operator<=(const BPackageVersion& other) const
100{
101	return Compare(other) <= 0;
102}
103
104
105inline bool
106BPackageVersion::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