Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
progressbar.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2016 Quaternion Risk Management Ltd
3 All rights reserved.
4
5 This file is part of ORE, a free-software/open-source library
6 for transparent pricing and risk analysis - http://opensourcerisk.org
7
8 ORE is free software: you can redistribute it and/or modify it
9 under the terms of the Modified BSD License. You should have received a
10 copy of the license along with this program.
11 The license is also available online at <http://opensourcerisk.org>
12
13 This program is distributed on the basis that it will form a useful
14 contribution to risk analytics and model standardisation, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
17*/
18
19/*! \file ored/utilities/progressbar.hpp
20 \brief Classes for progress reporting
21 \ingroup utilities
22*/
23
24#pragma once
25
27
28#include <ql/shared_ptr.hpp>
29#include <boost/unordered_set.hpp>
30
31#include <string>
32#include <thread>
33#include <set>
34
35namespace ore {
36namespace data {
37
38//! Abstract Base class for a Progress Indicator
39/*! \ingroup utilities
40 */
42public:
44 virtual ~ProgressIndicator() {}
45 virtual void updateProgress(const unsigned long progress, const unsigned long total, const std::string& detail) = 0;
46 virtual void reset() = 0;
47};
48
49//! Base class for a Progress Reporter
50/*! \ingroup utilities
51 */
53public:
55
56 //! register a Progress Indicator
57 void registerProgressIndicator(const QuantLib::ext::shared_ptr<ProgressIndicator>& indicator);
58
59 //! unregister a Progress Indicator
60 void unregisterProgressIndicator(const QuantLib::ext::shared_ptr<ProgressIndicator>& indicator);
61
62 //! unregister all progress indicators
64
65 //! update progress
66 void updateProgress(const unsigned long progress, const unsigned long total, const std::string& detail = "");
67
68 //! reset
69 void resetProgress();
70
71 //! return progress indicators
72 const std::set<QuantLib::ext::shared_ptr<ProgressIndicator>>& progressIndicators() const { return indicators_; }
73
74private:
75 std::set<QuantLib::ext::shared_ptr<ProgressIndicator>> indicators_;
76};
77
78//! Simple Progress Bar
79/*! Simple Progress Bar that writes a message followed by a status
80 bar to std::cout, no other output should be written to std::cout
81 during the bar from this instance is displayed
82
83 \ingroup utilities
84*/
86public:
87 SimpleProgressBar(const std::string& message, const QuantLib::Size messageWidth = 40,
88 const QuantLib::Size barWidth = 40, const QuantLib::Size numberOfScreenUpdates = 100);
89
90 //! ProgressIndicator interface
91 void updateProgress(const unsigned long progress, const unsigned long total, const std::string& detail) override;
92 void reset() override;
93
94private:
95 std::string key_;
98};
99
100//! Progress Logger that writes the progress using the LOG macro
101/*! \ingroup utilities
102 */
104public:
105 ProgressLog(const std::string& message, const unsigned int numberOfMessages = 100,
106 const oreSeverity logLevel = oreSeverity::debug);
107
108 //! ProgressIndicator interface
109 void updateProgress(const unsigned long progress, const unsigned long total, const std::string& detail) override;
110 void reset() override;
111
112private:
113 std::string key_;
114 unsigned int numberOfMessages_;
116 unsigned int messageCounter_;
117};
118
119/*! Progress Bar just writes the given message and flushes */
121public:
122 NoProgressBar(const std::string& message, const unsigned int messageWidth = 40);
123
124 /*! ProgressIndicator interface */
125 void updateProgress(const unsigned long progress, const unsigned long total, const std::string& detail) override {}
126 void reset() override {}
127};
128
129/*! Progress Manager that consolidates updates from multiple threads */
131public:
132 explicit MultiThreadedProgressIndicator(const std::set<QuantLib::ext::shared_ptr<ProgressIndicator>>& indicators);
133 void updateProgress(const unsigned long progress, const unsigned long total, const std::string& detail) override;
134 void reset() override;
135
136private:
137 mutable boost::shared_mutex mutex_;
138 std::set<QuantLib::ext::shared_ptr<ProgressIndicator>> indicators_;
139 std::map<std::thread::id, std::tuple<unsigned long, unsigned long, std::string>> threadData_;
140};
141
142} // namespace data
143} // namespace ore
void updateProgress(const unsigned long progress, const unsigned long total, const std::string &detail) override
std::set< QuantLib::ext::shared_ptr< ProgressIndicator > > indicators_
std::map< std::thread::id, std::tuple< unsigned long, unsigned long, std::string > > threadData_
void updateProgress(const unsigned long progress, const unsigned long total, const std::string &detail) override
Abstract Base class for a Progress Indicator.
Definition: progressbar.hpp:41
virtual void updateProgress(const unsigned long progress, const unsigned long total, const std::string &detail)=0
Progress Logger that writes the progress using the LOG macro.
unsigned int numberOfMessages_
void updateProgress(const unsigned long progress, const unsigned long total, const std::string &detail) override
ProgressIndicator interface.
unsigned int messageCounter_
void reset() override
Base class for a Progress Reporter.
Definition: progressbar.hpp:52
const std::set< QuantLib::ext::shared_ptr< ProgressIndicator > > & progressIndicators() const
return progress indicators
Definition: progressbar.hpp:72
void unregisterProgressIndicator(const QuantLib::ext::shared_ptr< ProgressIndicator > &indicator)
unregister a Progress Indicator
Definition: progressbar.cpp:31
void updateProgress(const unsigned long progress, const unsigned long total, const std::string &detail="")
update progress
Definition: progressbar.cpp:37
std::set< QuantLib::ext::shared_ptr< ProgressIndicator > > indicators_
Definition: progressbar.hpp:75
void registerProgressIndicator(const QuantLib::ext::shared_ptr< ProgressIndicator > &indicator)
register a Progress Indicator
Definition: progressbar.cpp:27
void unregisterAllProgressIndicators()
unregister all progress indicators
Definition: progressbar.cpp:35
Simple Progress Bar.
Definition: progressbar.hpp:85
void updateProgress(const unsigned long progress, const unsigned long total, const std::string &detail) override
ProgressIndicator interface.
Definition: progressbar.cpp:55
unsigned int numberOfScreenUpdates_
Definition: progressbar.hpp:96
Classes and functions for log message handling.
oreSeverity
Definition: log.hpp:70
@ data
Definition: log.hpp:77
Serializable Credit Default Swap.
Definition: namespaces.docs:23