All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ConsoleProgressViewer.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file terralib/common/progress/ConsoleProgressViewer.cpp
22 
23  \brief A progress viewer implementation for the console.
24 */
25 
26 // TerraLib
27 #include "../Translator.h"
28 #include "ConsoleProgressViewer.h"
29 #include "TaskProgress.h"
30 
31 // STL
32 #include <iostream>
33 
36  m_totalSteps(0),
37  m_currentStep(0),
38  m_propStep(0)
39 {
40 }
41 
43 {
44 }
45 
47 {
48  m_tasks.insert(std::map<int, TaskProgress*>::value_type(id, t));
49 
50  updateMessage(-1);
51 }
52 
54 {
55  std::map<int, TaskProgress*>::iterator it = m_tasks.find(taskId);
56 
57  if(it != m_tasks.end())
58  {
59  m_tasks.erase(it);
60  updateMessage(-1);
61  }
62 
63  if(m_tasks.empty())
64  {
65  m_totalSteps = 0;
66  m_currentStep = 0;
67  m_propStep = 0;
68  }
69 }
70 
72 {
73  std::map<int, TaskProgress*>::iterator it = m_tasks.find(taskId);
74 
75  if(it != m_tasks.end())
76  {
77  //update total and current values
78  m_totalSteps -= it->second->getTotalSteps();
79  m_currentStep -= it->second->getCurrentStep();
80 
81  double aux = static_cast<double>(m_currentStep) / static_cast<double>(m_totalSteps);
82 
83  m_propStep = static_cast<int>(100.0 * aux);
84  }
85 }
86 
88 {
89  m_totalSteps += m_tasks[taskId]->getTotalSteps();
90 }
91 
93 {
94  m_currentStep++;
95 
96  double aux = static_cast<double>(m_currentStep) / static_cast<double>(m_totalSteps);
97 
98  int val = static_cast<int>(100.0 * aux);
99 
100  if((val != m_propStep) && (val >= 0))
101  {
102  m_propStep = val;
103 
104  std::cout << m_message << TE_TR(" - Percent: ") << m_propStep << "%" <<std::endl;
105  }
106 }
107 
109 {
110  if(m_tasks.size() == 1)
111  {
112  m_message = m_tasks.begin()->second->getMessage();
113  }
114  else
115  {
116  m_message = TE_TR("Multi Tasks");
117  }
118 }
119 
This class can be used to inform the progress of a task.
A progress viewer implementation for the console.
This class can be used to inform the progress of a task.
Definition: TaskProgress.h:53
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:347
void updateMessage(int taskId)
Update the progress message.
ConsoleProgressViewer()
Default constructor.
A class that defines the interface of an abstract progress viewer.
void addTask(TaskProgress *t, int id)
Insert a new task in the progress viewer.
void removeTask(int taskId)
Removes a task from progress viewer container.
void cancelTask(int taskId)
Cancel a task.
void setTotalValues(int taskId)
Set task total steps.
void updateValue(int taskId)
Update the progress evaluation.