Botan  1.11.15
src/lib/filters/data_snk.h
Go to the documentation of this file.
00001 /*
00002 * DataSink
00003 * (C) 1999-2007 Jack Lloyd
00004 *
00005 * Botan is released under the Simplified BSD License (see license.txt)
00006 */
00007 
00008 #ifndef BOTAN_DATA_SINK_H__
00009 #define BOTAN_DATA_SINK_H__
00010 
00011 #include <botan/filter.h>
00012 #include <iosfwd>
00013 
00014 namespace Botan {
00015 
00016 /**
00017 * This class represents abstract data sink objects.
00018 */
00019 class BOTAN_DLL DataSink : public Filter
00020    {
00021    public:
00022       bool attachable() { return false; }
00023       DataSink() {}
00024       virtual ~DataSink() {}
00025 
00026       DataSink& operator=(const DataSink&) = delete;
00027       DataSink(const DataSink&) = delete;
00028    };
00029 
00030 /**
00031 * This class represents a data sink which writes its output to a stream.
00032 */
00033 class BOTAN_DLL DataSink_Stream : public DataSink
00034    {
00035    public:
00036       std::string name() const { return identifier; }
00037 
00038       void write(const byte[], size_t);
00039 
00040       /**
00041       * Construct a DataSink_Stream from a stream.
00042       * @param stream the stream to write to
00043       * @param name identifier
00044       */
00045       DataSink_Stream(std::ostream& stream,
00046                       const std::string& name = "<std::ostream>");
00047 
00048       /**
00049       * Construct a DataSink_Stream from a stream.
00050       * @param pathname the name of the file to open a stream to
00051       * @param use_binary indicates whether to treat the file
00052       * as a binary file or not
00053       */
00054       DataSink_Stream(const std::string& pathname,
00055                       bool use_binary = false);
00056 
00057       ~DataSink_Stream();
00058    private:
00059       const std::string identifier;
00060 
00061       std::ostream* sink_p;
00062       std::ostream& sink;
00063    };
00064 
00065 }
00066 
00067 #endif