Skip to content

Instantly share code, notes, and snippets.

@runceel
Created September 11, 2012 13:52
Show Gist options
  • Save runceel/3698649 to your computer and use it in GitHub Desktop.
Save runceel/3698649 to your computer and use it in GitHub Desktop.
BackgroundWorker interface sample
template<typename TProgress>
class BackgroundWorker
{
private:
TProgress progress_;
bool reportChanged_;
public:
BackgroundWorker(bool reportChanged = false) :
progress_(TProgress()),
reportChanged_(reportChanged)
{
}
BackgroundWorker(const TProgress &progress, bool reportChanged = false) :
progress_(progress),
reportChanged_(reportChanged)
{
}
void Run()
{
for (int i = 0; i < 10; i++)
{
int report = progress_.Execute();
if (reportChanged_)
{
this->Report(report);
}
}
}
private:
void Report(int report)
{
progress_.Report(report);
}
};
struct Progress
{
int count;
int Execute()
{
std::cout << "exec!!" << std::endl;
return count++;
}
void Report(int report)
{
std::cout << report << std::endl;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment