// // LOBStream.h // // Library: Data // Package: DataCore // Module: LOBStream // // Definition of the LOBStream class. // // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. // and Contributors. // // SPDX-License-Identifier: BSL-1.0 // #ifndef Data_LOBStream_INCLUDED #define Data_LOBStream_INCLUDED #include "Poco/Foundation.h" #include "Poco/UnbufferedStreamBuf.h" #include "Poco/Data/LOB.h" #include #include namespace Poco { namespace Data { template class LOBStreamBuf: public BasicUnbufferedStreamBuf> /// This is the streambuf class used for reading from and writing to a LOB. { public: LOBStreamBuf(LOB& lob): _lob(lob), _it(_lob.begin()) /// Creates LOBStreamBuf. { } ~LOBStreamBuf() /// Destroys LOBStreamBuf. { } protected: using TraitsType = std::char_traits; using BaseType = BasicUnbufferedStreamBuf; typename BaseType::int_type readFromDevice() { if (_it != _lob.end()) return BaseType::charToInt(*_it++); else return -1; } typename BaseType::int_type writeToDevice(T c) { _lob.appendRaw(&c, 1); return 1; } private: LOB& _lob; typename LOB::Iterator _it; }; template class LOBIOS: public virtual std::ios /// The base class for LOBInputStream and /// LOBOutputStream. /// /// This class is needed to ensure the correct initialization /// order of the stream buffer and base classes. { public: LOBIOS(LOB& lob, openmode mode): _buf(lob) /// Creates the LOBIOS with the given LOB. { poco_ios_init(&_buf); } ~LOBIOS() /// Destroys the LOBIOS. { } LOBStreamBuf* rdbuf() /// Returns a pointer to the internal LOBStreamBuf. { return &_buf; } protected: LOBStreamBuf _buf; }; template class LOBOutputStream: public LOBIOS, public std::basic_ostream> /// An output stream for writing to a LOB. { public: LOBOutputStream(LOB& lob): LOBIOS(lob, std::ios::out), std::ostream(LOBIOS::rdbuf()) /// Creates the LOBOutputStream with the given LOB. { } ~LOBOutputStream() /// Destroys the LOBOutputStream. { } }; template class LOBInputStream: public LOBIOS, public std::basic_istream> /// An input stream for reading from a LOB. { public: LOBInputStream(LOB& lob): LOBIOS(lob, std::ios::in), std::istream(LOBIOS::rdbuf()) /// Creates the LOBInputStream with the given LOB. { } ~LOBInputStream() /// Destroys the LOBInputStream. { } }; using BLOBOutputStream = LOBOutputStream; using CLOBOutputStream = LOBOutputStream; using BLOBInputStream = LOBInputStream; using CLOBInputStream = LOBInputStream; } } // namespace Poco::Data #endif // Data_LOBStream_INCLUDED