我已经为二进制I / O创建了自己的自定义流类。现在我正在尝试使它们与Crypto ++库兼容。我找到了question来处理自定义接收器并实现了我自己的接收器。现在我需要实现一个源代码。我搜索了文档,似乎有一个巨大的继承层次结构,所以我还不能理解它。
有人可以提供示例代码吗?
这是我的流类的一部分:
/// \brief Base class for a binary input stream.
/// \details Binary streams are used for low level unformatted I/O. Built on top
/// of standard streams, this system takes care of endianness and provides
/// convenient << and >> overloads. This class is designed to mirror
/// std::istream.
class BinaryInputStream : public virtual BinaryStreamBase
{
public:
/// \brief Returns whether last I/O operation has completed successfully.
/// \return True if last I/O operation has completed successfully,
/// false otherwise.
virtual bool IsGood() const = 0;
/// \brief Returns whether end-of-file has been reached.
/// \return True if end-of-file has been reached, false otherwise.
virtual bool IsEOF() const = 0;
/// \brief Returns whether recoverable error has occured.
/// \return True if recoverable error has occured, false otherwise.
virtual bool IsFail() const = 0;
/// \brief Returns whether non-recoverable error has occured.
/// \return True if non-recoverable error has occured, false otherwise.
virtual bool IsBad() const = 0;
/// \brief Reads a sequence of bytes from the stream.
/// \param[in,out] buffer Buffer to write to.
/// \param[in] size Number of bytes to read.
/// \return Reference to this stream.
/// \warning You are responsible for allocating the buffer and ensuring that
/// it contains enough space to hold the data. If number of bytes to read is
/// greater than the size of the buffer, the behavior is undefined.
virtual BinaryInputStream& Read(char* buffer, std::size_t size) = 0;
};
答案 0 :(得分:0)
我必须查看crypto ++的源代码并从FileSource
类复制大部分实现。相关文件为files.h
和files.cpp
。
首先,我们需要查看FileSource
类。它继承自SourceTemplate<FileStore>
。所以我们需要检查FileStore
类。它继承自Store
,FilterPutSpaceHelper
和NotCopyable
。我们需要创建也继承自这些类的类。
我们的商店类必须具有默认构造函数并实现以下虚函数:TransferTo2
,CopyRangeTo2
和StoreInitialize
。 StoreInitialize
可以是私密的。
最后,我们的源类只需要构造函数,如果你看files.h
,FileSource
完全在头文件中实现。