OpenVDB: openvdb/io/Stream.h Source File

OpenVDB 13.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: Apache-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 {
13 OPENVDB_USE_VERSION_NAMESPACE
14namespace OPENVDB_VERSION_NAME {
15namespace io {
16
17class GridDescriptor;
18
19
20/// Grid archive associated with arbitrary input and output streams (not necessarily files)
21 class OPENVDB_API Stream: public Archive
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.
32 Stream();
33 /// Construct an archive for output to the given stream.
34 explicit Stream(std::ostream&);
35
36 Stream(const Stream&);
37 Stream& operator=(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.
45 MetaMap::Ptr getMetadata() const;
46
47 /// Return pointers to the grids that were read from the input stream.
48 GridPtrVecPtr getGrids();
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
78 Stream::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
Archive.h
OPENVDB_API
#define OPENVDB_API
Definition Platform.h:291
openvdb::v13_0::GridBase::Ptr
SharedPtr< GridBase > Ptr
Definition Grid.h:80
openvdb::v13_0::MetaMap
Container that maps names (strings) to values of arbitrary types.
Definition MetaMap.h:20
openvdb::v13_0::MetaMap::Ptr
SharedPtr< MetaMap > Ptr
Definition MetaMap.h:22
openvdb::v13_0::io::Archive::Archive
Archive()
openvdb::v13_0::io::Archive::Ptr
SharedPtr< Archive > Ptr
Definition Archive.h:34
openvdb::v13_0::io::GridDescriptor
Definition GridDescriptor.h:20
openvdb::v13_0::io::Stream::Stream
Stream(const Stream &)
openvdb::v13_0::io::Stream::operator=
Stream & operator=(const Stream &)
openvdb::v13_0::io::Stream::getGrids
GridPtrVecPtr getGrids()
Return pointers to the grids that were read from the input stream.
openvdb::v13_0::io::Stream::write
void write(const GridCPtrVec &, const MetaMap &=MetaMap()) const override
Write the grids in the given container to this archive's output stream.
openvdb::v13_0::io::Stream::Stream
Stream()
Construct an archive for stream output.
openvdb::v13_0::io::Stream::copy
Archive::Ptr copy() const override
Return a copy of this archive.
openvdb::v13_0::io::Stream::getMetadata
MetaMap::Ptr getMetadata() const
Return the file-level metadata in a newly created MetaMap.
openvdb::v13_0::io::Stream::Stream
Stream(std::ostream &)
Construct an archive for output to the given stream.
openvdb::v13_0::io::Stream::~Stream
~Stream() override
openvdb::v13_0::io::Stream::Stream
Stream(std::istream &, bool delayLoad=true)
Read grids from an input stream.
openvdb::v13_0::GridPtrVecPtr
SharedPtr< GridPtrVec > GridPtrVecPtr
Definition Grid.h:511
openvdb::v13_0::GridCPtrVec
std::vector< GridBase::ConstPtr > GridCPtrVec
Definition Grid.h:513
openvdb
Definition Exceptions.h:13
OPENVDB_VERSION_NAME
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition version.h.in:121
OPENVDB_USE_VERSION_NAMESPACE
#define OPENVDB_USE_VERSION_NAMESPACE
Definition version.h.in:218