byteme
C++ wrappers for buffered inputs
Loading...
Searching...
No Matches
Writer.hpp
Go to the documentation of this file.
1#ifndef BYTEME_WRITER_HPP
2#define BYTEME_WRITER_HPP
3
4#include <string>
5#include <cstring>
6
13namespace byteme {
14
18class Writer {
19public:
20 virtual ~Writer() = default;
21
29 virtual void write(const unsigned char* buffer, size_t n) = 0;
30
35 virtual void finish() = 0;
36
42 void write(const std::string& x) {
43 write(reinterpret_cast<const unsigned char*>(x.c_str()), x.size());
44 }
45
51 void write(const char* x) {
52 write(reinterpret_cast<const unsigned char*>(x), std::strlen(x));
53 }
54
60 void write(char x) {
61 write(reinterpret_cast<const unsigned char*>(&x), 1);
62 }
63};
64
65}
66
67#endif
Virtual class for writing bytes to a sink.
Definition Writer.hpp:18
void write(const std::string &x)
Definition Writer.hpp:42
void write(char x)
Definition Writer.hpp:60
virtual void write(const unsigned char *buffer, size_t n)=0
virtual void finish()=0
void write(const char *x)
Definition Writer.hpp:51
Simple byte readers and writers.