]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/anyp/ProtocolVersion.h
2 * Copyright (C) 1996-2021 The Squid Software Foundation and contributors
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
9 #ifndef SQUID_ANYP_PROTOCOLVERSION_H
10 #define SQUID_ANYP_PROTOCOLVERSION_H
12 #include "anyp/ProtocolType.h"
20 * Stores a protocol version label.
21 * For example HTTP/1.1 or ICY/1.0 or FTP/2.0
27 // BUG: major() and minor() are macros.
28 // we can't use a fast constructor syntax without renaming them globally
29 ProtocolVersion() : protocol(PROTO_NONE
) {
34 ProtocolVersion(ProtocolType which
, unsigned int aMajor
, unsigned int aMinor
) : protocol(which
) {
39 ProtocolType protocol
; ///< which protocol this version is for
40 unsigned int major
; ///< major version number
41 unsigned int minor
; ///< minor version number
43 /// whether the version is "known" (e.g., has been parsed or explicitly set)
44 explicit operator bool() const { return protocol
!= PROTO_NONE
; }
46 bool operator==(const ProtocolVersion
& that
) const {
47 if (this->protocol
!= that
.protocol
)
50 if (this->major
!= that
.major
)
53 if (this->minor
!= that
.minor
)
59 bool operator!=(const ProtocolVersion
& that
) const {
60 return (((this->protocol
!= that
.protocol
) || this->major
!= that
.major
) || (this->minor
!= that
.minor
));
63 bool operator <(const ProtocolVersion
& that
) const {
64 if (this->protocol
!= that
.protocol
)
65 return false; // throw?
67 return (this->major
< that
.major
||
68 (this->major
== that
.major
&& this->minor
< that
.minor
));
71 bool operator >(const ProtocolVersion
& that
) const {
72 if (this->protocol
!= that
.protocol
)
73 return false; // throw?
75 return (this->major
> that
.major
||
76 (this->major
== that
.major
&& this->minor
> that
.minor
));
79 bool operator <=(const ProtocolVersion
& that
) const {
80 if (this->protocol
!= that
.protocol
)
81 return false; // throw?
83 return !(*this > that
);
86 bool operator >=(const ProtocolVersion
& that
) const {
87 if (this->protocol
!= that
.protocol
)
88 return false; // throw?
90 return !(*this < that
);
95 operator << (std::ostream
&os
, const AnyP::ProtocolVersion
&v
)
97 return (os
<< AnyP::ProtocolType_str
[v
.protocol
] << '/' << v
.major
<< '.' << v
.minor
);
102 #endif /* SQUID_ANYP_PROTOCOLVERSION_H */