Sequencer.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef BASE_SEQUENCER_H
00025 #define BASE_SEQUENCER_H
00026
00027 #include <vector>
00028 #include <memory>
00029 #include <CXX/Extensions.hxx>
00030
00031 #include "Exception.h"
00032
00033 namespace Base
00034 {
00035
00036 class AbortException;
00037 class SequencerLauncher;
00038
00115 class BaseExport SequencerBase
00116 {
00117 friend class SequencerLauncher;
00118
00119 public:
00131 static SequencerBase& Instance();
00138 virtual bool isBlocking() const;
00143 bool setLocked(bool bLock);
00145 bool isLocked() const;
00147 bool isRunning() const;
00151 bool wasCanceled() const;
00152
00153 protected:
00159 bool start(const char* pszStr, size_t steps);
00161 size_t numberOfSteps() const;
00163 int progressInPercent() const;
00174 bool next(bool canAbort = false);
00179 bool stop();
00185 virtual void pause();
00190 virtual void resume();
00195 void tryToCancel();
00201 void rejectCancel();
00202
00203 protected:
00205 SequencerBase();
00207 virtual ~SequencerBase();
00212 virtual void setText (const char* pszTxt);
00217 virtual void startStep();
00224 virtual void nextStep(bool canAbort);
00228 virtual void setProgress(size_t);
00234 virtual void resetData();
00235
00236 protected:
00237 size_t nProgress;
00238 size_t nTotalSteps;
00240 private:
00241 bool _bLocked;
00242 bool _bCanceled;
00243 int _nLastPercentage;
00244 };
00245
00249 class BaseExport EmptySequencer : public Base::SequencerBase
00250 {
00251 public:
00253 EmptySequencer();
00255 ~EmptySequencer();
00256 };
00257
00261 class BaseExport ConsoleSequencer : public SequencerBase
00262 {
00263 public:
00265 ConsoleSequencer ();
00267 ~ConsoleSequencer ();
00268
00269 protected:
00271 void startStep();
00273 void nextStep(bool canAbort);
00274
00275 private:
00277 void setText (const char* pszTxt);
00279 void resetData();
00280 };
00281
00364 class BaseExport SequencerLauncher
00365 {
00366 public:
00367 SequencerLauncher(const char* pszStr, size_t steps);
00368 ~SequencerLauncher();
00369 size_t numberOfSteps() const;
00370 void setText (const char* pszTxt);
00371 bool next(bool canAbort = false);
00372 void setProgress(size_t);
00373 bool wasCanceled() const;
00374 };
00375
00377 inline SequencerBase& Sequencer ()
00378 {
00379 return SequencerBase::Instance();
00380 }
00381
00382 class BaseExport ProgressIndicatorPy : public Py::PythonExtension<ProgressIndicatorPy>
00383 {
00384 public:
00385 static void init_type(void);
00386
00387 ProgressIndicatorPy();
00388 ~ProgressIndicatorPy();
00389
00390 Py::Object repr();
00391
00392 Py::Object start(const Py::Tuple&);
00393 Py::Object next(const Py::Tuple&);
00394 Py::Object stop(const Py::Tuple&);
00395
00396 private:
00397 static PyObject *PyMake(struct _typeobject *, PyObject *, PyObject *);
00398
00399 private:
00400 std::auto_ptr<SequencerLauncher> _seq;
00401 };
00402
00403 }
00404
00405 #endif // BASE_SEQUENCER_H