-
Notifications
You must be signed in to change notification settings - Fork 113
/
InputObjectIOstream.h
45 lines (34 loc) · 941 Bytes
/
InputObjectIOstream.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//
// Created by Dusan Klinec on 02.01.18.
//
#ifndef WHITEBOX_CRYPTO_AES_INPUTOBJECTIOSTREAM_H
#define WHITEBOX_CRYPTO_AES_INPUTOBJECTIOSTREAM_H
#include "InputObject.h"
#include <fstream>
#include <iostream>
#include <stdexcept>
template<typename T>
class InputObjectIOstream : public InputObject<T>{
public:
explicit InputObjectIOstream(std::iostream *ios) : ios(ios) {}
ssize_t write(const T *buffer, size_t maxSize) override {
ios->write((const char*)buffer, maxSize);
return maxSize;
}
ssize_t read(T *buffer, size_t maxSize) override {
ios->read((char*)buffer, maxSize);
return ios->gcount();
}
bool isGood() override {
return ios->good();
}
bool eof() override {
return ios->eof();
}
bool isFull() override {
return !ios->good();
}
protected:
std::iostream * ios;
};
#endif //WHITEBOX_CRYPTO_AES_INPUTOBJECTIOSTREAM_H