// // 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 #include 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