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 void encode(Buffer& buffer) const; 00056 void decode(Buffer& buffer); 00057 uint32_t encodedSize() const; 00058 00059 template <class S> void serialize(S& s) { s(value); } 00060 00061 friend inline int32_t operator-(const SequenceNumber& a, const SequenceNumber& b); 00062 }; 00063 00064 inline int32_t operator-(const SequenceNumber& a, const SequenceNumber& b) { 00065 return int32_t(a.value - b.value); 00066 } 00067 00068 struct Window 00069 { 00070 SequenceNumber hwm; 00071 SequenceNumber lwm; 00072 }; 00073 00074 QPID_COMMON_EXTERN std::ostream& operator<<(std::ostream& o, const SequenceNumber& n); 00075 00076 }} // namespace qpid::framing 00077 00078 00079 #endif