OpenVDB 5.1.0

Queue.h
Go to the documentation of this file.
1 //
3 // Copyright (c) 2012-2018 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
33
34 #ifndef OPENVDB_IO_QUEUE_HAS_BEEN_INCLUDED
35 #define OPENVDB_IO_QUEUE_HAS_BEEN_INCLUDED
36
37 #include <openvdb/Types.h>
38 #include <openvdb/Grid.h>
39 #include <algorithm> // for std::copy
40 #include <functional>
41 #include <iterator> // for std::back_inserter
42 #include <memory>
43
44
45 namespace openvdb {
46 OPENVDB_USE_VERSION_NAMESPACE
47 namespace OPENVDB_VERSION_NAME {
48 namespace io {
49
50 class Archive;
51
127 class OPENVDB_API Queue
128 {
129 public:
131 static const Index32 DEFAULT_CAPACITY = 100;
134 static const Index32 DEFAULT_TIMEOUT = 120; // seconds
135
137 using Id = Index32;
138
140 enum Status { UNKNOWN, PENDING, SUCCEEDED, FAILED };
141
142
144 explicit Queue(Index32 capacity = DEFAULT_CAPACITY);
146 ~Queue();
147
149 bool empty() const;
151 Index32 size() const;
152
156 Index32 capacity() const;
158 void setCapacity(Index32);
159
161 Index32 timeout() const;
163 void setTimeout(Index32 seconds = DEFAULT_TIMEOUT);
164
169 Status status(Id) const;
170
171 using Notifier = std::function<void (Id, Status)>;
181 Id addNotifier(Notifier);
183 void removeNotifier(Id);
185 void clearNotifiers();
186
207 Id writeGrid(GridBase::ConstPtr grid, const Archive& archive,
208 const MetaMap& fileMetadata = MetaMap());
209
235 template<typename GridPtrContainer>
236 Id write(const GridPtrContainer& grids, const Archive& archive,
237 const MetaMap& fileMetadata = MetaMap());
238
239 private:
240 // Disallow copying of instances of this class.
241 Queue(const Queue&);
242 Queue& operator=(const Queue&);
243
244 Id writeGridVec(const GridCPtrVec&, const Archive&, const MetaMap&);
245
246 struct Impl;
247 std::unique_ptr<Impl> mImpl;
248 }; // class Queue
249
250
251 template<typename GridPtrContainer>
252 inline Queue::Id
253 Queue::write(const GridPtrContainer& container,
254 const Archive& archive, const MetaMap& metadata)
255 {
256 GridCPtrVec grids;
257 std::copy(container.begin(), container.end(), std::back_inserter(grids));
258 return this->writeGridVec(grids, archive, metadata);
259 }
260
261 // Specialization for vectors of const Grid pointers; no copying necessary
262 template<>
263 inline Queue::Id
264 Queue::write<GridCPtrVec>(const GridCPtrVec& grids,
265 const Archive& archive, const MetaMap& metadata)
266 {
267 return this->writeGridVec(grids, archive, metadata);
268 }
269
270 } // namespace io
271 } // namespace OPENVDB_VERSION_NAME
272 } // namespace openvdb
273
274 #endif // OPENVDB_IO_QUEUE_HAS_BEEN_INCLUDED
275
276 // Copyright (c) 2012-2018 DreamWorks Animation LLC
277 // All rights reserved. This software is distributed under the
278 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
openvdb::v5_1::Index32
uint32_t Index32
Definition: Types.h:59
OPENVDB_API
#define OPENVDB_API
Helper macros for defining library symbol visibility.
Definition: Platform.h:194
Types.h
openvdb::v5_1::io::Queue::UNKNOWN
Definition: Queue.h:140
openvdb::v5_1::io::Queue::Id
Index32 Id
ID number of a queued task or of a registered notification callback.
Definition: Queue.h:137
OPENVDB_VERSION_NAME
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:136
openvdb::v5_1::GridBase::ConstPtr
SharedPtr< const GridBase > ConstPtr
Definition: Grid.h:108
openvdb::v5_1::io::Queue
Queue for asynchronous output of grids to files or streams.
Definition: Queue.h:127
openvdb
Definition: Exceptions.h:40
openvdb::v5_1::io::Queue::Notifier
std::function< void(Id, Status)> Notifier
Definition: Queue.h:171
openvdb::v5_1::GridCPtrVec
std::vector< GridBase::ConstPtr > GridCPtrVec
Definition: Grid.h:442
openvdb::v5_1::io::Archive
Grid serializer/unserializer.
Definition: Archive.h:59
Grid.h
openvdb::v5_1::io::Queue::Status
Status
Status of a queued task.
Definition: Queue.h:140
OPENVDB_USE_VERSION_NAMESPACE
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:188
openvdb::v5_1::MetaMap
Container that maps names (strings) to values of arbitrary types.
Definition: MetaMap.h:46