00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #ifndef CBZ_PHASE_H
00039 #define CBZ_PHASE_H
00040
00041
00042
00043
00044
00045
00046
00047 class Phase
00048 {
00049 public:
00050
00051 virtual void run() =0;
00052
00053 virtual void get_flags(str_list_p & arg) { };
00054
00055 virtual void usage() { };
00056 };
00057
00058
00059
00060
00061
00062
00063
00064 class Phase_entry
00065 {
00066 private:
00067
00068 string _name;
00069 int _order;
00070 Phase * _phase;
00071 string _desc;
00072
00073 public:
00074
00075 Phase_entry(const char * name, Phase * phase, const char * desc)
00076 : _name(string(name)),
00077 _order(0),
00078 _phase(phase)
00079 {
00080 if ( desc )
00081 _desc = string(desc);
00082 else
00083 _desc = "No description.";
00084 }
00085
00086 ~Phase_entry() { delete _phase; }
00087
00088 inline int order() const { return _order; }
00089 inline void order(int order) { _order = order; }
00090
00091 inline void disable() { _order = 0; }
00092 inline bool is_enabled() const { return _order != 0; }
00093
00094 inline string & name() { return _name; }
00095 inline const string & name() const { return _name; }
00096 inline void name(string & name) { _name = name; }
00097
00098 inline Phase * phase() const { return _phase; }
00099
00100
00101 inline void print() const {
00102 if (_phase) {
00103 cout << "Phase \"" << _name << "\": " << _desc << endl;
00104 _phase->usage();
00105 }
00106 }
00107 };
00108
00109 typedef vector< Phase_entry * > phase_vec;
00110 typedef phase_vec::iterator phase_vec_p;
00111
00112
00113
00114 class Less_phases
00115 {
00116 public:
00117 int operator()(const Phase_entry * ph1, const Phase_entry * ph2)
00118 { return ph1->order() < ph2->order(); }
00119 };
00120
00121 class Equal_phases
00122 {
00123 private:
00124
00125 string & _name;
00126
00127 public:
00128
00129 Equal_phases(string & name)
00130 : _name(name)
00131 {}
00132
00133 bool operator()(const Phase_entry * ph)
00134 { return ph->name() == _name; }
00135 };
00136
00137
00138
00139
00140 class Phases
00141 {
00142
00143 private:
00144
00145
00146
00147 static int _count;
00148 static int _cur_order;
00149 static phase_vec * _phases;
00150
00151 public:
00152
00153
00154
00155 Phases(const char * name, Phase * new_phase, const char * desc = NULL);
00156
00157 ~Phases();
00158
00159
00160
00161 static void run_all();
00162
00163
00164
00165 static bool phase_flag(str_list_p & arg);
00166
00167
00168
00169 static void next_phase(string & name);
00170 static void disable_phase(string & name);
00171 static phase_vec * phases() { return _phases; }
00172 };
00173
00174
00175
00176 #endif // CBZ_PHASE_H