1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
//
// C++ Interface: inputbuffer
//
// Description:
//
//
// Author: Rikard Bjorklind <olof@linux.nu>, (C) 2006
//
// Copyright: See COPYING file that comes with this distribution
//
//
#ifndef RPCINPUTBUFFER_H
#define RPCINPUTBUFFER_H
#include <boost/scoped_array.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/utility.hpp>
namespace rpc
{
/**
@author Rikard Bjorklind <olof@linux.nu>
*/
template<typename T>
class InputBuffer : private boost::noncopyable
{
public:
explicit InputBuffer(int aSize) : size( aSize ), buf( new char[size] ), p( buf.get() )
{
}
T* bufPtr()
{
return (T*)buf.get();
}
T* curPtr()
{
return reinterpret_cast<T*>(p);
}
void advance(int bytes)
{
p += bytes;
}
bool filled() const
{
return p == ( buf.get() + size );
}
int remaining() const
{
return ( buf.get() + size ) - p;
}
/**
* Reset the pointer to the next data item.
*/
void reset()
{
// Reset the pointer so that we start at the begining of the buffer
p = buf.get();
}
~InputBuffer()
{
}
int getSize() const {return size;}
private:
const int size;
boost::scoped_array<char> buf;
char* p; // points to the next free place
};
typedef boost::shared_ptr< InputBuffer<char> > CmdInputBufferPtr;
}
#endif
|