OpenVDB: Queue.h Source File

OpenVDB 7.1.0

Queue.h
Go to the documentation of this file.
1 // Copyright Contributors to the OpenVDB Project
2 // SPDX-License-Identifier: MPL-2.0
3
6
7 #ifndef OPENVDB_IO_QUEUE_HAS_BEEN_INCLUDED
8 #define OPENVDB_IO_QUEUE_HAS_BEEN_INCLUDED
9
10 #include <openvdb/Types.h>
11 #include <openvdb/Grid.h>
12 #include <algorithm> // for std::copy
13 #include <functional>
14 #include <iterator> // for std::back_inserter
15 #include <memory>
16
17
18 namespace openvdb {
19 OPENVDB_USE_VERSION_NAMESPACE
20 namespace OPENVDB_VERSION_NAME {
21 namespace io {
22
23 class Archive;
24
100 class OPENVDB_API Queue
101 {
102 public:
104 static const Index32 DEFAULT_CAPACITY = 100;
107 static const Index32 DEFAULT_TIMEOUT = 120; // seconds
108
110 using Id = Index32;
111
113 enum Status { UNKNOWN, PENDING, SUCCEEDED, FAILED };
114
115
117 explicit Queue(Index32 capacity = DEFAULT_CAPACITY);
119 ~Queue();
120
122 bool empty() const;
124 Index32 size() const;
125
129 Index32 capacity() const;
131 void setCapacity(Index32);
132
134 Index32 timeout() const;
136 void setTimeout(Index32 seconds = DEFAULT_TIMEOUT);
137
142 Status status(Id) const;
143
144 using Notifier = std::function<void (Id, Status)>;
154 Id addNotifier(Notifier);
156 void removeNotifier(Id);
158 void clearNotifiers();
159
180 Id writeGrid(GridBase::ConstPtr grid, const Archive& archive,
181 const MetaMap& fileMetadata = MetaMap());
182
208 template<typename GridPtrContainer>
209 Id write(const GridPtrContainer& grids, const Archive& archive,
210 const MetaMap& fileMetadata = MetaMap());
211
212 private:
213 // Disallow copying of instances of this class.
214 Queue(const Queue&);
215 Queue& operator=(const Queue&);
216
217 Id writeGridVec(const GridCPtrVec&, const Archive&, const MetaMap&);
218
219 struct Impl;
220 std::unique_ptr<Impl> mImpl;
221 }; // class Queue
222
223
224 template<typename GridPtrContainer>
225 inline Queue::Id
226 Queue::write(const GridPtrContainer& container,
227 const Archive& archive, const MetaMap& metadata)
228 {
229 GridCPtrVec grids;
230 std::copy(container.begin(), container.end(), std::back_inserter(grids));
231 return this->writeGridVec(grids, archive, metadata);
232 }
233
234 // Specialization for vectors of const Grid pointers; no copying necessary
235 template<>
236 inline Queue::Id
237 Queue::write<GridCPtrVec>(const GridCPtrVec& grids,
238 const Archive& archive, const MetaMap& metadata)
239 {
240 return this->writeGridVec(grids, archive, metadata);
241 }
242
243 } // namespace io
244 } // namespace OPENVDB_VERSION_NAME
245 } // namespace openvdb
246
247 #endif // OPENVDB_IO_QUEUE_HAS_BEEN_INCLUDED
openvdb::v7_1::MetaMap
Container that maps names (strings) to values of arbitrary types.
Definition: MetaMap.h:20
openvdb::v7_1::io::Queue
Queue for asynchronous output of grids to files or streams.
Definition: Queue.h:101
openvdb::v7_1::io::Queue::clearNotifiers
void clearNotifiers()
Deregister all notifiers.
openvdb::v7_1::io::Queue::setTimeout
void setTimeout(Index32 seconds=DEFAULT_TIMEOUT)
Set the maximum number of seconds to wait to queue a task when the queue is full.
Types.h
openvdb::v7_1::io::Queue::addNotifier
Id addNotifier(Notifier)
Register a function that will be called with a task's ID and status when that task completes,...
openvdb::v7_1::io::Queue::Id
Index32 Id
ID number of a queued task or of a registered notification callback.
Definition: Queue.h:110
openvdb::v7_1::io::Queue::removeNotifier
void removeNotifier(Id)
Deregister the notifier with the given ID.
openvdb::v7_1::io::Queue::Status
Status
Status of a queued task.
Definition: Queue.h:113
openvdb::v7_1::io::Queue::writeGrid
Id writeGrid(GridBase::ConstPtr grid, const Archive &archive, const MetaMap &fileMetadata=MetaMap())
Queue a single grid for output to a file or stream.
Grid.h
OPENVDB_API
#define OPENVDB_API
Helper macros for defining library symbol visibility.
Definition: Platform.h:230
openvdb::v7_1::Index32
uint32_t Index32
Definition: Types.h:29
openvdb::v7_1::io::Queue::size
Index32 size() const
Return the number of tasks currently in the queue.
openvdb::v7_1::io::Archive
Grid serializer/unserializer.
Definition: Archive.h:33
openvdb::v7_1::io::Queue::UNKNOWN
@ UNKNOWN
Definition: Queue.h:113
openvdb::v7_1::GridBase::ConstPtr
SharedPtr< const GridBase > ConstPtr
Definition: Grid.h:81
OPENVDB_USE_VERSION_NAMESPACE
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:146
openvdb::v7_1::io::Queue::Notifier
std::function< void(Id, Status)> Notifier
Definition: Queue.h:144
openvdb::v7_1::io::Queue::Queue
Queue(Index32 capacity=DEFAULT_CAPACITY)
Construct a queue with the given capacity.
openvdb::v7_1::io::Queue::timeout
Index32 timeout() const
Return the maximum number of seconds to wait to queue a task when the queue is full.
OPENVDB_VERSION_NAME
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:94
openvdb::v7_1::io::Queue::empty
bool empty() const
Return true if the queue is empty.
openvdb::v7_1::io::Queue::status
Status status(Id) const
Return the status of the task with the given ID.
openvdb::v7_1::GridCPtrVec
std::vector< GridBase::ConstPtr > GridCPtrVec
Definition: Grid.h:514
openvdb
Definition: Exceptions.h:13
openvdb::v7_1::io::Queue::capacity
Index32 capacity() const
Return the maximum number of tasks allowed in the queue.
openvdb::v7_1::io::Queue::setCapacity
void setCapacity(Index32)
Set the maximum number of tasks allowed in the queue.
openvdb::v7_1::io::Queue::~Queue
~Queue()
Block until all queued tasks complete (successfully or unsuccessfully).