------------------------------------------------------------------------------
| 19 | |
| 20 | //------------------------------------------------------------------------------ |
| 21 | void vtkMemoryResourceStream::SetBuffer(const void* buffer, std::size_t size, bool copy) |
| 22 | { |
| 23 | if (buffer == nullptr && size != 0) |
| 24 | { |
| 25 | vtkErrorMacro("buffer must not be nullptr if size > 0"); |
| 26 | return; |
| 27 | } |
| 28 | |
| 29 | this->Size = size; |
| 30 | this->Pos = 0; |
| 31 | this->Eos = (this->Size == 0); |
| 32 | this->Holder.reset(); |
| 33 | |
| 34 | if (copy && size > 0) |
| 35 | { |
| 36 | std::unique_ptr<unsigned char[]> ptr{ new unsigned char[size] }; |
| 37 | std::memcpy(ptr.get(), buffer, size); |
| 38 | |
| 39 | this->Buffer = ptr.get(); |
| 40 | this->Holder = MakeHolder(std::move(ptr)); |
| 41 | } |
| 42 | else |
| 43 | { |
| 44 | this->Buffer = static_cast<const unsigned char*>(buffer); |
| 45 | } |
| 46 | |
| 47 | this->Modified(); |
| 48 | } |
| 49 | |
| 50 | //------------------------------------------------------------------------------ |
| 51 | std::size_t vtkMemoryResourceStream::Read(void* buffer, std::size_t bytes) |