| Line | |
|---|
| 1 | /*
|
|---|
| 2 | * synergy -- mouse and keyboard sharing utility
|
|---|
| 3 | * Copyright (C) 2002 Chris Schoeneman
|
|---|
| 4 | *
|
|---|
| 5 | * This package is free software; you can redistribute it and/or
|
|---|
| 6 | * modify it under the terms of the GNU General Public License
|
|---|
| 7 | * found in the file COPYING that should have accompanied this file.
|
|---|
| 8 | *
|
|---|
| 9 | * This package is distributed in the hope that it will be useful,
|
|---|
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 12 | * GNU General Public License for more details.
|
|---|
| 13 | */
|
|---|
| 14 |
|
|---|
| 15 | #ifndef CSTREAMBUFFER_H
|
|---|
| 16 | #define CSTREAMBUFFER_H
|
|---|
| 17 |
|
|---|
| 18 | #include "BasicTypes.h"
|
|---|
| 19 | #include "stdlist.h"
|
|---|
| 20 | #include "stdvector.h"
|
|---|
| 21 |
|
|---|
| 22 | //! FIFO of bytes
|
|---|
| 23 | /*!
|
|---|
| 24 | This class maintains a FIFO (first-in, last-out) buffer of bytes.
|
|---|
| 25 | */
|
|---|
| 26 | class CStreamBuffer {
|
|---|
| 27 | public:
|
|---|
| 28 | CStreamBuffer();
|
|---|
| 29 | ~CStreamBuffer();
|
|---|
| 30 |
|
|---|
| 31 | //! @name manipulators
|
|---|
| 32 | //@{
|
|---|
| 33 |
|
|---|
| 34 | //! Read data without removing from buffer
|
|---|
| 35 | /*!
|
|---|
| 36 | Return a pointer to memory with the next \c n bytes in the buffer
|
|---|
| 37 | (which must be <= getSize()). The caller must not modify the returned
|
|---|
| 38 | memory nor delete it.
|
|---|
| 39 | */
|
|---|
| 40 | const void* peek(UInt32 n);
|
|---|
| 41 |
|
|---|
| 42 | //! Discard data
|
|---|
| 43 | /*!
|
|---|
| 44 | Discards the next \c n bytes. If \c n >= getSize() then the buffer
|
|---|
| 45 | is cleared.
|
|---|
| 46 | */
|
|---|
| 47 | void pop(UInt32 n);
|
|---|
| 48 |
|
|---|
| 49 | //! Write data to buffer
|
|---|
| 50 | /*!
|
|---|
| 51 | Appends \c n bytes from \c data to the buffer.
|
|---|
| 52 | */
|
|---|
| 53 | void write(const void* data, UInt32 n);
|
|---|
| 54 |
|
|---|
| 55 | //@}
|
|---|
| 56 | //! @name accessors
|
|---|
| 57 | //@{
|
|---|
| 58 |
|
|---|
| 59 | //! Get size of buffer
|
|---|
| 60 | /*!
|
|---|
| 61 | Returns the number of bytes in the buffer.
|
|---|
| 62 | */
|
|---|
| 63 | UInt32 getSize() const;
|
|---|
| 64 |
|
|---|
| 65 | //@}
|
|---|
| 66 |
|
|---|
| 67 | private:
|
|---|
| 68 | static const UInt32 kChunkSize;
|
|---|
| 69 |
|
|---|
| 70 | typedef std::vector<UInt8> Chunk;
|
|---|
| 71 | typedef std::list<Chunk> ChunkList;
|
|---|
| 72 |
|
|---|
| 73 | ChunkList m_chunks;
|
|---|
| 74 | UInt32 m_size;
|
|---|
| 75 | UInt32 m_headUsed;
|
|---|
| 76 | };
|
|---|
| 77 |
|
|---|
| 78 | #endif
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.