/* * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ #include #include #include "qpid/framing/amqp_framing.h" #include "qpid/framing/AMQFrame.h" #include "qpid/framing/SequenceNumber.h" #ifndef _FrameSet_ #define _FrameSet_ namespace qpid { namespace framing { /** * Collects the frames representing a message. */ class FrameSet { typedef std::vector Frames; const SequenceNumber id; Frames parts; public: typedef boost::shared_ptr shared_ptr; FrameSet(const SequenceNumber& id); void append(const AMQFrame& part); bool isComplete() const; uint64_t getContentSize() const; void getContent(std::string&) const; std::string getContent() const; bool isContentBearing() const; const AMQMethodBody* getMethod() const; const AMQHeaderBody* getHeaders() const; AMQHeaderBody* getHeaders(); template bool isA() const { const AMQMethodBody* method = getMethod(); return method && method->isA(); } template const T* as() const { const AMQMethodBody* method = getMethod(); return (method && method->isA()) ? dynamic_cast(method) : 0; } template const T* getHeaderProperties() const { const AMQHeaderBody* header = getHeaders(); return header ? header->get() : 0; } const SequenceNumber& getId() const { return id; } template void remove(P predicate) { parts.erase(remove_if(parts.begin(), parts.end(), predicate), parts.end()); } template void map(F& functor) { for_each(parts.begin(), parts.end(), functor); } template void map(F& functor) const { for_each(parts.begin(), parts.end(), functor); } template void map_if(F& functor, P predicate) { for(Frames::iterator i = parts.begin(); i != parts.end(); i++) { if (predicate(*i)) functor(*i); } } template void map_if(F& functor, P predicate) const { for(Frames::const_iterator i = parts.begin(); i != parts.end(); i++) { if (predicate(*i)) functor(*i); } } }; } } #endif