3#ifndef vtkMemoryResourceStream_h
4#define vtkMemoryResourceStream_h
7#include "vtkIOCoreModule.h"
15VTK_ABI_NAMESPACE_BEGIN
31 BasicHolder() =
default;
32 virtual ~BasicHolder() =
default;
33 BasicHolder(
const BasicHolder&) =
delete;
34 BasicHolder& operator=(
const BasicHolder&) =
delete;
35 BasicHolder(BasicHolder&&)
noexcept =
delete;
36 BasicHolder& operator=(BasicHolder&&)
noexcept =
delete;
46 struct DataHolder :
public BasicHolder
48 template <
typename... Args>
49 DataHolder(Args&&... args)
50 : Data{ std::forward<Args>(args)... }
54 ~DataHolder()
override =
default;
55 DataHolder(
const DataHolder&) =
delete;
56 DataHolder& operator=(
const DataHolder&) =
delete;
57 DataHolder(DataHolder&&)
noexcept =
delete;
58 DataHolder& operator=(DataHolder&&)
noexcept =
delete;
65 static std::unique_ptr<DataHolder<T>> MakeHolder(T&& value)
67 return std::unique_ptr<DataHolder<T>>{
new DataHolder<T>{ std::forward<T>(value) } };
79 std::size_t
Read(
void* buffer, std::size_t bytes)
override;
82 vtkTypeInt64
Tell()
override;
104 void SetBuffer(
const void* buffer, std::size_t size,
bool copy =
false);
122 template <
typename T>
127 this->SetBuffer(buffer->GetBuffer(), buffer->GetSize() *
sizeof(T));
128 this->Holder = MakeHolder(std::move(buffer));
132 this->SetBuffer(
nullptr, 0);
152 template <
typename T,
typename Allocator>
155 this->SetBuffer(vec.data(), vec.size() *
sizeof(T));
156 this->Holder = MakeHolder(std::move(vec));
166 template <
typename CharT,
typename Traits,
typename Allocator>
167 void SetBuffer(std::basic_string<CharT, Traits, Allocator> str)
172 auto holder = MakeHolder(std::move(str));
173 this->SetBuffer(holder->Data.data(), holder->Data.size() *
sizeof(CharT));
174 this->Holder = std::move(holder);
194 const unsigned char* Buffer =
nullptr;
195 std::size_t Size = 0;
196 vtkTypeInt64 Pos = 0;
198 std::unique_ptr<BasicHolder> Holder;
internal storage class used by vtkSOADataArrayTemplate, vtkAOSDataArrayTemplate, and others.
a simple class to control print indentation
vtkResourceStream implementation for memory input.
void SetBuffer(const void *buffer, std::size_t size, bool copy=false)
Set buffer to stream.
std::size_t Read(void *buffer, std::size_t bytes) override
Override vtkResourceStream functions.
vtkMemoryResourceStream(const vtkMemoryResourceStream &)=delete
vtkTypeInt64 Seek(vtkTypeInt64 pos, SeekDirection dir) override
Override vtkResourceStream functions.
vtkTypeInt64 Tell() override
Override vtkResourceStream functions.
void SetBuffer(std::vector< T, Allocator > vec)
Set buffer to stream.
void SetBuffer(vtkSmartPointer< vtkBuffer< T > > buffer)
Set buffer to stream.
static vtkMemoryResourceStream * New()
~vtkMemoryResourceStream() override=default
bool OwnsBuffer() const
Check if this has a internally managed buffer.
vtkMemoryResourceStream & operator=(const vtkMemoryResourceStream &)=delete
vtkMemoryResourceStream()
void SetBuffer(std::basic_string< CharT, Traits, Allocator > str)
Set buffer to stream.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
bool EndOfStream() override
Override vtkResourceStream functions.
Abstract class used for custom streams.
Hold a reference to a vtkObjectBase instance.