HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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
virtual NullInterrupter & interrupter() final
Convenience method to return a reference to the base class from a derived class.
void
Definition: png.h:1083
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:239
virtual void end()
Signal the end of an interruptible operation.
NullInterrupter()=default
Default constructor.
GLuint const GLchar * name
Definition: glcorearb.h:786
Library and file format version numbers.
virtual void start(const char *name=nullptr)
bool wasInterrupted(T *i, int percent=-1)
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:119