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_SequenceNumberSet_h 00022 #define _framing_SequenceNumberSet_h 00023 00024 #include <ostream> 00025 #include "amqp_types.h" 00026 #include "Buffer.h" 00027 #include "SequenceNumber.h" 00028 #include "qpid/framing/reply_exceptions.h" 00029 #include "qpid/InlineVector.h" 00030 00031 namespace qpid { 00032 namespace framing { 00033 00034 class SequenceNumberSet : public InlineVector<SequenceNumber, 2> 00035 { 00036 typedef InlineVector<SequenceNumber, 2> Base; 00037 public: 00038 typedef Base::const_iterator const_iterator; 00039 typedef Base::iterator iterator; 00040 00041 void encode(Buffer& buffer) const; 00042 void decode(Buffer& buffer); 00043 uint32_t encodedSize() const; 00044 SequenceNumberSet condense() const; 00045 void addRange(const SequenceNumber& start, const SequenceNumber& end); 00046 00047 template <class T> 00048 void processRanges(T& t) const 00049 { 00050 if (size() % 2) { //must be even number 00051 throw InvalidArgumentException("SequenceNumberSet contains odd number of elements"); 00052 } 00053 00054 for (SequenceNumberSet::const_iterator i = begin(); i != end(); i++) { 00055 SequenceNumber first = *(i); 00056 SequenceNumber last = *(++i); 00057 t(first, last); 00058 } 00059 } 00060 00061 friend std::ostream& operator<<(std::ostream&, const SequenceNumberSet&); 00062 }; 00063 00064 00065 }} // namespace qpid::framing 00066 00067 00068 #endif