AnCH Framework 0.1
Another C++ Hack Framework
 
Loading...
Searching...
No Matches
iostream.hpp
1/*
2 ANCH Framework: ANother C++ Hack is a C++ framework based on C++11 standard
3 Copyright (C) 2020 Vincent Lachenal
4
5 This file is part of ANCH Framework.
6
7 ANCH Framework is free software: you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 ANCH Framework is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with ANCH Framework. If not, see <http://www.gnu.org/licenses/>.
19*/
20#pragma once
21
22#include <streambuf>
23#include <cstring>
24#include <sstream>
25#include <functional>
26
27namespace anch::cutils {
28
36 enum class Direction {
37
39 IN = 0b01,
40
42 OUT = 0b10,
43
45 INOUT = 0b11,
46
47 };
48
58 struct cbuffer {
59
61 char* data;
62
64 std::size_t size;
65
67 std::function<std::size_t(char*,std::size_t)> read = nullptr;
68
70 std::function<std::size_t(char*,std::size_t)> write = nullptr;
71
72 };
73
74 // Classes declaration for \c friend usage +
75 class CIStream;
76 class COStream;
77 class CIOStream;
78 // Classes declaration for \c friend usage -
79
87 class CStreambuf: public std::streambuf {
88
92
93 // Attributes +
94 private:
97
99 bool _deleteBuffer;
100 // Attributes -
101
102 // Constructors +
103 public:
112 CStreambuf(anch::cutils::cbuffer cbuffer, anch::cutils::Direction dir);
113
114 protected:
118 CStreambuf() noexcept;
119 // Constructors -
120
121 // Destructor +
122 public:
126 virtual ~CStreambuf();
127 // Destructor -
128
129 // Methods +
130 public:
136 virtual std::streambuf::int_type underflow();
137
145 virtual std::streambuf::int_type overflow(std::streambuf::int_type value);
146
152 virtual int sync();
153
154 private:
158 void initBuffer();
159 // Methods -
160
161 };
162
170 class CIStream: public std::istream {
171
172 // Constructors +
173 public:
182
183 protected:
188 // Constructors -
189
190 // Destructor +
191 public:
195 virtual ~CIStream();
196 // Destructor -
197
198 // Methods +
199 protected:
208 // Methods -
209
210 };
211
219 class COStream: public std::ostream {
220
221 // Constructors +
222 public:
231
232 protected:
237 // Constructors -
238
239
240 // Destructor +
241 public:
245 virtual ~COStream();
246 // Destructor -
247
248 // Methods +
249 protected:
258 // Methods -
259
260 };
261
269 class CIOStream: public std::iostream {
270
271 // Constructors +
272 public:
281
282 protected:
287 // Constructors -
288
289
290 // Destructor +
291 public:
295 virtual ~CIOStream();
296 // Destructor -
297
298 // Methods +
299 protected:
308 // Methods -
309
310 };
311
312}
Definition iostream.hpp:269
CIOStream(anch::cutils::cbuffer cbuffer)
void setBuffer(anch::cutils::cbuffer cbuffer)
Definition iostream.hpp:170
void setBuffer(anch::cutils::cbuffer cbuffer)
CIStream(anch::cutils::cbuffer cbuffer)
Definition iostream.hpp:219
COStream(anch::cutils::cbuffer cbuffer)
void setBuffer(anch::cutils::cbuffer cbuffer)
virtual std::streambuf::int_type underflow()
CStreambuf(anch::cutils::cbuffer cbuffer, anch::cutils::Direction dir)
virtual std::streambuf::int_type overflow(std::streambuf::int_type value)
C buffer.
Definition iostream.hpp:58
std::function< std::size_t(char *, std::size_t)> read
Definition iostream.hpp:67
std::function< std::size_t(char *, std::size_t)> write
Definition iostream.hpp:70
char * data
Definition iostream.hpp:61
std::size_t size
Definition iostream.hpp:64