Inheritance diagram for csp::FIFOBuffer< DATA_TYPE, _LIST_DATA_TYPE >:
Unlike InfiniteFIFOBuffer, FIFOBuffer has a fixed maximum size. Data items come out of the buffer in the same order that they went in.
The complicated-looking second template parameter is a bit of C++ trickery (with the help of boost) that you are unlikely to need to ever alter. It implements a heuristic that uses std::list with a standard allocator (using new and delete) if sizeof(DATA_TYPE) is strictly greater than four times the sizeof(void*). Otherwise, boost's pool allocator is used to speed up the continual re-allocation of the linked list nodes. If you are incredibly concerned with memory or speed usage you may want to play with this parameter, but otherwise leave it as the default.
Public Types | |
typedef SizedChannelBufferFactoryImpl< DATA_TYPE, FIFOBuffer< DATA_TYPE, LIST_DATA_TYPE > > | Factory |
A channel buffer factory that can be used with this buffer. | |
Public Member Functions | |
virtual void | beginExtGet (DATA_TYPE *dest) |
Starts an extended input from the buffer. | |
virtual void | clear () |
Clears all data from the buffer. | |
virtual void | endExtGet () |
Ends the current extended input from the buffer. | |
FIFOBuffer (unsigned int n) | |
Constructor. | |
virtual void | get (DATA_TYPE *dest) |
Gets a single item of data from the buffer. | |
virtual bool | inputWouldSucceed () |
Checks whether an input would succeed on the buffer. | |
virtual bool | outputWouldSucceed (const DATA_TYPE *) |
Checks whether an output (of a specific item of data) would succeed on the buffer. | |
virtual void | put (const DATA_TYPE *source) |
Adds a single item of data to the buffer. |
typedef SizedChannelBufferFactoryImpl<DATA_TYPE,FIFOBuffer<DATA_TYPE,LIST_DATA_TYPE> > csp::FIFOBuffer< DATA_TYPE, _LIST_DATA_TYPE >::Factory |
A channel buffer factory that can be used with this buffer.
csp::FIFOBuffer< DATA_TYPE, _LIST_DATA_TYPE >::FIFOBuffer | ( | unsigned int | n | ) | [inline, explicit] |
Constructor.
n | The size of the FIFO buffer to create |
virtual bool csp::FIFOBuffer< DATA_TYPE, _LIST_DATA_TYPE >::inputWouldSucceed | ( | ) | [inline, virtual] |
Checks whether an input would succeed on the buffer.
Informally, inputWouldSucceed() will return true when the buffer is non-empty, but false when the buffer is empty.
Sub-classes will implement this method.
This method must return false at some point (i.e. the buffer must be emptyable). Because poison from writer to reader is only noticed when this method returns false, this method must at some point return false to allow a writer's poison to transmit properly.
This restriction should not be a problem for most buffers (intuitively, buffers should be empty once all data has been read from them). The sort of buffer that you should avoid implementing is one where data is (for example) forever overwritten but never actually removed from the buffer (so that a reader can always read the most recent value, over and over again). To produce the same effect, use a process that holds the value, with request/reply channels for accessing the value.
Implements csp::ChannelBuffer< DATA_TYPE >.
virtual bool csp::FIFOBuffer< DATA_TYPE, _LIST_DATA_TYPE >::outputWouldSucceed | ( | const DATA_TYPE * | ) | [inline, virtual] |
Checks whether an output (of a specific item of data) would succeed on the buffer.
Informally, outputWouldSucceed() will return true when the buffer is not full, but false when the buffer is full.
Passing the item of data allows buffers that may depend on the particular item given (particularly buffers that in some way aggregate the buffered data, or deal with items that can have different sizes).
Sub-classes will implement this method.
source must not be NULL.
Implements csp::ChannelBuffer< DATA_TYPE >.
virtual void csp::FIFOBuffer< DATA_TYPE, _LIST_DATA_TYPE >::put | ( | const DATA_TYPE * | source | ) | [inline, virtual] |
Adds a single item of data to the buffer.
Sub-classes will implement this method.
source | A pointer to the source data to be added to the buffer. The data pointed to by source will be copied from, and the pointer does not have to remain valid after this call has returned. source must not be NULL. |
Implements csp::ChannelBuffer< DATA_TYPE >.
virtual void csp::FIFOBuffer< DATA_TYPE, _LIST_DATA_TYPE >::get | ( | DATA_TYPE * | dest | ) | [inline, virtual] |
Gets a single item of data from the buffer.
The item of data is copied into dest and then removed from the buffer
Sub-classes will implement this method.
dest | A pointer to the destination to copy the data into. dest must not be NULL. |
Implements csp::ChannelBuffer< DATA_TYPE >.
virtual void csp::FIFOBuffer< DATA_TYPE, _LIST_DATA_TYPE >::beginExtGet | ( | DATA_TYPE * | dest | ) | [inline, virtual] |
Starts an extended input from the buffer.
Sub-classes should implement this method.
The implementation of this method for a new buffer may not be obvious. Put simply, when a channel begins an extended input on a buffered channel, it calls this beginExtGet method on the buffer. When the channel finishes the extended input, it calls endExtGet on the buffer. Each beginExtGet call will be followed by an extEndGet before the next beginEndGet call. How you implement these methods will require thinking about how the semantics of an extended input on your buffer.
Examples of semantic implementations can be found in the buffers provided with C++CSP2. See the Channel Buffers page for more information.
dest | A pointer to the destination to copy the data into. dest must not be NULL. |
Implements csp::ChannelBuffer< DATA_TYPE >.
virtual void csp::FIFOBuffer< DATA_TYPE, _LIST_DATA_TYPE >::endExtGet | ( | ) | [inline, virtual] |
Ends the current extended input from the buffer.
Sub-classes should implement this method.
The implementation of this method for a new buffer may not be obvious. Put simply, when a channel begins an extended input on a buffered channel, it calls this beginExtGet method on the buffer. When the channel finishes the extended input, it calls endExtGet on the buffer. Each beginExtGet call will be followed by an extEndGet before the next beginEndGet call. How you implement these methods will require thinking about how the semantics of an extended input on your buffer.
endExtGet will always be called either:
In particular, the buffer may be empty when this method is called, so remember to check for that.
Examples of semantic implementations can be found in the buffers provided with C++CSP2. See the Channel Buffers page for more information.
Implements csp::ChannelBuffer< DATA_TYPE >.
virtual void csp::FIFOBuffer< DATA_TYPE, _LIST_DATA_TYPE >::clear | ( | ) | [inline, virtual] |
Clears all data from the buffer.
Implements csp::ChannelBuffer< DATA_TYPE >.