Add missing headers and change StdioProgressSink() to use std::cout and friends.

Originally committed to SVN as r5314.
This commit is contained in:
Amar Takhar 2011-02-07 00:46:49 +00:00
parent e27c3e15b8
commit 7b06c334aa
2 changed files with 14 additions and 12 deletions

View file

@ -19,7 +19,12 @@
/// @ingroup libaegisub /// @ingroup libaegisub
#ifndef LAG_PRE #ifndef LAG_PRE
#include <assert.h>
#include <string> #include <string>
#include <iomanip>
#include <iostream>
#include <cmath>
#endif #endif
#include "libaegisub/progress.h" #include "libaegisub/progress.h"
@ -42,14 +47,13 @@ ProgressSink * NullProgressSinkFactory::create_progress_sink(const std::string &
class StdioProgressSink : public ProgressSink { class StdioProgressSink : public ProgressSink {
private: private:
FILE *file;
std::string operation; std::string operation;
float progress; float progress;
void print(); void print();
public: public:
StdioProgressSink(FILE *file, const std::string &title); StdioProgressSink(const std::string &title);
virtual ~StdioProgressSink(); virtual ~StdioProgressSink();
virtual void set_progress(int steps, int max); virtual void set_progress(int steps, int max);
virtual void set_operation(const std::string &operation); virtual void set_operation(const std::string &operation);
@ -57,21 +61,20 @@ public:
}; };
ProgressSink * StdioProgressSinkFactory::create_progress_sink(const std::string &title) const { ProgressSink * StdioProgressSinkFactory::create_progress_sink(const std::string &title) const {
return new StdioProgressSink(file, title); return new StdioProgressSink(title);
} }
StdioProgressSink::StdioProgressSink(FILE *file, const std::string &title) StdioProgressSink::StdioProgressSink(const std::string &title)
: file(file) : operation(title)
, operation(title)
, progress(0) { , progress(0) {
fprintf(file, "=== %s ===\n", title.c_str()); std::cout << title << ": ";
print(); print();
} }
StdioProgressSink::~StdioProgressSink() StdioProgressSink::~StdioProgressSink()
{ {
fprintf(file, "\n -===-\n"); std::cout << "end" << std::endl;
} }
@ -82,7 +85,7 @@ void StdioProgressSink::set_progress(int steps, int max) {
float old_progress = progress; float old_progress = progress;
progress = (100.f * steps)/max; progress = (100.f * steps)/max;
if (fabs(progress-old_progress) > 0.8) if (std::fabs(progress-old_progress) > 0.8)
{ {
print(); print();
} }
@ -96,7 +99,7 @@ void StdioProgressSink::set_operation(const std::string &operation) {
void StdioProgressSink::print() { void StdioProgressSink::print() {
fprintf(file, "%s: %.1f%%\r", operation.c_str(), progress); std::cout << operation << ": " << std::setprecision(2) << progress << std::endl;
} }

View file

@ -50,10 +50,9 @@ public:
class StdioProgressSinkFactory : public ProgressSinkFactory { class StdioProgressSinkFactory : public ProgressSinkFactory {
private: private:
FILE *file;
public: public:
StdioProgressSinkFactory(FILE *file) : file(file) { } StdioProgressSinkFactory();
virtual ProgressSink * create_progress_sink(const std::string &title) const; virtual ProgressSink * create_progress_sink(const std::string &title) const;
}; };