1 // Copyright 2006-2008 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef NET_HTTP_HTTP_VERSION_H_ 6 #define NET_HTTP_HTTP_VERSION_H_ 7 8 #include <stdint.h> 9 10 namespace net { 11 12 // Wrapper for an HTTP (major,minor) version pair. 13 class HttpVersion { 14 public: 15 // Default constructor (major=0, minor=0). HttpVersion()16 HttpVersion() : value_(0) { } 17 18 // Build from unsigned major/minor pair. HttpVersion(uint16_t major,uint16_t minor)19 HttpVersion(uint16_t major, uint16_t minor) 20 : value_(static_cast<uint32_t>(major << 16) | minor) {} 21 22 // Major version number. major_value()23 uint16_t major_value() const { return value_ >> 16; } 24 25 // Minor version number. minor_value()26 uint16_t minor_value() const { return value_ & 0xffff; } 27 28 // Overloaded operators: 29 30 bool operator==(const HttpVersion& v) const { 31 return value_ == v.value_; 32 } 33 bool operator!=(const HttpVersion& v) const { 34 return value_ != v.value_; 35 } 36 bool operator>(const HttpVersion& v) const { 37 return value_ > v.value_; 38 } 39 bool operator>=(const HttpVersion& v) const { 40 return value_ >= v.value_; 41 } 42 bool operator<(const HttpVersion& v) const { 43 return value_ < v.value_; 44 } 45 bool operator<=(const HttpVersion& v) const { 46 return value_ <= v.value_; 47 } 48 49 private: 50 uint32_t value_; // Packed as <major>:<minor> 51 }; 52 53 } // namespace net 54 55 #endif // NET_HTTP_HTTP_VERSION_H_ 56