OpenVDB  11.0.0
NullInterrupter.h
Go to the documentation of this file.
1 // Copyright Contributors to the OpenVDB Project
2 // SPDX-License-Identifier: MPL-2.0
3 //
4 /// @file NullInterrupter.h
5 
6 #ifndef OPENVDB_UTIL_NULL_INTERRUPTER_HAS_BEEN_INCLUDED
7 #define OPENVDB_UTIL_NULL_INTERRUPTER_HAS_BEEN_INCLUDED
8 
9 #include <openvdb/version.h>
10 
11 namespace openvdb {
13 namespace OPENVDB_VERSION_NAME {
14 namespace util {
15 
16 /// @brief Base class for interrupters
17 ///
18 /// The host application calls start() at the beginning of an interruptible operation,
19 /// end() at the end of the operation, and wasInterrupted() periodically during the
20 /// operation.
21 /// If any call to wasInterrupted() returns @c true, the operation will be aborted.
22 /// @note This interrupter was not virtual in a previous implementation, so it could
23 /// be compiled out, however it remains important to not call wasInterrupter() too
24 /// frequently so as to balance performance and the ability to interrupt an operation.
26 {
27  /// Default constructor
28  NullInterrupter() = default;
29  virtual ~NullInterrupter() = default;
30  /// Signal the start of an interruptible operation.
31  /// @param name an optional descriptive name for the operation
32  virtual void start(const char* name = nullptr) { (void)name; }
33  /// Signal the end of an interruptible operation.
34  virtual void end() { }
35  /// Check if an interruptible operation should be aborted.
36  /// @param percent an optional (when >= 0) percentage indicating
37  /// the fraction of the operation that has been completed
38  /// @note this method is assumed to be thread-safe.
39  virtual bool wasInterrupted(int percent = -1) { (void)percent; return false; }
40  /// Convenience method to return a reference to the base class from a derived class.
41  virtual NullInterrupter& interrupter() final {
42  return static_cast<NullInterrupter&>(*this);
43  }
44 }; // struct NullInterrupter
45 
46 /// This method is primarily for backwards-compatibility as the ability to compile out
47 /// the call to wasInterrupted() is no longer supported.
48 template <typename T>
49 inline bool wasInterrupted(T* i, int percent = -1) { return i && i->wasInterrupted(percent); }
50 
51 
52 } // namespace util
53 } // namespace OPENVDB_VERSION_NAME
54 } // namespace openvdb
55 
56 #endif // OPENVDB_UTIL_NULL_INTERRUPTER_HAS_BEEN_INCLUDED
bool wasInterrupted(T *i, int percent=-1)
Definition: NullInterrupter.h:49
Base class for interrupters.
Definition: NullInterrupter.h:25
virtual void start(const char *name=nullptr)
Definition: NullInterrupter.h:32
virtual void end()
Signal the end of an interruptible operation.
Definition: NullInterrupter.h:34
Definition: Exceptions.h:13
virtual bool wasInterrupted(int percent=-1)
Definition: NullInterrupter.h:39
virtual NullInterrupter & interrupter() final
Convenience method to return a reference to the base class from a derived class.
Definition: NullInterrupter.h:41
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h.in:121
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h.in:212