00001 #include "GProgress_Bar.h"
00002 #include "io/GStd_Output.h"
00003 #include <iostream>
00004 #include <vector>
00005 #include <sstream>
00006
00007 using namespace GMathLib::Util;
00008 using namespace GMathLib::IO;
00009
00010 GProgress_Bar::GProgress_Bar()
00011 :GObject(), now_state(0), now_timestep(0), end_timestep(-1)
00012 {
00013 Class_Name("GProgress_Bar");
00014 }
00015
00016 GProgress_Bar::~GProgress_Bar()
00017 {
00018 }
00019
00020 void GProgress_Bar::Prepair(int end_time_step, const std::string content)
00021 {
00022 end_timestep = end_time_step;
00023
00024
00025 std::vector<std::string> list;
00026 std::ostringstream oss;
00027
00028 oss << "Start the loop! : Total " << end_timestep << "turns";
00029 list.push_back(oss.str());
00030 list.push_back(content);
00031 GStd_Output::Write(Class_Name() + "::Prepair()", list);
00032
00033
00034 time(&start_time);
00035 }
00036
00037 void GProgress_Bar::Update_Counter()
00038 {
00039 int aster_num = (int) ( (now_timestep+1) * 10 / end_timestep);
00040 now_timestep++;
00041
00042 if(now_state == aster_num){
00043 return;
00044 }
00045
00046
00047 time_t now_time;
00048 time(&now_time);
00049
00050
00051 std::cout << "[ ";
00052 for(int i=1; i <= 10; i++ ){
00053 if(i <= aster_num){
00054 std::cout << "*";
00055 }else{
00056 std::cout << " ";
00057 }
00058 }
00059 std::cout << " ] ";
00060 std::cout << aster_num * 10 << "% : ";
00061 std::cout << difftime(now_time, start_time) << " s " << std::endl;
00062
00063
00064 now_state = aster_num;
00065 }
00066