mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2025-01-31 18:07:14 +01:00
4a6bfc086c
Switched to POCO library for unified platform/library interface. Deprecated the external module API. It was creating more problems than solving. Removed most built-in libraries in favor of system libraries for easier maintenance. Cleaned and secured code with help from static analyzers.
151 lines
2.8 KiB
C++
151 lines
2.8 KiB
C++
//
|
|
// 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 <istream>
|
|
#include <ostream>
|
|
|
|
|
|
namespace Poco {
|
|
namespace Data {
|
|
|
|
|
|
template <typename T>
|
|
class LOBStreamBuf: public BasicUnbufferedStreamBuf<T, std::char_traits<T>>
|
|
/// This is the streambuf class used for reading from and writing to a LOB.
|
|
{
|
|
public:
|
|
LOBStreamBuf(LOB<T>& lob): _lob(lob), _it(_lob.begin())
|
|
/// Creates LOBStreamBuf.
|
|
{
|
|
}
|
|
|
|
|
|
~LOBStreamBuf()
|
|
/// Destroys LOBStreamBuf.
|
|
{
|
|
}
|
|
|
|
protected:
|
|
using TraitsType = std::char_traits<T>;
|
|
using BaseType = BasicUnbufferedStreamBuf<T, TraitsType>;
|
|
|
|
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<T>& _lob;
|
|
typename LOB<T>::Iterator _it;
|
|
};
|
|
|
|
|
|
template <typename T>
|
|
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<T>& lob, openmode mode): _buf(lob)
|
|
/// Creates the LOBIOS with the given LOB.
|
|
{
|
|
poco_ios_init(&_buf);
|
|
}
|
|
|
|
~LOBIOS()
|
|
/// Destroys the LOBIOS.
|
|
{
|
|
}
|
|
|
|
LOBStreamBuf<T>* rdbuf()
|
|
/// Returns a pointer to the internal LOBStreamBuf.
|
|
{
|
|
return &_buf;
|
|
}
|
|
|
|
protected:
|
|
LOBStreamBuf<T> _buf;
|
|
};
|
|
|
|
|
|
template <typename T>
|
|
class LOBOutputStream: public LOBIOS<T>, public std::basic_ostream<T, std::char_traits<T>>
|
|
/// An output stream for writing to a LOB.
|
|
{
|
|
public:
|
|
LOBOutputStream(LOB<T>& lob):
|
|
LOBIOS<T>(lob, std::ios::out),
|
|
std::ostream(LOBIOS<T>::rdbuf())
|
|
/// Creates the LOBOutputStream with the given LOB.
|
|
{
|
|
}
|
|
|
|
~LOBOutputStream()
|
|
/// Destroys the LOBOutputStream.
|
|
{
|
|
}
|
|
};
|
|
|
|
|
|
template <typename T>
|
|
class LOBInputStream: public LOBIOS<T>, public std::basic_istream<T, std::char_traits<T>>
|
|
/// An input stream for reading from a LOB.
|
|
{
|
|
public:
|
|
LOBInputStream(LOB<T>& lob):
|
|
LOBIOS<T>(lob, std::ios::in),
|
|
std::istream(LOBIOS<T>::rdbuf())
|
|
/// Creates the LOBInputStream with the given LOB.
|
|
{
|
|
}
|
|
|
|
~LOBInputStream()
|
|
/// Destroys the LOBInputStream.
|
|
{
|
|
}
|
|
};
|
|
|
|
|
|
using BLOBOutputStream = LOBOutputStream<unsigned char>;
|
|
using CLOBOutputStream = LOBOutputStream<char>;
|
|
|
|
using BLOBInputStream = LOBInputStream<unsigned char>;
|
|
using CLOBInputStream = LOBInputStream<char>;
|
|
|
|
} } // namespace Poco::Data
|
|
|
|
|
|
#endif // Data_LOBStream_INCLUDED
|