/usr/share/cruisecontrol-bin-2.6.1/projects/qpid-trunk/cpp/src/qpid/framing/SequenceSet.h

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_SequenceSet_h
00022 #define _framing_SequenceSet_h
00023 
00024 #include <ostream>
00025 #include <list>
00026 #include "amqp_types.h"
00027 #include "Buffer.h"
00028 #include "SequenceNumber.h"
00029 #include "qpid/framing/reply_exceptions.h"
00030 
00031 namespace qpid {
00032 namespace framing {
00033 
00034 class SequenceSet
00035 {
00036     struct Range
00037     {
00038         SequenceNumber start;
00039         SequenceNumber end;
00040         
00041         Range(SequenceNumber s, SequenceNumber e);
00042         bool contains(SequenceNumber i) const;
00043         bool intersects(const Range& r) const;
00044         bool merge(const Range& r);
00045         bool mergeable(const SequenceNumber& r) const;
00046         void encode(Buffer& buffer) const;
00047     };
00048 
00049     typedef std::list<Range> Ranges;
00050     Ranges ranges;
00051 
00052 public:
00053     SequenceSet() {}
00054     SequenceSet(const SequenceNumber& s) { add(s); }
00055 
00056     void encode(Buffer& buffer) const;
00057     void decode(Buffer& buffer);
00058     uint32_t size() const;   
00059 
00060     bool contains(const SequenceNumber& s) const;
00061     void add(const SequenceNumber& s);
00062     void add(const SequenceNumber& start, const SequenceNumber& end);
00063     void add(const SequenceSet& set);
00064     void remove(const SequenceNumber& s);
00065     void remove(const SequenceNumber& start, const SequenceNumber& end);
00066     void remove(const SequenceSet& set);
00067 
00068     void clear();
00069     bool empty() const;
00070 
00071     template <class T>
00072     void for_each(T& t) const
00073     {
00074         for (Ranges::const_iterator i = ranges.begin(); i != ranges.end(); i++) {
00075             t(i->start, i->end);
00076         }
00077     }
00078 
00079     friend std::ostream& operator<<(std::ostream&, const SequenceSet&);
00080 };    
00081 
00082 
00083 }} // namespace qpid::framing
00084 
00085 
00086 #endif

Generated on Thu Apr 10 11:08:18 2008 for Qpid by  doxygen 1.4.7