OpendTect  6.3
executor.h
Go to the documentation of this file.
1 #pragma once
2 
3 /*+
4 ________________________________________________________________________
5 
6  (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt
7  Author: A.H.Bril
8  Date: 11-7-1996
9 ________________________________________________________________________
10 
11 -*/
12 
13 #include "basicmod.h"
14 #include "task.h"
15 #include "namedobj.h"
16 #include "progressmeter.h"
17 #include "notify.h"
18 #include "od_iosfwd.h"
19 
39 {
40 public:
41  Executor( const char* nm )
42  : SequentialTask(nm)
43  , prestep(this), poststep(this) {}
44  virtual ~Executor() {}
45 
46  virtual int doStep();
47 
48  inline bool go( od_ostream* s=0, bool isfirst=true,
49  bool islast=true, int delaybtwnstepsinms=0 )
50  { return goImpl(s,isfirst,islast,delaybtwnstepsinms); }
51  inline bool go( od_ostream& s, bool isfirst=true,
52  bool islast=true, int delaybtwnstepsinms=0 )
53  { return goImpl(&s,isfirst,islast,delaybtwnstepsinms); }
54 
57 
58  // Being a Task requires:
59  virtual bool execute() { return go(); }
60 
61  // Being an Executor requires:
62  virtual uiString message() const = 0;
63  virtual uiString nrDoneText() const = 0;
64  virtual od_int64 nrDone() const = 0;
65 
66 protected:
67 
68  virtual bool goImpl(od_ostream*,bool,bool,int);
69 
70 };
71 
72 
82 {
83 public:
84  ExecutorGroup( const char* nm, bool parallel=false,
85  bool ownsexecs=true );
86  virtual ~ExecutorGroup();
87  virtual void add( Executor* );
90  uiString message() const;
91  virtual od_int64 totalNr() const;
92  virtual od_int64 nrDone() const;
93  uiString nrDoneText() const;
94 
95  int nrExecutors() { return executors_.size(); }
96  Executor* getExecutor(int idx) { return executors_[idx]; }
97 
98  void setNrDoneText(const uiString& txt)
99  { nrdonetext_ = txt; }
101 
102 protected:
103 
104  virtual int nextStep();
105  virtual bool goToNextExecutor();
106  void findNextSumStop();
107 
109  int sumstop_;
110  const bool parallel_;
116 
117 };
118 
119 
125 {
126 public:
128  : TaskRunner()
129  , strm_(strm) {}
130 
131  bool execute(Task&);
132 
133 protected:
134 
136 
137 };
#define mExpClass(module)
Definition: commondefs.h:157
OD class for stream write common access to the user log file, or std::cout in batch progs...
Definition: od_ostream.h:25
Executor consisting of other executors.
Definition: executor.h:81
Notifier< Executor > prestep
Definition: executor.h:55
#define od_int64
Definition: plftypes.h:34
ObjectSet< Executor > & executors_
Definition: executor.h:113
const bool parallel_
Definition: executor.h:110
Notifier< Executor > poststep
Only when MoreToDo will be returned.
Definition: executor.h:56
Definition: uistring.h:88
Executor * getExecutor(int idx)
Definition: executor.h:96
od_ostream & strm_
Definition: executor.h:135
void message(const char *)
default: to stderr
The generalization of something (e.g. a computation) where the steps must be done in sequence...
Definition: task.h:147
int nrExecutors()
Definition: executor.h:95
void setNrDoneText(const uiString &txt)
If set, will use this and the counted nrdone.
Definition: executor.h:98
int sumstop_
Definition: executor.h:109
Class that can execute a task.
Definition: task.h:193
TextTaskRunner(od_ostream &strm)
Definition: executor.h:127
bool go(od_ostream &s, bool isfirst=true, bool islast=true, int delaybtwnstepsinms=0)
Definition: executor.h:51
virtual ~Executor()
Definition: executor.h:44
uiString nrdonetext_
Definition: executor.h:112
TaskRunner to show progress of a Task in text format.
Definition: executor.h:124
int currentexec_
Definition: executor.h:111
int sumstart_
Definition: executor.h:108
TypeSet< int > executorres_
Definition: executor.h:114
int doStep()
Generalization of something (e.g. a computation) that needs to be done in multiple steps...
Definition: task.h:26
bool ownsexecs_
Definition: executor.h:115
virtual bool execute()
Definition: executor.h:59
Executor(const char *nm)
Definition: executor.h:41
bool go(od_ostream *s=0, bool isfirst=true, bool islast=true, int delaybtwnstepsinms=0)
Definition: executor.h:48
Specification to enable chunkwise execution of a process.
Definition: executor.h:38

Generated at for the OpendTect seismic interpretation project. Copyright (C): dGB Beheer B. V. 2017