OpenVDB  1.1.0
Stream.h
Go to the documentation of this file.
1 
2 //
3 // Copyright (c) 2012-2013 DreamWorks Animation LLC
4 //
5 // All rights reserved. This software is distributed under the
6 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
7 //
8 // Redistributions of source code must retain the above copyright
9 // and license notice and the following restrictions and disclaimer.
10 //
11 // * Neither the name of DreamWorks Animation nor the names of
12 // its contributors may be used to endorse or promote products derived
13 // from this software without specific prior written permission.
14 //
15 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY INDIRECT, INCIDENTAL,
20 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 // IN NO EVENT SHALL THE COPYRIGHT HOLDERS' AND CONTRIBUTORS' AGGREGATE
27 // LIABILITY FOR ALL CLAIMS REGARDLESS OF THEIR BASIS EXCEED US$250.00.
28 //
30 
31 #ifndef OPENVDB_IO_STREAM_HAS_BEEN_INCLUDED
32 #define OPENVDB_IO_STREAM_HAS_BEEN_INCLUDED
33 
34 #include <iosfwd>
35 #include "Archive.h"
36 
37 
38 namespace openvdb {
40 namespace OPENVDB_VERSION_NAME {
41 namespace io {
42 
43 class GridDescriptor;
44 
45 
47 class OPENVDB_API Stream: public Archive
48 {
49 public:
51  explicit Stream(std::istream&);
52  Stream();
53  ~Stream();
54 
56  MetaMap::Ptr getMetadata() const;
57 
59  GridPtrVecPtr getGrids() { return mGrids; }
60 
62  template<typename GridPtrContainerT>
63  void write(std::ostream&, const GridPtrContainerT&, const MetaMap& = MetaMap()) const;
64 
65 private:
69  GridBase::Ptr readGrid(const GridDescriptor&, std::istream&) const;
70 
71  void writeGrids(std::ostream&, const GridCPtrVec&, const MetaMap&) const;
72 
73  // Disallow copying of instances of this class.
74  Stream(const Stream&);
75  Stream& operator=(const Stream&);
76 
77 
78  MetaMap::Ptr mMeta;
79  GridPtrVecPtr mGrids;
80 };
81 
82 
84 
85 
86 template<typename GridPtrContainerT>
87 inline void
88 Stream::write(std::ostream& os, const GridPtrContainerT& container,
89  const MetaMap& metadata) const
90 {
91  GridCPtrVec grids;
92  std::copy(container.begin(), container.end(), std::back_inserter(grids));
93  this->writeGrids(os, grids, metadata);
94 }
95 
96 template<>
97 inline void
98 Stream::write<GridCPtrVec>(std::ostream& os, const GridCPtrVec& grids,
99  const MetaMap& metadata) const
100 {
101  this->writeGrids(os, grids, metadata);
102 }
103 
104 } // namespace io
105 } // namespace OPENVDB_VERSION_NAME
106 } // namespace openvdb
107 
108 #endif // OPENVDB_IO_STREAM_HAS_BEEN_INCLUDED
109 
110 // Copyright (c) 2012-2013 DreamWorks Animation LLC
111 // All rights reserved. This software is distributed under the
112 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )