Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
MultiThreadedProgressIndicator Class Reference

#include <ored/utilities/progressbar.hpp>

+ Inheritance diagram for MultiThreadedProgressIndicator:
+ Collaboration diagram for MultiThreadedProgressIndicator:

Public Member Functions

 MultiThreadedProgressIndicator (const std::set< QuantLib::ext::shared_ptr< ProgressIndicator > > &indicators)
 
void updateProgress (const unsigned long progress, const unsigned long total, const std::string &detail) override
 
void reset () override
 
- Public Member Functions inherited from ProgressIndicator
 ProgressIndicator ()
 
virtual ~ProgressIndicator ()
 
virtual void updateProgress (const unsigned long progress, const unsigned long total, const std::string &detail)=0
 
virtual void reset ()=0
 

Private Attributes

boost::shared_mutex mutex_
 
std::set< QuantLib::ext::shared_ptr< ProgressIndicator > > indicators_
 
std::map< std::thread::id, std::tuple< unsigned long, unsigned long, std::string > > threadData_
 

Detailed Description

Progress Manager that consolidates updates from multiple threads

Definition at line 130 of file progressbar.hpp.

Constructor & Destructor Documentation

◆ MultiThreadedProgressIndicator()

MultiThreadedProgressIndicator ( const std::set< QuantLib::ext::shared_ptr< ProgressIndicator > > &  indicators)
explicit

Definition at line 114 of file progressbar.cpp.

116 : indicators_(indicators) {}
std::set< QuantLib::ext::shared_ptr< ProgressIndicator > > indicators_

Member Function Documentation

◆ updateProgress()

void updateProgress ( const unsigned long  progress,
const unsigned long  total,
const std::string &  detail 
)
overridevirtual

Implements ProgressIndicator.

Definition at line 118 of file progressbar.cpp.

118 {
119 boost::unique_lock<boost::shared_mutex> lock(mutex_);
120 threadData_[std::this_thread::get_id()] = std::make_tuple(progress, total, detail);
121 unsigned long progressTmp = 0;
122 unsigned long totalTmp = 0;
123 std::ostringstream detailTmp;
124 for (auto const& d : threadData_) {
125 progressTmp += std::get<0>(d.second);
126 totalTmp += std::get<1>(d.second);
127
128 if (detailTmp.tellp() != 0)
129 detailTmp << "|";
130 detailTmp << std::get<2>(d.second);
131 }
132 for (auto& i : indicators_)
133 i->updateProgress(progressTmp, totalTmp, detailTmp.str());
134}
std::map< std::thread::id, std::tuple< unsigned long, unsigned long, std::string > > threadData_

◆ reset()

void reset ( )
overridevirtual

Implements ProgressIndicator.

Definition at line 136 of file progressbar.cpp.

136 {
137 boost::unique_lock<boost::shared_mutex> lock(mutex_);
138 for (auto& i : indicators_)
139 i->reset();
140 threadData_.clear();
141}

Member Data Documentation

◆ mutex_

boost::shared_mutex mutex_
mutableprivate

Definition at line 137 of file progressbar.hpp.

◆ indicators_

std::set<QuantLib::ext::shared_ptr<ProgressIndicator> > indicators_
private

Definition at line 138 of file progressbar.hpp.

◆ threadData_

std::map<std::thread::id, std::tuple<unsigned long, unsigned long, std::string> > threadData_
private

Definition at line 139 of file progressbar.hpp.