Apache Qpid - AMQP Messaging for Java JMS, C++, Python, Ruby, and .NET | Apache Qpid Documentation |
00001 /* 00002 * 00003 * Licensed to the Apache Software Foundation (ASF) under one 00004 * or more contributor license agreements. See the NOTICE file 00005 * distributed with this work for additional information 00006 * regarding copyright ownership. The ASF licenses this file 00007 * to you under the Apache License, Version 2.0 (the 00008 * "License"); you may not use this file except in compliance 00009 * with the License. You may obtain a copy of the License at 00010 * 00011 * http://www.apache.org/licenses/LICENSE-2.0 00012 * 00013 * Unless required by applicable law or agreed to in writing, 00014 * software distributed under the License is distributed on an 00015 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 00016 * KIND, either express or implied. See the License for the 00017 * specific language governing permissions and limitations 00018 * under the License. 00019 * 00020 */ 00021 #ifndef _framing_SequenceNumber_h 00022 #define _framing_SequenceNumber_h 00023 00024 #include "qpid/framing/amqp_types.h" 00025 #include <boost/operators.hpp> 00026 #include <iosfwd> 00027 #include "qpid/CommonImportExport.h" 00028 00029 namespace qpid { 00030 namespace framing { 00031 00032 class Buffer; 00033 00037 class QPID_COMMON_CLASS_EXTERN SequenceNumber : public 00038 boost::equality_comparable< 00039 SequenceNumber, boost::less_than_comparable< 00040 SequenceNumber, boost::incrementable< 00041 SequenceNumber, boost::decrementable<SequenceNumber> > > > 00042 { 00043 int32_t value; 00044 00045 public: 00046 SequenceNumber(uint32_t v=0) : value(v) {} 00047 00048 SequenceNumber& operator++() { ++value; return *this; } 00049 SequenceNumber& operator--() { --value; return *this; } 00050 bool operator==(const SequenceNumber& other) const { return value == other.value; } 00051 bool operator<(const SequenceNumber& other) const { return (value - other.value) < 0; } 00052 uint32_t getValue() const { return uint32_t(value); } 00053 operator uint32_t() const { return uint32_t(value); } 00054 00055 QPID_COMMON_EXTERN void encode(Buffer& buffer) const; 00056 QPID_COMMON_EXTERN void decode(Buffer& buffer); 00057 QPID_COMMON_EXTERN uint32_t encodedSize() const; 00058 00059 template <class S> void serialize(S& s) { s(value); } 00060 }; 00061 00062 inline int32_t operator-(const SequenceNumber& a, const SequenceNumber& b) { 00063 return int32_t(a.getValue() - b.getValue()); 00064 } 00065 00066 inline SequenceNumber operator+(const SequenceNumber& a, int32_t n) { 00067 return SequenceNumber(a.getValue() + n); 00068 } 00069 00070 inline SequenceNumber operator-(const SequenceNumber& a, int32_t n) { 00071 return SequenceNumber(a.getValue() - n); 00072 } 00073 00074 struct Window 00075 { 00076 SequenceNumber hwm; 00077 SequenceNumber lwm; 00078 }; 00079 00080 QPID_COMMON_EXTERN std::ostream& operator<<(std::ostream& o, const SequenceNumber& n); 00081 00082 }} // namespace qpid::framing 00083 00084 00085 #endif