13aeae97fSOliver Tappe/*
23aeae97fSOliver Tappe * Copyright 2011, Haiku, Inc.
33aeae97fSOliver Tappe * Distributed under the terms of the MIT License.
43aeae97fSOliver Tappe */
53aeae97fSOliver Tappe#ifndef _PACKAGE__PACKAGE_VERSION_H_
63aeae97fSOliver Tappe#define _PACKAGE__PACKAGE_VERSION_H_
73aeae97fSOliver Tappe
83aeae97fSOliver Tappe
93aeae97fSOliver Tappe#include <String.h>
103aeae97fSOliver Tappe
113aeae97fSOliver Tappe
123aeae97fSOliver Tappenamespace BPackageKit {
133aeae97fSOliver Tappe
143aeae97fSOliver Tappe
150d68f6afSOliver Tappenamespace BHPKG {
1692b07297SMurai Takashi	struct BPackageVersionData;
170d68f6afSOliver Tappe}
180d68f6afSOliver Tappeusing BHPKG::BPackageVersionData;
190d68f6afSOliver Tappe
200d68f6afSOliver Tappe
213aeae97fSOliver Tappeclass BPackageVersion {
223aeae97fSOliver Tappepublic:
233aeae97fSOliver Tappe								BPackageVersion();
240d68f6afSOliver Tappe								BPackageVersion(
250d68f6afSOliver Tappe									const BPackageVersionData& data);
261a34656bSIngo Weinhold	explicit					BPackageVersion(const BString& versionString,
27202c1daaSIngo Weinhold									bool revisionIsOptional = true);
283aeae97fSOliver Tappe								BPackageVersion(const BString& major,
293aeae97fSOliver Tappe									const BString& minor, const BString& micro,
30202c1daaSIngo Weinhold									const BString& preRelease, uint32 revision);
313aeae97fSOliver Tappe
323aeae97fSOliver Tappe			status_t			InitCheck() const;
333aeae97fSOliver Tappe
342f7778f3SOliver Tappe			const BString&		Major() const;
352f7778f3SOliver Tappe			const BString&		Minor() const;
362f7778f3SOliver Tappe			const BString&		Micro() const;
37ed6d59a9SIngo Weinhold			const BString&		PreRelease() const;
38ed6d59a9SIngo Weinhold									// "alpha3", "beta2", "rc1" or "" if final
39202c1daaSIngo Weinhold			uint32				Revision() const;
402f7778f3SOliver Tappe
41ceb993abSOliver Tappe			BString				ToString() const;
423aeae97fSOliver Tappe
433aeae97fSOliver Tappe			void				SetTo(const BString& major,
443aeae97fSOliver Tappe									const BString& minor, const BString& micro,
45202c1daaSIngo Weinhold									const BString& preRelease, uint32 revision);
46a3dd6cafSIngo Weinhold			status_t			SetTo(const BString& versionString,
47202c1daaSIngo Weinhold									bool revisionIsOptional = true);
483aeae97fSOliver Tappe			void				Clear();
493aeae97fSOliver Tappe
503aeae97fSOliver Tappe			int					Compare(const BPackageVersion& other) const;
513aeae97fSOliver Tappe									// does a natural compare over major, minor
52202c1daaSIngo Weinhold									// and micro, finally comparing revision
533aeae97fSOliver Tappe
54f96ed662SIngo Weinhold	inline	bool				operator==(const BPackageVersion& other) const;
55f96ed662SIngo Weinhold	inline	bool				operator!=(const BPackageVersion& other) const;
56f96ed662SIngo Weinhold	inline	bool				operator<(const BPackageVersion& other) const;
57f96ed662SIngo Weinhold	inline	bool				operator>(const BPackageVersion& other) const;
58f96ed662SIngo Weinhold	inline	bool				operator<=(const BPackageVersion& other) const;
59f96ed662SIngo Weinhold	inline	bool				operator>=(const BPackageVersion& other) const;
60f96ed662SIngo Weinhold
613aeae97fSOliver Tappeprivate:
623aeae97fSOliver Tappe			BString				fMajor;
633aeae97fSOliver Tappe			BString				fMinor;
643aeae97fSOliver Tappe			BString				fMicro;
65ed6d59a9SIngo Weinhold			BString				fPreRelease;
66202c1daaSIngo Weinhold			uint32				fRevision;
673aeae97fSOliver Tappe};
683aeae97fSOliver Tappe
693aeae97fSOliver Tappe
70f96ed662SIngo Weinholdinline bool
71f96ed662SIngo WeinholdBPackageVersion::operator==(const BPackageVersion& other) const
72f96ed662SIngo Weinhold{
73f96ed662SIngo Weinhold	return Compare(other) == 0;
74f96ed662SIngo Weinhold}
75f96ed662SIngo Weinhold
76f96ed662SIngo Weinhold
77f96ed662SIngo Weinholdinline bool
78f96ed662SIngo WeinholdBPackageVersion::operator!=(const BPackageVersion& other) const
79f96ed662SIngo Weinhold{
80f96ed662SIngo Weinhold	return Compare(other) != 0;
81f96ed662SIngo Weinhold}
82f96ed662SIngo Weinhold
83f96ed662SIngo Weinhold
84f96ed662SIngo Weinholdinline bool
85f96ed662SIngo WeinholdBPackageVersion::operator<(const BPackageVersion& other) const
86f96ed662SIngo Weinhold{
87f96ed662SIngo Weinhold	return Compare(other) < 0;
88f96ed662SIngo Weinhold}
89f96ed662SIngo Weinhold
90f96ed662SIngo Weinhold
91f96ed662SIngo Weinholdinline bool
92f96ed662SIngo WeinholdBPackageVersion::operator>(const BPackageVersion& other) const
93f96ed662SIngo Weinhold{
94f96ed662SIngo Weinhold	return Compare(other) > 0;
95f96ed662SIngo Weinhold}
96f96ed662SIngo Weinhold
97f96ed662SIngo Weinhold
98f96ed662SIngo Weinholdinline bool
99f96ed662SIngo WeinholdBPackageVersion::operator<=(const BPackageVersion& other) const
100f96ed662SIngo Weinhold{
101f96ed662SIngo Weinhold	return Compare(other) <= 0;
102f96ed662SIngo Weinhold}
103f96ed662SIngo Weinhold
104f96ed662SIngo Weinhold
105f96ed662SIngo Weinholdinline bool
106f96ed662SIngo WeinholdBPackageVersion::operator>=(const BPackageVersion& other) const
107f96ed662SIngo Weinhold{
108f96ed662SIngo Weinhold	return Compare(other) >= 0;
109f96ed662SIngo Weinhold}
110f96ed662SIngo Weinhold
111f96ed662SIngo Weinhold
1123aeae97fSOliver Tappe}	// namespace BPackageKit
1133aeae97fSOliver Tappe
1143aeae97fSOliver Tappe
1153aeae97fSOliver Tappe#endif	// _PACKAGE__PACKAGE_VERSION_H_
116