VRS
A file format for sensor data.
Loading...
Searching...
No Matches
ProgressLogger.h
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#pragma once
18
19#include <string>
20
21#include <vrs/VrsExport.h>
22
23namespace vrs {
24
25using std::string;
26
33class VRS_API ProgressLogger {
34 public:
35 static constexpr double kDefaultUpdateDelay = 2;
40 explicit ProgressLogger(bool detailedProgress = false, double updateDelay = kDefaultUpdateDelay);
41 virtual ~ProgressLogger();
42
46 virtual void setStepCount(int stepCount);
49 virtual void setDetailedProgress(bool detailedProgress);
52 bool getDetailedProgress() const {
53 return detailedProgress_;
54 }
55
61 virtual bool logNewStep(const string& stepName, size_t progress = 0, size_t maxProgress = 100);
62
69 bool logProgress(const string& stepName, size_t progress = 0, size_t maxProgress = 100) {
70 return logProgress(stepName, progress, maxProgress, false);
71 }
74 bool logProgress(const string& stepName, int64_t progress, int64_t maxProgress) {
75 return logProgress(
76 stepName, static_cast<size_t>(progress), static_cast<size_t>(maxProgress), false);
77 }
78
83 virtual bool logStatus(const string& stepName, int status = 0);
84
90 virtual bool logDuration(const string& operationName, double duration, int precision = 1);
91
92 protected:
98 virtual bool
99 logProgress(const string& stepName, size_t progress, size_t maxProgress, bool newStep);
103 virtual void logMessage(const string& message);
107 virtual void logErrorMessage(const string& message);
111 virtual void updateStep(size_t progress = 0, size_t maxProgress = 100);
113 virtual void updateNextProgressTime();
118 virtual bool shouldKeepGoing();
119
120 protected:
121 bool detailedProgress_;
122 double updateDelay_;
123 int stepNumber_;
124 int stepCount_;
125 double nextProgressTime_;
126};
127
129class VRS_API SilentLogger : public ProgressLogger {
130 public:
131 ~SilentLogger() override;
132 bool logProgress(const string&, size_t = 0, size_t = 100, bool = false) override {
133 return true;
134 }
135 bool logStatus(const string&, int = 0) override {
136 return true;
137 }
138 bool logDuration(const string& /*operationName*/, double /*duration*/, int /*precision*/ = 1)
139 override {
140 return true;
141 }
142};
143
144} // namespace vrs
ProgressLogger class to be notified of some process' progress.
Definition ProgressLogger.h:33
bool logProgress(const string &stepName, size_t progress=0, size_t maxProgress=100)
Definition ProgressLogger.h:69
bool logProgress(const string &stepName, int64_t progress, int64_t maxProgress)
Definition ProgressLogger.h:74
bool getDetailedProgress() const
Definition ProgressLogger.h:52
Progress logger to ignore all progress notifications.
Definition ProgressLogger.h:129
bool logDuration(const string &, double, int=1) override
Definition ProgressLogger.h:138
bool logStatus(const string &, int=0) override
Definition ProgressLogger.h:135
bool logProgress(const string &, size_t=0, size_t=100, bool=false) override
Definition ProgressLogger.h:132
Definition Compressor.cpp:113