OpenVDB 7.0.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
Types.h
openvdb::v7_0::io::Queue::Id
Index32 Id
ID number of a queued task or of a registered notification callback.
Definition: Queue.h:110
openvdb::v7_0::io::Archive
Grid serializer/unserializer.
Definition: Archive.h:32
openvdb::v7_0::GridCPtrVec
std::vector< GridBase::ConstPtr > GridCPtrVec
Definition: Grid.h:514
openvdb::v7_0::io::Queue
Queue for asynchronous output of grids to files or streams.
Definition: Queue.h:100
Grid.h
openvdb::v7_0::GridBase::ConstPtr
SharedPtr< const GridBase > ConstPtr
Definition: Grid.h:81
OPENVDB_API
#define OPENVDB_API
Helper macros for defining library symbol visibility.
Definition: Platform.h:230
openvdb::v7_0::MetaMap
Container that maps names (strings) to values of arbitrary types.
Definition: MetaMap.h:19
openvdb::v7_0::io::Queue::Status
Status
Status of a queued task.
Definition: Queue.h:113
openvdb::v7_0::io::Queue::Notifier
std::function< void(Id, Status)> Notifier
Definition: Queue.h:144
openvdb::v7_0::io::Queue::UNKNOWN
Definition: Queue.h:113
OPENVDB_USE_VERSION_NAMESPACE
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:154
OPENVDB_VERSION_NAME
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:102
openvdb::v7_0::Index32
uint32_t Index32
Definition: Types.h:29
openvdb
Definition: Exceptions.h:13