File: mbl_progress.cxx

package info (click to toggle)
vxl 1.17.0.dfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 153,280 kB
  • ctags: 105,123
  • sloc: cpp: 747,420; ansic: 209,130; fortran: 34,230; lisp: 14,915; sh: 6,187; python: 5,856; makefile: 340; perl: 294; xml: 160
file content (140 lines) | stat: -rw-r--r-- 4,057 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#include "mbl_progress.h"
// This is mul/mbl/mbl_progress.cxx
#ifdef VCL_NEEDS_PRAGMA_INTERFACE
#pragma implementation
#endif

#include <vcl_config_compiler.h>


//=======================================================================
void mbl_progress::set_estimated_iterations(const vcl_string& identifier,
                                            const int iterations,
                                            const vcl_string& display_text)
{
  identifier2estimatediterations_[identifier] = iterations;
  identifier2progress_[identifier] = 0;
  identifier2cancel_[identifier] = false;
  identifier2displaytext_[identifier] = display_text;
  on_set_estimated_iterations(identifier, iterations);
}


//=======================================================================
void mbl_progress::set_progress(const vcl_string& identifier,
                                const int progress)
{
  if (is_cancelled(identifier))
  {
    end_progress(identifier);
#if VCL_HAS_EXCEPTIONS
    if (throw_exception_on_cancel_)
    {
      throw mbl_progress_cancel_exception();
    }
#endif
  }

  vcl_map<vcl_string, int>::iterator it = identifier2progress_.find(identifier);
  if (it != identifier2progress_.end())
  {
    it->second = progress;
    on_set_progress(identifier, progress);
  }
}


//=======================================================================
void mbl_progress::increment_progress(const vcl_string& identifier,
                                      const int n)
{
  vcl_map<vcl_string, int>::const_iterator it =
    identifier2progress_.find(identifier);
  if (it != identifier2progress_.end())
  {
    int progress = it->second + n;
    set_progress(identifier, progress);
  }
}


//=======================================================================
void mbl_progress::end_progress(const vcl_string& identifier)
{
  on_end_progress(identifier);
}


//=======================================================================
int mbl_progress::progress(const vcl_string& identifier) const
{
  int p = -1;
  vcl_map<vcl_string, int>::const_iterator it =
    identifier2progress_.find(identifier);
  if (it != identifier2progress_.end())
  {
    p = it->second;
  }
  return p;
}


//=======================================================================
vcl_string mbl_progress::display_text(const vcl_string& identifier) const
{
  vcl_string dt;
  vcl_map<vcl_string, vcl_string>::const_iterator it =
    identifier2displaytext_.find(identifier);
  if (it != identifier2displaytext_.end())
  {
    dt = it->second;
  }
  return dt;
}


//=======================================================================
int mbl_progress::estimated_iterations(const vcl_string& identifier) const
{
  int n = -1;
  vcl_map<vcl_string, int>::const_iterator it =
    identifier2estimatediterations_.find(identifier);
  if (it != identifier2estimatediterations_.end())
  {
    n = it->second;
  }
  return n;
}


//=======================================================================
// Modify the flag to cancel the current process.
// identifier: Progress object to cancel.
//=======================================================================
void mbl_progress::set_cancelled(const vcl_string& identifier,
                                 const bool cancel)
{
  vcl_map<vcl_string, bool>::iterator it = identifier2cancel_.find(identifier);
  if (it != identifier2cancel_.end())
  {
    it->second = cancel;
  }
}


//=======================================================================
// Check whether a cancel request has been registered.
// identifier:  Progress object to check for a cancel request.
// Returns True if a cancel request has been received for this progress object.
//=======================================================================
bool mbl_progress::is_cancelled(const vcl_string &identifier) const
{
  bool retval = false;
  vcl_map<vcl_string, bool>::const_iterator it = identifier2cancel_.find(identifier);
  if (it != identifier2cancel_.end())
  {
    retval = it->second;
  }
  return retval;
}