OpenVDB: Queue.h Source File

OpenVDB 3.1.0

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

Queue.h
Go to the documentation of this file.
1 //
3 // Copyright (c) 2012-2015 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 <boost/function.hpp>
40 #include <boost/shared_ptr.hpp>
41 #include <algorithm> // for std::copy
42 #include <iterator> // for std::back_inserter
43
44
45 namespace openvdb {
46 OPENVDB_USE_VERSION_NAMESPACE
47 namespace OPENVDB_VERSION_NAME {
48 namespace io {
49
50 class Archive;
51
126 class OPENVDB_API Queue
127 {
128 public:
130 static const Index32 DEFAULT_CAPACITY = 100;
133 static const Index32 DEFAULT_TIMEOUT = 120; // seconds
134
136 typedef Index32 Id;
137
139 enum Status { UNKNOWN, PENDING, SUCCEEDED, FAILED };
140
141
143 explicit Queue(Index32 capacity = DEFAULT_CAPACITY);
145 ~Queue();
146
148 bool empty() const;
150 Index32 size() const;
151
155 Index32 capacity() const;
157 void setCapacity(Index32);
158
160 Index32 timeout() const;
162 void setTimeout(Index32 seconds = DEFAULT_TIMEOUT);
163
168 Status status(Id) const;
169
170 typedef boost::function<void (Id, Status)> Notifier;
180 Id addNotifier(Notifier);
182 void removeNotifier(Id);
184 void clearNotifiers();
185
206 Id writeGrid(GridBase::ConstPtr grid, const Archive& archive,
207 const MetaMap& fileMetadata = MetaMap());
208
234 template<typename GridPtrContainer>
235 Id write(const GridPtrContainer& grids, const Archive& archive,
236 const MetaMap& fileMetadata = MetaMap());
237
238 private:
239 // Disallow copying of instances of this class.
240 Queue(const Queue&);
241 Queue& operator=(const Queue&);
242
243 Id writeGridVec(const GridCPtrVec&, const Archive&, const MetaMap&);
244
245 struct Impl;
246 boost::shared_ptr<Impl> mImpl;
247 }; // class Queue
248
249
250 template<typename GridPtrContainer>
251 inline Queue::Id
252 Queue::write(const GridPtrContainer& container,
253 const Archive& archive, const MetaMap& metadata)
254 {
255 GridCPtrVec grids;
256 std::copy(container.begin(), container.end(), std::back_inserter(grids));
257 return this->writeGridVec(grids, archive, metadata);
258 }
259
260 // Specialization for vectors of const Grid pointers; no copying necessary
261 template<>
262 inline Queue::Id
263 Queue::write<GridCPtrVec>(const GridCPtrVec& grids,
264 const Archive& archive, const MetaMap& metadata)
265 {
266 return this->writeGridVec(grids, archive, metadata);
267 }
268
269 } // namespace io
270 } // namespace OPENVDB_VERSION_NAME
271 } // namespace openvdb
272
273 #endif // OPENVDB_IO_QUEUE_HAS_BEEN_INCLUDED
274
275 // Copyright (c) 2012-2015 DreamWorks Animation LLC
276 // All rights reserved. This software is distributed under the
277 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
OPENVDB_API
#define OPENVDB_API
Helper macros for defining library symbol visibility.
Definition: Platform.h:195
Types.h
openvdb::v3_1_0::io::Queue::Id
Index32 Id
ID number of a queued task or of a registered notification callback.
Definition: Queue.h:136
openvdb::v3_1_0::MetaMap
Container that maps names (strings) to values of arbitrary types.
Definition: MetaMap.h:46
openvdb::v3_1_0::Index32
uint32_t Index32
Definition: Types.h:56
openvdb::v3_1_0::io::Queue
Queue for asynchronous output of grids to files or streams.
Definition: Queue.h:126
OPENVDB_VERSION_NAME
#define OPENVDB_VERSION_NAME
Definition: version.h:43
openvdb
Definition: Exceptions.h:39
openvdb::v3_1_0::GridBase::ConstPtr
boost::shared_ptr< const GridBase > ConstPtr
Definition: Grid.h:107
openvdb::v3_1_0::io::Queue::Status
Status
Status of a queued task.
Definition: Queue.h:139
openvdb::v3_1_0::io::Queue::UNKNOWN
Definition: Queue.h:139
openvdb::v3_1_0::GridCPtrVec
std::vector< GridBase::ConstPtr > GridCPtrVec
Definition: Grid.h:425
Grid.h
openvdb::v3_1_0::io::Queue::Notifier
boost::function< void(Id, Status)> Notifier
Definition: Queue.h:170
OPENVDB_USE_VERSION_NAMESPACE
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:71
openvdb::v3_1_0::io::Archive
Grid serializer/unserializer.
Definition: Archive.h:59