CatapultServer  v0.5.0.1 (Elephant)
RawBuffer.h
Go to the documentation of this file.
1 
21 #pragma once
22 #include "traits/Traits.h"
23 #include <ostream>
24 #include <string>
25 #include <stddef.h>
26 #include <stdint.h>
27 
28 namespace catapult { namespace utils {
29 
31  template<typename T>
33  public:
35  constexpr BasicRawBuffer() : BasicRawBuffer(nullptr, 0)
36  {}
37 
39  template<
40  typename TContainer,
41  // disable when copy/move constructors should be used
42  typename X = std::enable_if_t<!traits::is_base_of_ignore_reference_v<BasicRawBuffer, TContainer>>,
43  // disable when other constructors are better match
44  typename Y = std::enable_if_t<!std::is_scalar_v<TContainer>>
45  >
46  BasicRawBuffer(TContainer&& container) : BasicRawBuffer(container.data(), container.size())
47  {}
48 
50  constexpr BasicRawBuffer(T* pRawBuffer, size_t size) : pData(pRawBuffer), Size(size)
51  {}
52 
53  public:
55  T* pData;
56 
58  size_t Size;
59  };
60 
63 
66 
68  class RawString : public BasicRawBuffer<const char> {
69  public:
71 
72  public:
74  constexpr RawString() : BasicRawBuffer()
75  {}
76 
78  RawString(const char* str);
79  };
80 
82  class MutableRawString : public BasicRawBuffer<char> {
83  public:
85 
86  public:
89  {}
90 
92  MutableRawString(std::string& str);
93  };
94 
96  template<
97  typename T,
98  typename X = std::enable_if_t<std::is_same_v<char, typename std::remove_const_t<T>>>>
99  std::ostream& operator<<(std::ostream& out, const BasicRawBuffer<T>& str) {
100  out.write(str.pData, static_cast<std::streamsize>(str.Size));
101  return out;
102  }
103 }}
RawBuffer.h
catapult::utils::BasicRawBuffer::BasicRawBuffer
constexpr BasicRawBuffer(T *pRawBuffer, size_t size)
Creates buffer around pRawBuffer pointer and size.
Definition: RawBuffer.h:50
catapult::utils::RawString::RawString
constexpr RawString()
Creates an empty string buffer.
Definition: RawBuffer.h:74
catapult::utils::BasicRawBuffer
Basic raw buffer that is composed of a pointer and a size.
Definition: RawBuffer.h:32
size
uint64_t size
Definition: MemoryCounters.cpp:65
catapult::utils::MutableRawString
A mutable string buffer.
Definition: RawBuffer.h:82
catapult::utils::BasicRawBuffer::Size
size_t Size
Data size.
Definition: RawBuffer.h:58
catapult::utils::RawString
A const string buffer.
Definition: RawBuffer.h:68
catapult::utils::operator<<
std::ostream & operator<<(std::ostream &out, const BlockSpan &blockSpan)
Insertion operator for outputting blockSpan to out.
Definition: BlockSpan.cpp:27
catapult::utils::BasicRawBuffer::pData
T * pData
Data pointer.
Definition: RawBuffer.h:55
catapult::utils::BasicRawBuffer::BasicRawBuffer
BasicRawBuffer(TContainer &&container)
Creates a buffer around the entire contents of container.
Definition: RawBuffer.h:46
Traits.h
catapult
Definition: AddressExtractionExtension.cpp:28
catapult::utils::BasicRawBuffer::BasicRawBuffer
constexpr BasicRawBuffer()
Creates an empty buffer.
Definition: RawBuffer.h:35
catapult::utils::MutableRawString::MutableRawString
constexpr MutableRawString()
Creates an empty mutable string buffer.
Definition: RawBuffer.h:88