- IOChannel, IOChannelConfig, ActiveIOChannel

- ActiveMethod::operator () default argument value (convenient for arguments of Poco::Void type)
This commit is contained in:
Aleksandar Fabijanic 2008-03-01 14:50:43 +00:00
parent 0178d9c14e
commit 0c65fa6295
10 changed files with 972 additions and 1 deletions

View File

@ -4785,6 +4785,46 @@
</File>
</Filter>
</Filter>
<Filter
Name="IO"
>
<Filter
Name="Header Files"
>
<File
RelativePath=".\include\Poco\ActiveIOChannel.h"
>
</File>
<File
RelativePath=".\include\Poco\IOChannel.h"
>
</File>
<File
RelativePath=".\include\Poco\IOChannelConfig.h"
>
</File>
<File
RelativePath=".\include\Poco\IOChannelStream.h"
>
</File>
</Filter>
<Filter
Name="Source Files"
>
<File
RelativePath=".\src\IOChannel.cpp"
>
</File>
<File
RelativePath=".\src\IOChannelConfig.cpp"
>
</File>
<File
RelativePath=".\src\IOChannelStream.cpp"
>
</File>
</Filter>
</Filter>
</Files>
<Globals>
</Globals>

View File

@ -6,6 +6,7 @@
ProjectGUID="{8164D41D-B053-405B-826C-CF37AC0EF176}"
RootNamespace="Foundation"
Keyword="Win32Proj"
TargetFrameworkVersion="0"
>
<Platforms>
<Platform
@ -4775,6 +4776,46 @@
</File>
</Filter>
</Filter>
<Filter
Name="IO"
>
<Filter
Name="Header Files"
>
<File
RelativePath=".\include\Poco\ActiveIOChannel.h"
>
</File>
<File
RelativePath=".\include\Poco\IOChannel.h"
>
</File>
<File
RelativePath=".\include\Poco\IOChannelConfig.h"
>
</File>
<File
RelativePath=".\include\Poco\IOChannelStream.h"
>
</File>
</Filter>
<Filter
Name="Source Files"
>
<File
RelativePath=".\src\IOChannel.cpp"
>
</File>
<File
RelativePath=".\src\IOChannelConfig.cpp"
>
</File>
<File
RelativePath=".\src\IOChannelStream.cpp"
>
</File>
</Filter>
</Filter>
</Files>
<Globals>
</Globals>

View File

@ -0,0 +1,89 @@
//
// ActiveIOChannel.h
//
// $Id: //poco/Main/Data/include/Poco/ActiveIOChannel.h#1 $
//
// Library: Foundation
// Package: Foundation
// Module: ActiveIOChannel
//
// Definition of the ActiveIOChannel class.
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTFoundationN WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#ifndef Foundation_ActiveIOChannel_INCLUDED
#define Foundation_ActiveIOChannel_INCLUDED
#include "Poco/Foundation.h"
#include "Poco/ActiveMethod.h"
#include "Poco/Void.h"
namespace Poco {
template <class P>
class ActiveIOChannel
{
public:
ActiveIOChannel(P& channel):
read(this, &ActiveIOChannel::readImpl),
write(this, &ActiveIOChannel::writeImpl),
_channel(channel)
{
}
~ActiveIOChannel()
{
}
Poco::ActiveMethod<std::string, Void, ActiveIOChannel> read;
Poco::ActiveMethod<int, std::string, ActiveIOChannel> write;
protected:
std::string readImpl(const Void&)
{
std::string buffer;
return _channel.read(buffer);
}
int writeImpl(const std::string& data)
{
return _channel.write(data);
}
private:
P& _channel;
};
} // namespace Poco
#endif // Foundation_ActiveIOChannel_INCLUDED

View File

@ -106,7 +106,7 @@ public:
poco_check_ptr (pOwner);
}
ActiveResultType operator () (const ArgType& arg)
ActiveResultType operator () (const ArgType& arg = ArgType())
/// Invokes the ActiveMethod.
{
ActiveResultType result(new ActiveResultHolder<ResultType>());

View File

@ -0,0 +1,242 @@
//
// IOChannel.h
//
// $Id: //poco/svn/Foundation/include/Poco/IOChannel.h#2 $
//
// Library: Foundation
// Package: IO
// Module: IOChannel
//
// Definition of the IOChannel class.
//
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#ifndef Foundation_IOChannel_INCLUDED
#define Foundation_IOChannel_INCLUDED
#include "Poco/Foundation.h"
#include "Poco/IOChannelConfig.h"
#include "Poco/RefCountedObject.h"
#include "Poco/AutoPtr.h"
namespace Poco {
class Foundation_API IOChannel: public RefCountedObject
/// IOChannel supports I/O operations on streams or other input/output facilities.
///
/// IOChannel supports blocking (default) and non-blocking read and write operations.
{
public:
typedef AutoPtr<IOChannelConfig> ConfigPtr;
IOChannel(const std::string& name = "");
/// Creates the IOChannel.
IOChannel(IOChannelConfig* pConfig, const std::string& name = "");
/// Creates the IOChannel with specified configuration.
virtual ~IOChannel();
/// Destroys the IOChannel.
virtual void open() = 0;
/// Opens the channel.
virtual void close() = 0;
/// Closes the channel.
std::string& read(std::string& buffer, int length = 0);
/// Read up to length bytes into the supplied buffer.
/// If length is 0, the channel implementation must provide
/// support for the termination of transmission.
/// Also, in case when length is 0 and the channel implementation
/// provides the buffer length and termination character
/// information, it also allocates the buffer. The buffer,
/// however, is always freed in this function, regardless of where
/// it was allocated. See readData(char*&) for more information.
const std::string& read(int length);
/// Read up to length bytes and return the reference to internal buffer.
int read(char* pReadBuf, int length);
/// Reads a string of characters from the channel.
int write(char c);
/// Writes a character to the channel.
int write(const char* buffer, int length);
/// Write length bytes from buffer.
/// Returns the number of bytes written.
int write(const std::string& data);
/// Writes a string of characters to the channel.
char read();
/// Reads one character from the channel.
const std::string& name() const;
/// Returns the channel name.
virtual void setTimeout(int timeoutMS);
/// Sets timeout in milliseconds.
virtual void setBlocking();
/// Sets blocking operation.
virtual void setNonblocking(int timeoutMS);
/// Sets non-blocking operation by calling setTimeout().
int getTimeout() const;
/// Returns timeout in milliseconds.
bool isBlocking() const;
/// Returns true if operation is blocking, false otherwise.
protected:
IOChannelConfig& config();
/// Returns the reference to the configuration for this cahannel.
virtual void init();
/// (Re)initializes the internal channel configuration.
/// Does nothing in this implementation.
virtual int readData(char* pReadBuf, int length) = 0;
/// Reads length bytes and puts them in the buffer.
/// Must be implemented by the inheriting class.
virtual int readData(char*& pReadBuf) = 0;
/// Reads an unspecified amount of bytes and places them in the buffer.
/// Properly behaved implementation of this function reads bytes and places
/// them in the buffer. Buffer is allocated by the implementation as
/// needed. Implementation must provide a way to terminate the communication
/// session.
/// Important: this function is called from read(std::string, int length) when
/// the length is zero. The buffer allocated in the implementation of this function
/// is always freed in the caller function.
virtual int writeData(const char* buffer, int length) = 0;
/// Writes length bytes from buffer to the target.
/// Must be implemented by the inheriting class.
private:
IOChannel(const IOChannel&);
IOChannel& operator = (const IOChannel&);
std::string _name;
std::string _buffer;
ConfigPtr _pConfig;
};
//
// inlines
//
inline IOChannelConfig& IOChannel::config()
{
return *_pConfig;
}
inline void IOChannel::init()
{
}
inline const std::string& IOChannel::name() const
{
return _name;
}
inline const std::string& IOChannel::read(int length)
{
return read(_buffer, length);
}
inline int IOChannel::read(char* pReadBuf, int length)
{
return readData(pReadBuf, length);
}
inline int IOChannel::write(char c)
{
return writeData(&c, 1);
}
inline int IOChannel::write(const std::string& data)
{
return writeData(data.data(), static_cast<int>(data.size()));
}
inline int IOChannel::write(const char* buffer, int length)
{
return writeData(buffer, length);
}
inline void IOChannel::setTimeout(int timeoutMS)
{
_pConfig->setTimeout(timeoutMS);
}
inline void IOChannel::setBlocking()
{
_pConfig->setBlocking();
}
inline void IOChannel::setNonblocking(int timeoutMS)
{
setTimeout(timeoutMS);
}
inline int IOChannel::getTimeout() const
{
return _pConfig->getTimeout();
}
inline bool IOChannel::isBlocking() const
{
return _pConfig->isBlocking();
}
} // namespace Poco
#endif // Foundation_IOChannel_INCLUDED

View File

@ -0,0 +1,158 @@
//
// IOChannelConfig.h
//
// $Id: //poco/Main/Data/include/Poco/IOChannelConfig.h#1 $
//
// Library: Foundation
// Package: IO
// Module: IOChannelConfig
//
// Definition of the IOChannelConfig class.
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#ifndef Foundation_IOChannelConfig_INCLUDED
#define Foundation_IOChannelConfig_INCLUDED
#include "Poco/Foundation.h"
#include "Poco/RefCountedObject.h"
namespace Poco {
class Foundation_API IOChannelConfig: public RefCountedObject
{
public:
enum ChannelType
{
CONNECTION_CHANNEL,
CONNECTIONLESS_CHANNEL
};
IOChannelConfig(const std::string& name = "",
ChannelType type = CONNECTION_CHANNEL,
int timeoutMS = INFINITE_TIMEOUT);
/// Creates IOChannelConfig.
virtual ~IOChannelConfig();
/// Destroys IOChannelConfig.
virtual void setTimeout(int timeoutMS);
/// Sets timeout in milliseconds.
int getTimeout() const;
/// Returns timeout in milliseconds.
virtual void setBlocking();
/// Sets blocking operation.
virtual void setNonblocking(int timeoutMS);
/// Sets blocking operation.
bool isBlocking() const;
/// Returns true if operation is blocking, false otherwise.
void setName(const std::string& name);
/// Sets the channel name.
const std::string& getName() const;
/// Returns the channel name.
void setType(ChannelType type);
/// Sets the channel name.
ChannelType getType() const;
/// Returns the channel name.
static const int INFINITE_TIMEOUT = -1;
private:
std::string _name;
ChannelType _type;
int _timeoutMS;
};
//
// inlines
//
inline void IOChannelConfig::setBlocking()
{
_timeoutMS = INFINITE_TIMEOUT;
}
inline void IOChannelConfig::setNonblocking(int timeoutMS)
{
_timeoutMS = timeoutMS;
}
inline int IOChannelConfig::getTimeout() const
{
return _timeoutMS;
}
inline bool IOChannelConfig::isBlocking() const
{
return INFINITE_TIMEOUT == _timeoutMS;
}
inline void IOChannelConfig::setName(const std::string& name)
{
_name = name;
}
inline const std::string& IOChannelConfig::getName() const
{
return _name;
}
inline void IOChannelConfig::setType(ChannelType type)
{
_type = type;
}
inline IOChannelConfig::ChannelType IOChannelConfig::getType() const
{
return _type;
}
} // namespace Poco
#endif // Foundation_IOChannelConfig_INCLUDED

View File

@ -0,0 +1,130 @@
//
// IOChannelStream.h
//
// $Id: //poco/Main/Data/include/Poco/IOChannelStream.h#1 $
//
// Library: Poco
// Package: IO
// Module: IOChannelStream
//
// Definition of the IOChannelStream class.
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#ifndef Foundation_IOChannelStream_INCLUDED
#define Foundation_IOChannelStream_INCLUDED
#include "Poco/Foundation.h"
#include "Poco/UnbufferedStreamBuf.h"
#include "Poco/IOChannel.h"
#include <istream>
#include <ostream>
namespace Poco {
class Foundation_API IOChannelStreamBuf: public UnbufferedStreamBuf
/// This is the streambuf class used for reading from and writing to a IOChannel.
{
public:
IOChannelStreamBuf(IOChannel& channel);
/// Creates a IOChannelStreamBuf with the given IOChannel.
~IOChannelStreamBuf();
/// Destroys the IOChannelStreamBuf.
void close();
/// Closes the channel.
protected:
int_type readFromDevice();
int_type writeToDevice(char c);
private:
IOChannel& _channel;
};
class Foundation_API IOChannelIOS: public virtual std::ios
/// The base class for IOChannelInputStream and
/// IOChannelOutputStream.
///
/// This class is needed to ensure the correct initialization
/// order of the stream buffer and base classes.
{
public:
IOChannelIOS(IOChannel& channel, openmode mode);
/// Creates the IOChannelIOS with the given IOChannel.
~IOChannelIOS();
/// Destroys the IOChannelIOS.
IOChannelStreamBuf* rdbuf();
/// Returns a pointer to the internal IOChannelStreamBuf.
protected:
IOChannelStreamBuf _buf;
};
class Foundation_API IOChannelOutputStream: public IOChannelIOS, public std::ostream
/// An output stream for writing to a IOChannel.
{
public:
IOChannelOutputStream(IOChannel& channel);
/// Creates the IOChannelOutputStream with the given IOChannel.
~IOChannelOutputStream();
/// Destroys the IOChannelOutputStream.
///
/// Flushes the buffer, but does not close the channel.
};
class Foundation_API IOChannelInputStream: public IOChannelIOS, public std::istream
/// An input stream for reading from a IOChannel.
///
/// Using formatted input from a IOChannelInputStream
/// is not recommended, due to the read-ahead behavior of
/// istream with formatted reads.
{
public:
IOChannelInputStream(IOChannel& channel);
/// Creates the IOChannelInputStream with the given IOChannel.
~IOChannelInputStream();
/// Destroys the IOChannelInputStream.
};
} // namespace Poco
#endif // Foundation_IOChannelStream_INCLUDED

View File

@ -0,0 +1,93 @@
//
// IOChannel.cpp
//
// $Id: //poco/svn/Foundation/src/IOChannel.cpp#2 $
//
// Library: Foundation
// Package: IO
// Module: IOChannel
//
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "Poco/IOChannel.h"
namespace Poco {
IOChannel::IOChannel(const std::string& name):
_name(name),
_pConfig(new IOChannelConfig)
{
}
IOChannel::IOChannel(IOChannelConfig* pConfig, const std::string& name):
_name(name),
_pConfig(pConfig)
{
}
IOChannel::~IOChannel()
{
}
char IOChannel::read()
{
char readBuf = 0;
char* pReadBuf = &readBuf;
readData(pReadBuf, 1);
return readBuf;
}
std::string& IOChannel::read(std::string& buffer, int length)
{
buffer.clear();
char* pBuf = 0;
int len = 0;
if (length > 0)
{
pBuf = static_cast<char*>(std::calloc(length, sizeof(char)));
len = readData(pBuf, length);
}
else
len = readData(pBuf); // must allocate buffer as needed
if (len > 0) buffer.assign(pBuf, len);
std::free(pBuf);
return buffer;
}
} // namespace Poco

View File

@ -0,0 +1,67 @@
//
// SerialConfig.cpp
//
// $Id: //poco/Main/IO/src/IOChannelConfig.cpp#1 $
//
// Library: Foundation
// Package: IO
// Module: IOChannelConfig
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "Poco/IOChannelConfig.h"
#include "Poco/Exception.h"
namespace Poco {
IOChannelConfig::IOChannelConfig(const std::string& name, ChannelType type, int timeoutMS):
_name(name),
_type(type),
_timeoutMS(timeoutMS)
{
}
IOChannelConfig::~IOChannelConfig()
{
}
void IOChannelConfig::setTimeout(int timeoutMS)
{
if (timeoutMS < 0 && INFINITE_TIMEOUT != timeoutMS)
throw InvalidArgumentException("Invalid timeout value");
_timeoutMS = timeoutMS;
}
} // namespace Poco::IO

View File

@ -0,0 +1,111 @@
//
// DigestStream.cpp
//
// $Id: //poco/1.2/IO/src/IOChannelStream.cpp#1 $
//
// Library: IO
// Package: IO
// Module: IOChannelStream
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "Poco/IOChannelStream.h"
namespace Poco {
IOChannelStreamBuf::IOChannelStreamBuf(IOChannel& channel): _channel(channel)
{
}
IOChannelStreamBuf::~IOChannelStreamBuf()
{
}
void IOChannelStreamBuf::close()
{
_channel.close();
}
UnbufferedStreamBuf::int_type IOChannelStreamBuf::readFromDevice()
{
return charToInt(_channel.read());
}
UnbufferedStreamBuf::int_type IOChannelStreamBuf::writeToDevice(char c)
{
return _channel.write(c);
}
IOChannelIOS::IOChannelIOS(IOChannel& channel, openmode mode) :_buf(channel)
{
poco_ios_init(&_buf);
}
IOChannelIOS::~IOChannelIOS()
{
}
IOChannelStreamBuf* IOChannelIOS::rdbuf()
{
return &_buf;
}
IOChannelOutputStream::IOChannelOutputStream(IOChannel& channel):
IOChannelIOS(channel, std::ios::out),
std::ostream(&_buf)
{
}
IOChannelOutputStream::~IOChannelOutputStream()
{
}
IOChannelInputStream::IOChannelInputStream(IOChannel& channel):
IOChannelIOS(channel, std::ios::in),
std::istream(&_buf)
{
}
IOChannelInputStream::~IOChannelInputStream()
{
}
} // namespace Poco