Source: OmInputStringStream.h
|
|
|
|
#ifndef OM_INPUT_STRING_STREAM_H
#define OM_INPUT_STRING_STREAM_H
/**
* Implementation of input stream for strings.
*
* This class provides a specialization of OmInputStream for strings buffers.
* This corresponds to an encapsulation of I/O operations needed by the library.
*/
class OmInputStringStream : public OmInputStream
{
public:
/**
* Constructor. The given buffer is fully copied and no sharing occurs.
* @li Precondition: ~ NullPointer(buffer_in)
*/
explicit OmInputStringStream(const char * buffer_in) {
OmException::checkNullPointer(buffer_in);
buffer_ = strcpy(new char[strlen(buffer_in)+1], buffer_in);
shared_ = false;
setIO(OMmakeIOString(&buffer_)); }
/**
* Constructor. By default the given buffer is fully copied and no sharing occurs.
* However sharing can be provided if explicitly specified here. In this case the user
* must be careful about its changed in memory.
* @li Precondition: ~ NullPointer(buffer_in)
*/
explicit OmInputStringStream(char * buffer_in, bool shared_in=false) {
OmException::checkNullPointer(buffer_in);
buffer_ = shared_in ? buffer_in : strcpy(new char[strlen(buffer_in)+1], buffer_in);
shared_ = shared_in;
setIO(OMmakeIOString(&buffer_)); }
/**
* Destructor.
*/
virtual ~OmInputStringStream() {
if (!shared_)
delete[] buffer_; }
/**
* Get the buffer.
*/
virtual const char * getBuffer() const {
return buffer_; }
/**
* Test if buffer is shared.
*/
virtual bool isShared() const {
return shared_; }
private:
char * buffer_;
bool shared_;
};
#endif // OM_INPUT_STRING_STREAM_H
Generated by: root@localhost.localdomain on Tue Oct 12 21:02:30 199. |