ProtocolVersion.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2018 The Squid Software Foundation and contributors
3  *
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.
7  */
8 
9 #ifndef SQUID_ANYP_PROTOCOLVERSION_H
10 #define SQUID_ANYP_PROTOCOLVERSION_H
11 
12 #include "anyp/ProtocolType.h"
13 
14 #include <ostream>
15 
16 namespace AnyP
17 {
18 
24 {
25 
26 public:
27  // BUG: major() and minor() are macros.
28  // we can't use a fast constructor syntax without renaming them globally
30  major = 0;
31  minor = 0;
32  }
33 
34  ProtocolVersion(ProtocolType which, unsigned int aMajor, unsigned int aMinor) : protocol(which) {
35  major = aMajor;
36  minor = aMinor;
37  }
38 
40  unsigned int major;
41  unsigned int minor;
42 
43  bool operator==(const ProtocolVersion& that) const {
44  if (this->protocol != that.protocol)
45  return false;
46 
47  if (this->major != that.major)
48  return false;
49 
50  if (this->minor != that.minor)
51  return false;
52 
53  return true;
54  }
55 
56  bool operator!=(const ProtocolVersion& that) const {
57  return (((this->protocol != that.protocol) || this->major != that.major) || (this->minor != that.minor));
58  }
59 
60  bool operator <(const ProtocolVersion& that) const {
61  if (this->protocol != that.protocol)
62  return false; // throw?
63 
64  return (this->major < that.major ||
65  (this->major == that.major && this->minor < that.minor));
66  }
67 
68  bool operator >(const ProtocolVersion& that) const {
69  if (this->protocol != that.protocol)
70  return false; // throw?
71 
72  return (this->major > that.major ||
73  (this->major == that.major && this->minor > that.minor));
74  }
75 
76  bool operator <=(const ProtocolVersion& that) const {
77  if (this->protocol != that.protocol)
78  return false; // throw?
79 
80  return !(*this > that);
81  }
82 
83  bool operator >=(const ProtocolVersion& that) const {
84  if (this->protocol != that.protocol)
85  return false; // throw?
86 
87  return !(*this < that);
88  }
89 };
90 
91 inline std::ostream &
92 operator << (std::ostream &os, const AnyP::ProtocolVersion &v)
93 {
94  return (os << AnyP::ProtocolType_str[v.protocol] << '/' << v.major << '.' << v.minor);
95 }
96 
97 } // namespace AnyP
98 
99 #endif /* SQUID_ANYP_PROTOCOLVERSION_H */
100 
bool operator==(const ProtocolVersion &that) const
bool operator!=(const ProtocolVersion &that) const
bool operator>(const ProtocolVersion &that) const
bool operator<=(const ProtocolVersion &that) const
unsigned int major
major version number
bool operator<(const ProtocolVersion &that) const
ProtocolType
Definition: ProtocolType.h:22
const char * ProtocolType_str[]
std::ostream & operator<<(std::ostream &os, ProtocolType const &p)
Definition: ProtocolType.h:53
unsigned int minor
minor version number
ProtocolVersion(ProtocolType which, unsigned int aMajor, unsigned int aMinor)
ProtocolType protocol
which protocol this version is for
bool operator>=(const ProtocolVersion &that) const

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors