OpenVDB 14.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 {
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 /// @param is The input stream to read from
26 explicit Stream(std::istream& is);
27
28 /// @brief Read grids from an input stream using the given read options.
29 /// @param is The input stream to read from
30 /// @param readOptions Options controlling how grids are read (e.g. attribute
31 /// skipping for point data grids)
32 /// @throw ValueError if @a readOptions requests @c io::ReadMode::MetadataOnly
33 /// or @c io::ReadMode::TopologyOnly. These modes leave a grid's data
34 /// partially unread, which a sequentially read stream cannot skip over.
35 Stream(std::istream& is, const io::ReadOptions& readOptions);
36
37 /// Construct an archive for stream output.
38 Stream() = default;
39 /// Construct an archive for output to the given stream.
40 explicit Stream(std::ostream&);
41
42 Stream(const Stream&);
44
45 ~Stream() override { }
46
47 /// @brief Return a copy of this archive.
48 Archive::Ptr copy() const override;
49
50 /// Return the file-level metadata in a newly created MetaMap.
52
53 /// Return pointers to the grids that were read from the input stream.
55
56 /// @brief Write the grids in the given container to this archive's output stream.
57 /// @throw ValueError if this archive was constructed without specifying an output stream.
58 void write(const GridCPtrVec&, const MetaMap& = MetaMap(),
59 const io::WriteOptions& = io::WriteOptions{}) const override;
60
61 /// @brief Write the grids in the given container to this archive's output stream.
62 /// @throw ValueError if this archive was constructed without specifying an output stream.
63 template<typename GridPtrContainerT>
64 void write(const GridPtrContainerT&, const MetaMap& = MetaMap(),
65 const io::WriteOptions& = io::WriteOptions{}) const;
66
67private:
68 void writeGrids(std::ostream&, const GridCPtrVec&, const MetaMap&,
69 const io::WriteOptions&) const;
70
71 MetaMap::Ptr mMeta;
72 GridPtrVecPtr mGrids;
73 std::ostream* mOutputStream = nullptr;
74};
75
76
77////////////////////////////////////////
78
79
80template<typename GridPtrContainerT>
81inline void
82Stream::write(const GridPtrContainerT& container, const MetaMap& metadata,
83 const io::WriteOptions& writeOptions) const
84{
85 GridCPtrVec grids;
86 std::copy(container.begin(), container.end(), std::back_inserter(grids));
87 this->write(grids, metadata, writeOptions);
88}
89
90} // namespace io
91} // namespace OPENVDB_VERSION_NAME
92} // namespace openvdb
93
94#endif // OPENVDB_IO_STREAM_HAS_BEEN_INCLUDED
#define OPENVDB_API
Definition Platform.h:286
Container that maps names (strings) to values of arbitrary types.
Definition MetaMap.h:20
SharedPtr< MetaMap > Ptr
Definition MetaMap.h:22
SharedPtr< Archive > Ptr
Definition Archive.h:38
Stream & operator=(const Stream &)
GridPtrVecPtr getGrids()
Return pointers to the grids that were read from the input stream.
Stream()=default
Construct an archive for stream output.
Stream(std::istream &is)
Read grids from an input stream.
Archive::Ptr copy() const override
Return a copy of this archive.
Stream(std::istream &is, const io::ReadOptions &readOptions)
Read grids from an input stream using the given read options.
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.
void write(const GridCPtrVec &, const MetaMap &=MetaMap(), const io::WriteOptions &=io::WriteOptions{}) const override
Write the grids in the given container to this archive's output stream.
~Stream() override
Definition Stream.h:45
SharedPtr< GridPtrVec > GridPtrVecPtr
Definition Grid.h:511
std::vector< GridBase::ConstPtr > GridCPtrVec
Definition Grid.h:513
Definition Exceptions.h:13
Global read configuration passed to every codec during deserialization.
Definition Codec.h:167
Global write configuration passed to every codec during serialization.
Definition Codec.h:188
#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:291