OpenVDB 11.0.0
Loading...
Searching...
No Matches
Stream.h
Go to the documentation of this file.
1// Copyright Contributors to the OpenVDB Project
2// SPDX-License-Identifier: MPL-2.0
3
4#ifndef OPENVDB_IO_STREAM_HAS_BEEN_INCLUDED
5#define OPENVDB_IO_STREAM_HAS_BEEN_INCLUDED
6
7#include "Archive.h"
8#include <iosfwd>
9#include <memory>
10
11
12namespace openvdb {
14namespace OPENVDB_VERSION_NAME {
15namespace io {
16
17class GridDescriptor;
18
19
20/// Grid archive associated with arbitrary input and output streams (not necessarily files)
22{
23public:
24 /// @brief Read grids from an input stream.
25 /// @details If @a delayLoad is true, map the contents of the input stream
26 /// into memory and enable delayed loading of grids.
27 /// @note Define the environment variable @c OPENVDB_DISABLE_DELAYED_LOAD
28 /// to disable delayed loading unconditionally.
29 explicit Stream(std::istream&, bool delayLoad = true);
30
31 /// Construct an archive for stream output.
33 /// Construct an archive for output to the given stream.
34 explicit Stream(std::ostream&);
35
36 Stream(const Stream&);
38
39 ~Stream() override;
40
41 /// @brief Return a copy of this archive.
42 Archive::Ptr copy() const override;
43
44 /// Return the file-level metadata in a newly created MetaMap.
46
47 /// Return pointers to the grids that were read from the input stream.
49
50 /// @brief Write the grids in the given container to this archive's output stream.
51 /// @throw ValueError if this archive was constructed without specifying an output stream.
52 void write(const GridCPtrVec&, const MetaMap& = MetaMap()) const override;
53
54 /// @brief Write the grids in the given container to this archive's output stream.
55 /// @throw ValueError if this archive was constructed without specifying an output stream.
56 template<typename GridPtrContainerT>
57 void write(const GridPtrContainerT&, const MetaMap& = MetaMap()) const;
58
59private:
60 /// Create a new grid of the type specified by the given descriptor,
61 /// then populate the grid from the given input stream.
62 /// @return the newly created grid.
63 GridBase::Ptr readGrid(const GridDescriptor&, std::istream&) const;
64
65 void writeGrids(std::ostream&, const GridCPtrVec&, const MetaMap&) const;
66
67
68 struct Impl;
69 std::unique_ptr<Impl> mImpl;
70};
71
72
73////////////////////////////////////////
74
75
76template<typename GridPtrContainerT>
77inline void
78Stream::write(const GridPtrContainerT& container, const MetaMap& metadata) const
79{
80 GridCPtrVec grids;
81 std::copy(container.begin(), container.end(), std::back_inserter(grids));
82 this->write(grids, metadata);
83}
84
85} // namespace io
86} // namespace OPENVDB_VERSION_NAME
87} // namespace openvdb
88
89#endif // OPENVDB_IO_STREAM_HAS_BEEN_INCLUDED
#define OPENVDB_API
Definition Platform.h:274
SharedPtr< GridBase > Ptr
Definition Grid.h:80
Container that maps names (strings) to values of arbitrary types.
Definition MetaMap.h:20
SharedPtr< MetaMap > Ptr
Definition MetaMap.h:22
Grid serializer/unserializer.
Definition Archive.h:32
SharedPtr< Archive > Ptr
Definition Archive.h:34
Definition GridDescriptor.h:20
Grid archive associated with arbitrary input and output streams (not necessarily files)
Definition Stream.h:22
Stream & operator=(const Stream &)
GridPtrVecPtr getGrids()
Return pointers to the grids that were read from the input stream.
void write(const GridCPtrVec &, const MetaMap &=MetaMap()) const override
Write the grids in the given container to this archive's output stream.
Stream()
Construct an archive for stream output.
Archive::Ptr copy() const override
Return a copy of this archive.
MetaMap::Ptr getMetadata() const
Return the file-level metadata in a newly created MetaMap.
Stream(std::ostream &)
Construct an archive for output to the given stream.
Stream(std::istream &, bool delayLoad=true)
Read grids from an input stream.
SharedPtr< GridPtrVec > GridPtrVecPtr
Definition Grid.h:511
std::vector< GridBase::ConstPtr > GridCPtrVec
Definition Grid.h:513
Definition Exceptions.h:13
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition version.h.in:121
#define OPENVDB_USE_VERSION_NAMESPACE
Definition version.h.in:212