ARC SDK
JobState.h
1 #ifndef __ARC_JOBSTATE_H__
2 #define __ARC_JOBSTATE_H__
3 
4 #include <string>
5 #include <map>
6 
7 #ifdef JOBSTATE_TABLE
8 #undef JOBSTATE_TABLE
9 #endif
10 
11 #ifdef JOBSTATE_X
12 #undef JOBSTATE_X
13 #endif
14 
15 namespace Arc {
16 
42  class JobState {
43  public:
55  enum StateType {
60 
65 
70 
75 
80 
85 
90 
95 
100 
105 
110 
115 
120  };
121 
122  static const std::string StateTypeString[];
123 
124  JobState() : ssf(FormatSpecificState), type(UNDEFINED) {}
126 
129  JobState(const std::string& jobstate) : ssf(FormatSpecificState), state(jobstate), type(GetStateType(jobstate)) {}
130 
131  JobState& operator=(const JobState& js) { type = js.type; state = js.state; ssf = js.ssf; return *this; }
132 
133  operator bool() const { return type != UNDEFINED; }
134  operator StateType() const { return type; }
135  bool operator!() const { return type == UNDEFINED; }
136  bool operator==(const StateType& st) const { return type == st; }
137  bool operator!=(const StateType& st) const { return type != st; }
138 
140 
144  bool IsFinished() const { return type == FINISHED || type == KILLED || type == FAILED || type == DELETED; }
145 
147 
154  const std::string& operator()() const { return state; }
155 
157 
165  const std::string& GetGeneralState() const { return StateTypeString[type]; }
166 
168 
176  std::string GetSpecificState() const { return ssf(state); }
177 
178  static StateType GetStateType(const std::string& state);
179 
180  friend class Job;
181 
182  protected:
183  typedef std::string (*SpecificStateFormater)(const std::string&);
184  SpecificStateFormater ssf;
185  static std::string FormatSpecificState(const std::string& state) { return state; }
186 
187  JobState(const std::string& state, JobState::StateType (*map)(const std::string&), SpecificStateFormater ssf = FormatSpecificState)
188  : ssf(ssf), state(state), type((*map)(state)) {};
189  std::string state;
190  StateType type;
191  };
192 
197  typedef JobState::StateType (*JobStateMap)(const std::string&);
198 }
199 
200 #endif // __ARC_JOBSTATE_H__