monotone

monotone Mtn Source Tree

Root/cryptopp/files.h

1#ifndef CRYPTOPP_FILES_H
2#define CRYPTOPP_FILES_H
3
4#include "cryptlib.h"
5#include "filters.h"
6
7#include <iostream>
8#include <fstream>
9
10NAMESPACE_BEGIN(CryptoPP)
11
12//! .
13class FileStore : public Store, private FilterPutSpaceHelper
14{
15public:
16class Err : public Exception
17{
18public:
19Err(const std::string &s) : Exception(IO_ERROR, s) {}
20};
21class OpenErr : public Err {public: OpenErr(const std::string &filename) : Err("FileStore: error opening file for reading: " + filename) {}};
22class ReadErr : public Err {public: ReadErr() : Err("FileStore: error reading file") {}};
23
24FileStore() : m_stream(NULL) {}
25FileStore(std::istream &in)
26{StoreInitialize(MakeParameters("InputStreamPointer", &in));}
27FileStore(const char *filename)
28{StoreInitialize(MakeParameters("InputFileName", filename));}
29
30std::istream* GetStream() {return m_stream;}
31
32unsigned long MaxRetrievable() const;
33unsigned int TransferTo2(BufferedTransformation &target, unsigned long &transferBytes, const std::string &channel=NULL_CHANNEL, bool blocking=true);
34unsigned int CopyRangeTo2(BufferedTransformation &target, unsigned long &begin, unsigned long end=ULONG_MAX, const std::string &channel=NULL_CHANNEL, bool blocking=true) const;
35
36private:
37void StoreInitialize(const NameValuePairs &parameters);
38
39std::ifstream m_file;
40std::istream *m_stream;
41byte *m_space;
42unsigned int m_len;
43bool m_waiting;
44};
45
46//! .
47class FileSource : public SourceTemplate<FileStore>
48{
49public:
50typedef FileStore::Err Err;
51typedef FileStore::OpenErr OpenErr;
52typedef FileStore::ReadErr ReadErr;
53
54FileSource(BufferedTransformation *attachment = NULL)
55: SourceTemplate<FileStore>(attachment) {}
56FileSource(std::istream &in, bool pumpAll, BufferedTransformation *attachment = NULL)
57: SourceTemplate<FileStore>(attachment) {SourceInitialize(pumpAll, MakeParameters("InputStreamPointer", &in));}
58FileSource(const char *filename, bool pumpAll, BufferedTransformation *attachment = NULL, bool binary=true)
59: SourceTemplate<FileStore>(attachment) {SourceInitialize(pumpAll, MakeParameters("InputFileName", filename)("InputBinaryMode", binary));}
60
61std::istream* GetStream() {return m_store.GetStream();}
62};
63
64//! .
65class FileSink : public Sink
66{
67public:
68class Err : public Exception
69{
70public:
71Err(const std::string &s) : Exception(IO_ERROR, s) {}
72};
73class OpenErr : public Err {public: OpenErr(const std::string &filename) : Err("FileSink: error opening file for writing: " + filename) {}};
74class WriteErr : public Err {public: WriteErr() : Err("FileSink: error writing file") {}};
75
76FileSink() : m_stream(NULL) {}
77FileSink(std::ostream &out)
78{IsolatedInitialize(MakeParameters("OutputStreamPointer", &out));}
79FileSink(const char *filename, bool binary=true)
80{IsolatedInitialize(MakeParameters("OutputFileName", filename)("OutputBinaryMode", binary));}
81
82std::ostream* GetStream() {return m_stream;}
83
84void IsolatedInitialize(const NameValuePairs &parameters);
85unsigned int Put2(const byte *inString, unsigned int length, int messageEnd, bool blocking);
86bool IsolatedFlush(bool hardFlush, bool blocking);
87
88private:
89std::ofstream m_file;
90std::ostream *m_stream;
91};
92
93NAMESPACE_END
94
95#endif

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status