]>
git.saurik.com Git - apple/security.git/blob - cdsa/cdsa_utilities/bufferfifo.h
2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please obtain
7 * a copy of the License at http://www.apple.com/publicsource and read it before
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
15 * specific language governing rights and limitations under the License.
20 // bufferfifo - a Sink that queues data in a FIFO of buffers for retrieval
35 // A BufferFifo acts as a First-in First-out queue of Buffer objects.
36 // This is usually used as a flexible I/O buffer queue mechanism.
37 // For convenience, a BufferFifo is a Sink, so you can push data
38 // into it directly using the Sink mechanism.
39 // Note that there is currently no mechanism for restricting the
40 // memory footprint of a BufferFifo.
42 class BufferFifo
: public Sink
{
44 BufferFifo(size_t es
= 4096) : bufferLength(es
) { }
47 Buffer
*top() const { assert(!mBuffers
.empty()); return mBuffers
.front(); }
49 void push(Buffer
*b
) { mBuffers
.push(b
); }
51 bool isEmpty() const { return mBuffers
.empty(); }
52 size_t size() const { return mBuffers
.size(); }
53 size_t topLength() const { assert(!isEmpty()); return mBuffers
.front()->length(); }
55 // Sink implementation
56 void consume(const void *data
, size_t size
);
60 typedef queue
< Buffer
*, list
<Buffer
*> > BufferQueue
;
62 const size_t bufferLength
;
67 } // end namespace Security