Lagrange
ProgressCallback.h
1/*
2 * Copyright 2020 Adobe. All rights reserved.
3 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License. You may obtain a copy
5 * of the License at http://www.apache.org/licenses/LICENSE-2.0
6 *
7 * Unless required by applicable law or agreed to in writing, software distributed under
8 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9 * OF ANY KIND, either express or implied. See the License for the specific language
10 * governing permissions and limitations under the License.
11 */
12#pragma once
13
14#include <lagrange/api.h>
15
16#include <tbb/spin_mutex.h>
17#include <atomic>
18#include <functional>
19#include <string>
20
21namespace lagrange {
22
26class LA_CORE_API ProgressCallback
27{
28public:
38 std::function<void(const std::string &, float)> func = nullptr,
39 std::string name = "",
40 size_t num_iterations = 1);
41
48 void set_callback(std::function<void(const std::string &, float)> func);
49
57 void set_section(std::string name, size_t num_iterations = 1);
58
64 const std::string & get_section() const { return m_section_name; }
65
72 void set_num_iterations(size_t num_iterations);
73
78 void advance(size_t increment);
79
84 void update();
85
91 void update(float progress);
92
99 void set_verbose(bool verbose) { m_verbose = verbose; }
100
101private:
103 std::function<void(const std::string &, float)> m_callback;
104
106 std::string m_section_name;
107
109 size_t m_num_iterations = 1;
110
112 std::atomic_size_t m_current_iteration = {0};
113
115 float m_last_progress = 0.f;
116
118 tbb::spin_mutex m_mutex;
119
121 bool m_verbose = false;
122};
123
124} // namespace lagrange
A simple thread-safe progress callback.
Definition: ProgressCallback.h:27
const std::string & get_section() const
Retrieves current section name.
Definition: ProgressCallback.h:64
void set_verbose(bool verbose)
Sets the verbosity.
Definition: ProgressCallback.h:99
Main namespace for Lagrange.
Definition: AABBIGL.h:30