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