1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 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 #pragma once 8 9 #include "base/basictypes.h" 10 11 namespace net { 12 13 // Wrapper for an HTTP (major,minor) version pair. 14 class HttpVersion { 15 public: 16 // Default constructor (major=0, minor=0). HttpVersion()17 HttpVersion() : value_(0) { } 18 19 // Build from unsigned major/minor pair. HttpVersion(uint16 major,uint16 minor)20 HttpVersion(uint16 major, uint16 minor) : value_(major << 16 | minor) { } 21 22 // Major version number. major_value()23 uint16 major_value() const { 24 return value_ >> 16; 25 } 26 27 // Minor version number. minor_value()28 uint16 minor_value() const { 29 return value_ & 0xffff; 30 } 31 32 // Overloaded operators: 33 34 bool operator==(const HttpVersion& v) const { 35 return value_ == v.value_; 36 } 37 bool operator!=(const HttpVersion& v) const { 38 return value_ != v.value_; 39 } 40 bool operator>(const HttpVersion& v) const { 41 return value_ > v.value_; 42 } 43 bool operator>=(const HttpVersion& v) const { 44 return value_ >= v.value_; 45 } 46 bool operator<(const HttpVersion& v) const { 47 return value_ < v.value_; 48 } 49 bool operator<=(const HttpVersion& v) const { 50 return value_ <= v.value_; 51 } 52 53 private: 54 uint32 value_; // Packed as <major>:<minor> 55 }; 56 57 } // namespace net 58 59 #endif // NET_HTTP_HTTP_VERSION_H_ 60