34#include <NDEVR/BaseValues.h>
35#include <NDEVR/TimeSpan.h>
36#include <NDEVR/Buffer.h>
52 friend class ProgressInfo;
53 friend class CancelInfo;
54 friend class LogManager;
55 InfoPipe()
noexcept {};
56 virtual ~InfoPipe(){};
60 virtual void addMessages(
uint04 id,
const AlocatingAlignedBuffer<LogMessage, 32>& messages) = 0;
61 virtual void addStream(
LogStream*,
bool) {}
63 virtual bool cancelRequested()
const = 0;
64 virtual void requestCancel() = 0;
65 virtual void requestCancel(
uint04) = 0;
66 virtual fltp04 progressIdx(
uint04)
const {
return 1.0f; };
75 virtual void removeProgressSource(
uint04 idx) = 0;
76 virtual void setProgressIdx(
uint04 idx,
fltp04 percent) = 0;
87 virtual bool cancelRequestedIdx(
uint04 idx)
const = 0;
91 virtual void removeInputGuard(
uint04 idx) = 0;
93 virtual void clearInputIdx(
uint04) = 0;
95 static volatile uint04 s_idx_incrementor;
101 class LogPtr :
public InfoPipe
106 , m_idx(Constant<uint04>::Invalid)
108 LogPtr(InfoPipe* log)
110 , m_idx(Constant<uint04>::Invalid)
112 LogPtr(
const LogPtr& log)
116 explicit LogPtr(InfoPipe& log)
118 , m_idx(Constant<uint04>::Invalid)
122 return m_log !=
nullptr;
124 InfoPipe* pipe()
const
128 LogPtr& operator=(
const LogPtr& log)
133 bool operator==(
const LogPtr& log)
const
135 if (m_log == log.m_log && m_idx == log.m_idx)
139 bool operator!=(
const LogPtr& log)
const
141 if (m_log != log.m_log || m_idx != log.m_idx)
145 void addMessage(
const LogMessage& message)
const
148 return m_log->addMessage(m_idx, message);
153 return m_log->addMessage(m_idx, message, log_level);
158 m_log->addMessage(m_idx, message, log_level);
161 void addMessages(
const AlocatingAlignedBuffer<LogMessage, 32>& messages)
const
164 m_log->addMessages(m_idx, messages);
166 void addStream(
LogStream* stream,
bool add_all)
final override
168 if (m_log) m_log->addStream(stream, add_all);
170 void removeStream(
LogStream* stream)
final override
172 if (m_log) m_log->removeStream(stream);
174 void requestCancel()
final override
176 if (m_log) m_log->requestCancel();
178 void requestCancel(
uint04 idx)
final override
180 if (m_log) m_log->requestCancel(idx);
182 bool cancelRequested()
const override
185 return m_log->cancelRequested();
191 return m_log->progressIdx(idx);
197 m_log->addInput(s, idx);
199 void addInput(
const StringView& s)
final override
205 virtual void addMessage(
uint04 id,
const LogMessage& message)
final override
208 m_log->addMessage(
id, message);
213 m_log->addMessage(
id, message, log_level);
218 m_log->addMessage(
id, message, log_level);
220 virtual void addMessages(
uint04 id,
const AlocatingAlignedBuffer<LogMessage, 32>& messages)
final override
223 m_log->addMessages(
id, messages);
225 void setProgressIdx(
uint04 idx,
fltp04 percent)
final override
228 m_log->setProgressIdx(idx, percent);
233 return m_log->addProgressSource(
name, progress);
234 return Constant<uint04>::Invalid;
241 void removeProgressSource(
uint04 idx)
final override
244 m_log->removeProgressSource(idx);
249 return m_log->addCancelGuard(
name);
250 return Constant<uint04>::Invalid;
260 m_log->removeCancelGuard(idx);
262 bool cancelRequestedIdx(
uint04 idx)
const final override
265 return m_log->cancelRequestedIdx(idx);
269 uint04 addInputGuard(
const TranslatedString&
name)
final override
272 return m_log->addInputGuard(
name);
273 return Constant<uint04>::Invalid;
275 void addInputGuard(
const TranslatedString&
name,
uint04 idx)
final override
278 m_log->addInputGuard(
name, idx);
280 void removeInputGuard(
uint04 idx)
final override
283 m_log->removeInputGuard(idx);
285 virtual void getInputIdx(String& s,
uint04 idx,
bool clear)
final override
288 m_log->getInputIdx(s, idx, clear);
290 virtual void clearInputIdx(
uint04 idx)
final override
293 m_log->clearInputIdx(idx);
302 class ProgressInfo :
public LogPtr
312 pipe->addProgressSource(
name, percent);
322 m_idx = pipe.addProgressSource(
name, percent);
324 ProgressInfo(
const ProgressInfo& info) =
delete;
327 LogPtr::setProgressIdx(m_idx, 1.0f);
328 LogPtr::removeProgressSource(m_idx);
337 LogPtr::setProgressIdx(m_idx, 1.0f);
338 LogPtr::removeProgressSource(m_idx);
339 m_idx = Constant<uint04>::Invalid;
343 LogPtr::setProgressIdx(m_idx, 1.0f);
344 LogPtr::removeProgressSource(m_idx);
354 void setProgress(
fltp04 progress)
356 LogPtr::setProgressIdx(m_idx, progress);
358 template<
class t_type_a>
359 void setProgress(
const t_type_a& count,
const t_type_a& total)
361 if(LogPtr::isValid())
364 template<
class t_type_a>
365 void setProgressIfNeeded(
const t_type_a& count,
const t_type_a& total,
const t_type_a& epsilon)
368 if(LogPtr::isValid() && (m_last_progress_set > ucount || m_last_progress_set + epsilon > ucount))
372 template<
class t_type_a>
373 static t_type_a CalcAbsEpsilon(
const t_type_a& total,
fltp08 desired_epsilon = 0.01)
379 if (LogPtr::isValid())
380 LogPtr::setProgressIdx(m_idx,
cast<fltp04>(count / total));
382 void setToIndeterminateProgress()
384 LogPtr::setProgressIdx(m_idx, Constant<fltp04>::Invalid);
388 return LogPtr::progressIdx(m_idx);
391 uint08 m_last_progress_set = Constant<uint08>::Invalid;
396 class CancelInfo :
public LogPtr
406 m_idx = pipe->addCancelGuard(
name);
416 m_idx = pipe.addCancelGuard(
name);
418 CancelInfo(
const CancelInfo& info) =
delete;
444 bool cancelRequested()
const final override
447 return m_log->cancelRequestedIdx(m_idx);
A light-weight base class for Log that allows processes to update, without the need for additional in...
virtual uint04 addCancelGuard(const TranslatedString &name)=0
If added, signals to any LogStream that cancel is enabled.
virtual void removeCancelGuard(uint04 idx)=0
If removed, signals to any LogStream that cancel is disabled, assuming there are no more cancel gaurd...
virtual uint04 addProgressSource(const TranslatedString &name, fltp04 progress)=0
Adds a progress gaurd, which.
A class that allows for specific log information to be conveyed to a InfoPipe object including inform...
uint04 addCancelGuard(const TranslatedString &name) final override
If added, signals to any LogStream that cancel is enabled.
virtual uint04 addProgressSource(const TranslatedString &name, fltp04 progress) final override
Adds a progress gaurd, which.
void removeCancelGuard(uint04 idx) final override
If removed, signals to any LogStream that cancel is disabled, assuming there are no more cancel gaurd...
A listener that receives and processes log messages and progress updates from an InfoPipe.
The core String View class for the NDEVR API.
The core String class for the NDEVR API.
Stores a time span, or difference between two times, with an optional start time.
Any text displayed to the user should be defined as a TranslatedString which allows the program to lo...
The primary namespace for the NDEVR SDK.
float fltp04
Defines an alias representing a 4 byte floating-point number Bit layout is as follows: -Sign: 1 bit a...
uint64_t uint08
-Defines an alias representing an 8 byte, unsigned integer
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
double fltp08
Defines an alias representing an 8 byte floating-point number.
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
@ name
The display name of the object.
constexpr t_to cast(const Angle< t_from > &value)
Casts an Angle from one backing type to another.