Mass++ Common Libraries v2.7.5
 All Classes Namespaces Files Functions Variables Enumerations Macros
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
kome::core::Progress Class Referenceabstract

progress display abstract class More...

#include <Progress.h>

Inheritance diagram for kome::core::Progress:
Inheritance graph
[legend]
Collaboration diagram for kome::core::Progress:
Collaboration graph
[legend]

Public Member Functions

 Progress (const char *title=NULL)
 constructor More...
 
virtual ~Progress ()
 destructor
 
void setRange (const int start, const int end)
 sets progress range More...
 
void setPosition (const int pos, const bool bForced=false)
 sets progress position More...
 
void setStatus (const char *status, const bool bForced=false)
 sets status More...
 
bool isStopped ()
 judges whether it has to finish More...
 
void fill ()
 sets end position
 
int getRelativePosition ()
 gets relative position More...
 
Timer * createTimer (const char *name)
 creates timer More...
 
unsigned int getNumberOfTimers ()
 gets the number of timers More...
 
const char * getTimerName (const unsigned int index)
 gets timer name More...
 
Timer * getTimer (const unsigned int index)
 gets timer More...
 
void createSubProgresses (const unsigned int num)
 creates sub progresses More...
 
unsigned int getNumberOfSubProgresses ()
 gets the number of sub progresses More...
 
Progress * getSubProgress (const unsigned int idx)
 gets subprogress More...
 

Static Public Member Functions

static Progress & getIgnoringProgress ()
 gets progress object. But this object does nothing even if a method is called. More...
 

Protected Member Functions

virtual void onSetRange (const int start, const int end)=0
 This method is called by setRange method. (abstract method) More...
 
virtual void onSetPosition (const int pos, const int prevPos)=0
 This method is called by setPosition method. (abstract method) More...
 
virtual void onSetStatus (const char *status, const bool bForced)=0
 This method is called by setStatus method. (abstract method) More...
 
virtual bool onIsStopped ()=0
 This method is called by isStopped method. (abstract method) More...
 
virtual void onFill (void)=0
 This method is called by fill method. (abstract method)
 

Protected Attributes

std::vector< Progress * > m_subProgresses
 
int m_start
 
int m_end
 
int m_pos
 
int m_prevPos
 
int m_relPos
 
std::string m_title
 
Timer m_timer
 
std::vector< std::pair
< std::string, Timer * > > * 
m_timers
 
long long m_llPrevTime
 
std::string m_strStatus
 

Detailed Description

progress display abstract class

Definition at line 31 of file Progress.h.

Constructor & Destructor Documentation

kome::core::Progress::Progress ( const char *  title = NULL)

constructor

Parameters
[in]titleprogress title

Definition at line 37 of file Progress.cpp.

37  {
38  m_start = 0;
39  m_end = 0;
40  m_pos = 0;
41  m_prevPos = 0;
42  m_relPos = 0;
43  m_title = NVL( title, "" );
44 
45 // >>>>>> @Date:2013/11/18 <Add> A.Ozaki
46 //
47  m_llPrevTime = 0;
48  m_strStatus.clear( );
49 //
50 // <<<<<< @Date:2013/11/18 <Add> A.Ozaki
51 
52  m_timers = new std::vector< std::pair< std::string, Timer* > >();
53 }
std::string m_title
Definition: Progress.h:62
std::vector< std::pair< std::string, Timer * > > * m_timers
Definition: Progress.h:68
#define NVL(checkVal, replaceVal)
Definition: CoreMacros.h:99
std::string m_strStatus
Definition: Progress.h:115
long long m_llPrevTime
Definition: Progress.h:112

Member Function Documentation

void kome::core::Progress::createSubProgresses ( const unsigned int  num)

creates sub progresses

Parameters
[in]numthe number of subprogresses

Definition at line 299 of file Progress.cpp.

299  {
300  // check the number
301  if( num == 0 ) {
302  return;
303  }
304  if( this == &( getIgnoringProgress() ) ) {
305  return;
306  }
307 
308  // create progresses
309  m_subProgresses.reserve( num );
310  for( unsigned int i = 0; i < num; i++ ) {
311  Progress* subProgress = new SubProgress( *this );
312  delete subProgress->m_timers;
313  subProgress->m_timers = m_timers;
314 
315  m_subProgresses.push_back( subProgress );
316  }
317 
318  // set range
319  setRange( 0, (int)m_subProgresses.size() * 100 );
320 }
static Progress & getIgnoringProgress()
gets progress object. But this object does nothing even if a method is called.
Definition: Progress.cpp:343
std::vector< std::pair< std::string, Timer * > > * m_timers
Definition: Progress.h:68
std::vector< Progress * > m_subProgresses
Definition: Progress.h:48
progress display abstract class
Definition: Progress.h:31
sub progress object.
Definition: Progress.h:295
void setRange(const int start, const int end)
sets progress range
Definition: Progress.cpp:79

Here is the call graph for this function:

Timer * kome::core::Progress::createTimer ( const char *  name)

creates timer

Parameters
[in]nametimer name
Returns
created timer

Definition at line 252 of file Progress.cpp.

252  {
253  // check the name
254  if( name == NULL || m_timers == NULL ) {
255  return NULL;
256  }
257 
258  // search
259  for( unsigned int i = 0; i < m_timers->size(); i++ ) {
260  if( ( *m_timers )[ i ].first.compare( name ) == 0 ) {
261  return ( *m_timers )[ i ].second;
262  }
263  }
264 
265  // new timer
266  m_timers->push_back( std::make_pair( name, new Timer() ) );
267 
268  return m_timers->back().second;
269 }
std::vector< std::pair< std::string, Timer * > > * m_timers
Definition: Progress.h:68
timer class
Definition: Timer.h:26
#define NULL
Definition: CoreMacros.h:18
static Progress & kome::core::Progress::getIgnoringProgress ( )
static

gets progress object. But this object does nothing even if a method is called.

Returns
progress object

Definition at line 343 of file Progress.cpp.

343  {
344  static IgnoringProgress progress;
345 
346  return progress;
347 }
Progress object. Even if a method is called, it disgards it.
Definition: Progress.h:238
unsigned int kome::core::Progress::getNumberOfSubProgresses ( )

gets the number of sub progresses

Returns
the number of sub progresses

Definition at line 323 of file Progress.cpp.

323  {
324  if( this == &( getIgnoringProgress() ) ) {
325  return 0;
326  }
327  return m_subProgresses.size();
328 }
static Progress & getIgnoringProgress()
gets progress object. But this object does nothing even if a method is called.
Definition: Progress.cpp:343
std::vector< Progress * > m_subProgresses
Definition: Progress.h:48

Here is the call graph for this function:

unsigned int kome::core::Progress::getNumberOfTimers ( )

gets the number of timers

Returns
the number of timers

Definition at line 272 of file Progress.cpp.

272  {
273  if( m_timers == NULL ) {
274  return 0;
275  }
276 
277  return m_timers->size();
278 }
std::vector< std::pair< std::string, Timer * > > * m_timers
Definition: Progress.h:68
#define NULL
Definition: CoreMacros.h:18
int kome::core::Progress::getRelativePosition ( )

gets relative position

Returns
relative position

Definition at line 247 of file Progress.cpp.

247  {
248  return m_relPos;
249 }
Progress * kome::core::Progress::getSubProgress ( const unsigned int  idx)

gets subprogress

Parameters
[in]idxsub progress index
Returns
sub progress object (If NULL, the index is illegal.)

Definition at line 331 of file Progress.cpp.

331  {
332  if( this == &( getIgnoringProgress() ) ) {
333  return this;
334  }
335  if( idx >= m_subProgresses.size() ) {
336  return NULL;
337  }
338 
339  return m_subProgresses[ idx ];
340 }
static Progress & getIgnoringProgress()
gets progress object. But this object does nothing even if a method is called.
Definition: Progress.cpp:343
std::vector< Progress * > m_subProgresses
Definition: Progress.h:48
#define NULL
Definition: CoreMacros.h:18

Here is the call graph for this function:

Timer * kome::core::Progress::getTimer ( const unsigned int  index)

gets timer

Parameters
[in]indextimer index
Returns
timer object

Definition at line 290 of file Progress.cpp.

290  {
291  if( m_timers == NULL || index >= m_timers->size() ) {
292  return NULL;
293  }
294 
295  return ( *m_timers )[ index ].second;
296 }
std::vector< std::pair< std::string, Timer * > > * m_timers
Definition: Progress.h:68
#define NULL
Definition: CoreMacros.h:18
const char * kome::core::Progress::getTimerName ( const unsigned int  index)

gets timer name

Parameters
[in]indextimer index
Returns
timer name (If NULL, the index is illegal.)

Definition at line 281 of file Progress.cpp.

281  {
282  if( m_timers == NULL || index >= m_timers->size() ) {
283  return NULL;
284  }
285 
286  return ( *m_timers )[ index ].first.c_str();
287 }
std::vector< std::pair< std::string, Timer * > > * m_timers
Definition: Progress.h:68
#define NULL
Definition: CoreMacros.h:18
bool kome::core::Progress::isStopped ( )

judges whether it has to finish

Returns
If it has to finish, this method returns true

Definition at line 199 of file Progress.cpp.

199  {
200  bool ret = onIsStopped();
201 
202  return ret;
203 }
virtual bool onIsStopped()=0
This method is called by isStopped method. (abstract method)

Here is the call graph for this function:

bool kome::core::Progress::onIsStopped ( )
protectedpure virtual

This method is called by isStopped method. (abstract method)

Returns
If it has to finish, this method returns true

Implemented in kome::core::SubProgress, kome::core::IgnoringProgress, and kome::core::DisplayProgress.

void kome::core::Progress::onSetPosition ( const int  pos,
const int  prevPos 
)
protectedpure virtual

This method is called by setPosition method. (abstract method)

Parameters
[in]posprogress position
[in]prevPosprevious position

Implemented in kome::core::SubProgress, kome::core::IgnoringProgress, and kome::core::DisplayProgress.

void kome::core::Progress::onSetRange ( const int  start,
const int  end 
)
protectedpure virtual

This method is called by setRange method. (abstract method)

Parameters
[in]startstart position
[in]endend position

Implemented in kome::core::SubProgress, kome::core::IgnoringProgress, and kome::core::DisplayProgress.

void kome::core::Progress::onSetStatus ( const char *  status,
const bool  bForced 
)
protectedpure virtual

This method is called by setStatus method. (abstract method)

Parameters
[in]statusstatus
[in]bForcedflag for drawing forced

Implemented in kome::core::SubProgress, kome::core::IgnoringProgress, and kome::core::DisplayProgress.

void kome::core::Progress::setPosition ( const int  pos,
const bool  bForced = false 
)

sets progress position

Parameters
[in]posprogress position
[in]bForcedflag of drawing forced

Definition at line 98 of file Progress.cpp.

98  {
99 
100  // set members
101  m_prevPos = m_pos;
102  m_pos = pos;
103 
104 // >>>>>> @Date:2013/11/18 <Add> A.Ozaki
105 //
106 #ifdef _USE_INTERVAL_
107  if ( false == bForced )
108  {
109  long long llPassed = getcurrenttime( );
110  llPassed = llPassed - m_llPrevTime;
111  if ( DRAW_INTERVAL > llPassed )
112  {
113  return;
114  }
115  }
116  m_llPrevTime = getcurrenttime( );
117 #endif
118 //
119 // <<<<<< @Date:2013/11/18 <Add> A.Ozaki
120 
121 
122  if( m_start == m_end ) {
123  m_relPos = 0;
124  }
125  else {
126  double d1 = (double)abs( m_pos - m_start );
127  double d2 = (double)abs( m_end - m_pos );
128  m_relPos = roundnum( d1 * 100.0 / ( d1 + d2 ) );
129  }
130 
131 // >>>>>> @Date:2013/11/18 <Add> A.Ozaki
132 //
133 #ifndef _USE_INTERVAL_
134  if( isStopped() ){ // @date 2013.09.26 <Mod> M.Izumi
135  return;
136  }
137  // set position
139 #else
140  if ( false == m_strStatus.empty( ) )
141  {
142  onSetStatus( m_strStatus.c_str( ), bForced );
143  m_strStatus.clear( );
144  }
145 
146  // set position
148 
149  if ( isStopped( ) )
150  {
151  return;
152  }
153 #endif
154  return;
155 //
156 // <<<<<< @Date:2013/11/18 <Add> A.Ozaki
157 }
bool isStopped()
judges whether it has to finish
Definition: Progress.cpp:199
int roundnum(const double v)
gets the closest integer to the argument
std::string m_strStatus
Definition: Progress.h:115
virtual void onSetPosition(const int pos, const int prevPos)=0
This method is called by setPosition method. (abstract method)
long long m_llPrevTime
Definition: Progress.h:112
long long getcurrenttime()
gets current time in miliseconds
virtual void onSetStatus(const char *status, const bool bForced)=0
This method is called by setStatus method. (abstract method)

Here is the call graph for this function:

void kome::core::Progress::setRange ( const int  start,
const int  end 
)

sets progress range

Parameters
[in]startstart position
[in]endend position

Definition at line 79 of file Progress.cpp.

79  {
80 
81  // set members
82  m_start = start;
83  m_end = end;
84 
85  // start timer
86  m_timer.start();
87 
88  // set range
89  onSetRange( start, end );
90  setPosition( start );
91 
92  if( isStopped() ){ // @date 2013.09.26 <Mod> M.Izumi
93  return;
94  }
95 }
void start()
starts timer
Definition: Timer.cpp:46
bool isStopped()
judges whether it has to finish
Definition: Progress.cpp:199
void setPosition(const int pos, const bool bForced=false)
sets progress position
Definition: Progress.cpp:98
virtual void onSetRange(const int start, const int end)=0
This method is called by setRange method. (abstract method)

Here is the call graph for this function:

void kome::core::Progress::setStatus ( const char *  status,
const bool  bForced = false 
)

sets status

Parameters
[in]statusstatus
[in]bForcedflag of drawing forced

Definition at line 160 of file Progress.cpp.

160  {
161 // >>>>>> @Date:2013/11/18 <Add> A.Ozaki
162 //
163 #ifndef _USE_INTERVAL_
164  if( isStopped() ){ // @date 2013.09.26 <Mod> M.Izumi
165  return;
166  }
167  onSetStatus( status );
168 #else
169  if ( (const char *)NULL == status )
170  {
171  if ( false == m_strStatus.empty( ) )
172  {
173  onSetStatus( m_strStatus.c_str( ), bForced );
174  }
175  }
176  else
177  {
178  if ( false == bForced )
179  {
180  m_strStatus = NVL( status, "" );
181  }
182  else
183  {
184  onSetStatus( status, bForced );
185  }
186 
187  if ( isStopped( ) )
188  {
189  return;
190  }
191  }
192 #endif
193  return;
194 //
195 // <<<<<< @Date:2013/11/18 <Add> A.Ozaki
196 }
bool isStopped()
judges whether it has to finish
Definition: Progress.cpp:199
#define NVL(checkVal, replaceVal)
Definition: CoreMacros.h:99
std::string m_strStatus
Definition: Progress.h:115
#define NULL
Definition: CoreMacros.h:18
virtual void onSetStatus(const char *status, const bool bForced)=0
This method is called by setStatus method. (abstract method)

Here is the call graph for this function:

Member Data Documentation

int kome::core::Progress::m_end
protected

end position

Definition at line 53 of file Progress.h.

long long kome::core::Progress::m_llPrevTime
protected

previous update time

Definition at line 112 of file Progress.h.

int kome::core::Progress::m_pos
protected

current position

Definition at line 55 of file Progress.h.

int kome::core::Progress::m_prevPos
protected

previous position

Definition at line 57 of file Progress.h.

int kome::core::Progress::m_relPos
protected

relative position

Definition at line 59 of file Progress.h.

int kome::core::Progress::m_start
protected

start position

Definition at line 51 of file Progress.h.

std::string kome::core::Progress::m_strStatus
protected

status message

Definition at line 115 of file Progress.h.

std::vector< Progress* > kome::core::Progress::m_subProgresses
protected

sub progresses

Definition at line 48 of file Progress.h.

Timer kome::core::Progress::m_timer
protected

main timer

Definition at line 65 of file Progress.h.

std::vector< std::pair< std::string, Timer* > >* kome::core::Progress::m_timers
protected

timer array

Definition at line 68 of file Progress.h.

std::string kome::core::Progress::m_title
protected

title

Definition at line 62 of file Progress.h.


The documentation for this class was generated from the following files: