OpenWalnut  1.5.0dev
Public Types | Public Member Functions | Protected Attributes | Friends | List of all members
WProgressCombiner Class Reference

Base class for all kinds of progress combinations. More...

#include <WProgressCombiner.h>

+ Inheritance diagram for WProgressCombiner:
+ Collaboration diagram for WProgressCombiner:

Public Types

typedef std::shared_ptr< WProgressCombinerSPtr
 Abbreviate shared_ptr for this class. More...
 
typedef std::shared_ptr< const WProgressCombinerConstSPtr
 Abbreviate shared_ptr for this class. More...
 
- Public Types inherited from WProgress
typedef std::shared_ptr< WProgressSPtr
 Shared pointer on a WProgress. More...
 
typedef std::shared_ptr< const WProgressConstSPtr
 Const Shared pointer on a WProgress. More...
 

Public Member Functions

 WProgressCombiner (std::string name="")
 Default constructor. More...
 
virtual ~WProgressCombiner ()
 Destructor. More...
 
virtual void finish ()
 Stops the progress. More...
 
virtual WProgressCombineroperator++ ()
 Simple increment operator to signal a forward stepping. More...
 
virtual float getProgress ()
 Returns the overall progress of this progress instance, including the child progress'. More...
 
virtual void addSubProgress (std::shared_ptr< WProgress > progress)
 Adds a new progress to this combiner. More...
 
virtual void removeSubProgress (std::shared_ptr< WProgress > progress)
 Removes the specified sub progress from this combiner. More...
 
virtual void update ()
 Function updating the internal state. More...
 
std::string getCombinedNames (bool excludeFinished=false) const
 Generates a string combined out of every child progress name. More...
 
- Public Member Functions inherited from WProgress
 WProgress (std::string name, size_t count=0)
 Creates a new progress instance as child of the specified progress. More...
 
virtual ~WProgress ()
 Destructor. More...
 
virtual WProgressoperator+ (size_t steps)
 Increments the operator by the given number of steps to signal forward progress. More...
 
virtual bool isPending ()
 Returns true when the operation is pending. More...
 
std::string getName () const
 Returns the name of the progress. More...
 
virtual bool isDetermined ()
 Returns true whenever the progress has a known end. More...
 
virtual void increment (size_t steps)
 Increment the progress counter by the given amount. More...
 

Protected Attributes

std::string m_name
 The name of the combiner. More...
 
float m_progress
 The current conglomerated progress. More...
 
std::set< std::shared_ptr< WProgress > > m_children
 Set of all child progress. More...
 
std::shared_mutex m_updateLock
 Lock for the above child set and the internal state update. More...
 
- Protected Attributes inherited from WProgress
std::string m_name
 Progress name. More...
 
size_t m_max
 The maximum count (which marks the 100%). More...
 
size_t m_count
 The current counter. More...
 
bool m_pending
 Flag denoting whether the progress is running or not. More...
 
bool m_determined
 True if the progress has a known end point. More...
 

Friends

class WProgressCombinerTest
 Access for test class. More...
 

Detailed Description

Base class for all kinds of progress combinations.

You might want to derive from this class to implement some special progress combination.

Definition at line 41 of file WProgressCombiner.h.

Member Typedef Documentation

◆ ConstSPtr

typedef std::shared_ptr< const WProgressCombiner > WProgressCombiner::ConstSPtr

Abbreviate shared_ptr for this class.

Definition at line 53 of file WProgressCombiner.h.

◆ SPtr

typedef std::shared_ptr< WProgressCombiner > WProgressCombiner::SPtr

Abbreviate shared_ptr for this class.

Definition at line 48 of file WProgressCombiner.h.

Constructor & Destructor Documentation

◆ WProgressCombiner()

WProgressCombiner::WProgressCombiner ( std::string  name = "")
explicit

Default constructor.

It creates a empty combiner.

Parameters
namethe (optional) name of this progress.

Definition at line 34 of file WProgressCombiner.cpp.

References WProgress::m_pending.

◆ ~WProgressCombiner()

WProgressCombiner::~WProgressCombiner ( )
virtual

Destructor.

Definition at line 43 of file WProgressCombiner.cpp.

Member Function Documentation

◆ addSubProgress()

void WProgressCombiner::addSubProgress ( std::shared_ptr< WProgress progress)
virtual

Adds a new progress to this combiner.

It does not check whether the specified progress already is associated with another combiner, which allows some kind of "shared" progress. The progress stays in the progress list until finish() is called, which actually cleans up and resets a combiner.

Parameters
progressthe progress to add as a child.
Note
it is possible to add ProgressCombiner instances as well.

Definition at line 114 of file WProgressCombiner.cpp.

References m_children, and m_updateLock.

Referenced by WProgressCombinerTest::testWithChilds().

+ Here is the caller graph for this function:

◆ finish()

void WProgressCombiner::finish ( )
virtual

Stops the progress.

Progress combiner propagate this request to their children. Please not that this operation is expansive. It locks the updateLock and removes all child progress.

Reimplemented from WProgress.

Definition at line 130 of file WProgressCombiner.cpp.

References WProgress::finish(), m_children, m_progress, and m_updateLock.

Referenced by WProgressCombinerTest::testInternalStateIgnoresIncrementAndFinish(), and WProgressCombinerTest::testWithChilds().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getCombinedNames()

std::string WProgressCombiner::getCombinedNames ( bool  excludeFinished = false) const

Generates a string combined out of every child progress name.

Parameters
excludeFinishedif true, the combined name list only contains unfinished progress'
Returns
One describing string for all child progress names.

Definition at line 85 of file WProgressCombiner.cpp.

References m_children, and m_updateLock.

◆ getProgress()

float WProgressCombiner::getProgress ( )
virtual

Returns the overall progress of this progress instance, including the child progress'.

Returns
the progress.

Reimplemented from WProgress.

Definition at line 159 of file WProgressCombiner.cpp.

References m_progress.

Referenced by WProgressCombinerTest::testInternalStateIgnoresIncrementAndFinish(), and WProgressCombinerTest::testWithChilds().

+ Here is the caller graph for this function:

◆ operator++()

WProgressCombiner & WProgressCombiner::operator++ ( )
virtual

Simple increment operator to signal a forward stepping.

Note
this actually is for ++p. p++ is not useful since it returns a copy of WProgress with the old count.
Returns
the incremented WProgress instance.

Reimplemented from WProgress.

Definition at line 153 of file WProgressCombiner.cpp.

◆ removeSubProgress()

void WProgressCombiner::removeSubProgress ( std::shared_ptr< WProgress progress)
virtual

Removes the specified sub progress from this combiner.

Parameters
progressthe progress to remove.

Definition at line 122 of file WProgressCombiner.cpp.

References m_children, and m_updateLock.

◆ update()

void WProgressCombiner::update ( )
virtual

Function updating the internal state.

This needs to be called before any get function to ensure the getter return the right values.

Note
this method is expansive. It uses a lock to avoid concurrent write and iterates over this combiners children.

Reimplemented from WProgress.

Definition at line 48 of file WProgressCombiner.cpp.

References m_children, WProgress::m_determined, WProgress::m_pending, m_progress, and m_updateLock.

Referenced by WProgressCombinerTest::testInternalStateIgnoresIncrementAndFinish(), and WProgressCombinerTest::testWithChilds().

+ Here is the caller graph for this function:

Friends And Related Function Documentation

◆ WProgressCombinerTest

friend class WProgressCombinerTest
friend

Access for test class.

Definition at line 43 of file WProgressCombiner.h.

Member Data Documentation

◆ m_children

std::set< std::shared_ptr< WProgress > > WProgressCombiner::m_children
protected

Set of all child progress.

Definition at line 137 of file WProgressCombiner.h.

Referenced by addSubProgress(), finish(), getCombinedNames(), removeSubProgress(), WProgressCombinerTest::testWithChilds(), and update().

◆ m_name

std::string WProgressCombiner::m_name
protected

The name of the combiner.

Definition at line 127 of file WProgressCombiner.h.

◆ m_progress

float WProgressCombiner::m_progress
protected

The current conglomerated progress.

Set by update().

Definition at line 132 of file WProgressCombiner.h.

Referenced by finish(), getProgress(), and update().

◆ m_updateLock

std::shared_mutex WProgressCombiner::m_updateLock
mutableprotected

Lock for the above child set and the internal state update.

Definition at line 142 of file WProgressCombiner.h.

Referenced by addSubProgress(), finish(), getCombinedNames(), removeSubProgress(), and update().


The documentation for this class was generated from the following files: