bux API Reference 1.9.0
Static library of whatever are seen required in general purpose but not directly supported from Modern C++. Or whatever reusable originated from my side projects.
Loading...
Searching...
No Matches
MemIn.h
Go to the documentation of this file.
1#pragma once
2
3#include <istream> // std::basic_istream<>
4#include <string_view> // std::basic_string_view<>
5
6namespace bux {
7
8//
9// Types
10//
11template <class _CharT, class _Traits>
13{
14 // Data
15 struct C_IMemBuf: std::basic_streambuf<_CharT,_Traits>
16 {
17 C_IMemBuf(const _CharT *buffer, size_t size)
18 {
19 const auto beg = const_cast<_CharT*>(buffer);
20 this->setg(beg, beg, beg+size);
21 }
22 C_IMemBuf(std::basic_string_view<_CharT,_Traits> buffer)
23 {
24 const auto beg = const_cast<_CharT*>(buffer.data());
25 this->setg(beg, beg, beg+buffer.size());
26 }
28
29 // Ctor
30 C_IMemBufAsMember(const _CharT *buffer, size_t size): m_Buffer(buffer, size) {}
31 C_IMemBufAsMember(std::basic_string_view<_CharT,_Traits> buffer): m_Buffer(buffer) {}
32 C_IMemBufAsMember(std::basic_string<_CharT,_Traits> &&) = delete;
33};
34
35template <class _CharT, class _Traits = std::char_traits<_CharT>>
37 private C_IMemBufAsMember<_CharT,_Traits>,
38 public std::basic_istream<_CharT,_Traits> // Inheritance order matters
39{
40public:
41
42 // Ctors
43 C_IMemStreamT(const _CharT *buffer, size_t size):
44 C_IMemBufAsMember<_CharT,_Traits>(buffer, size),
45 std::basic_istream<_CharT,_Traits>(&this->m_Buffer)
46 {}
47 C_IMemStreamT(std::basic_string_view<_CharT,_Traits> buffer):
48 C_IMemBufAsMember<_CharT,_Traits>(buffer),
49 std::basic_istream<_CharT,_Traits>(&this->m_Buffer)
50 {}
51 C_IMemStreamT(const _CharT *str):
52 C_IMemStreamT(std::basic_string_view<_CharT,_Traits>{str})
53 {}
54 C_IMemStreamT(std::basic_string<_CharT,_Traits> &&) = delete;
55};
57
58} // namespace bux
C_IMemStreamT(const _CharT *str)
Definition MemIn.h:51
C_IMemStreamT(std::basic_string_view< _CharT, _Traits > buffer)
Definition MemIn.h:47
C_IMemStreamT(const _CharT *buffer, size_t size)
Definition MemIn.h:43
C_IMemStreamT(std::basic_string< _CharT, _Traits > &&)=delete
THE common namespace of bux library.
Definition AtomiX.cpp:3
C_IMemBuf(std::basic_string_view< _CharT, _Traits > buffer)
Definition MemIn.h:22
C_IMemBuf(const _CharT *buffer, size_t size)
Definition MemIn.h:17
C_IMemBufAsMember(std::basic_string_view< _CharT, _Traits > buffer)
Definition MemIn.h:31
bux::C_IMemBufAsMember::C_IMemBuf m_Buffer
C_IMemBufAsMember(const _CharT *buffer, size_t size)
Definition MemIn.h:30
C_IMemBufAsMember(std::basic_string< _CharT, _Traits > &&)=delete