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) {}
125 
126  JobState& operator=(const JobState& js) { type = js.type; state = js.state; ssf = js.ssf; return *this; }
127 
128  operator bool() const { return type != UNDEFINED; }
129  operator StateType() const { return type; }
130  bool operator!() const { return type == UNDEFINED; }
131  bool operator==(const StateType& st) const { return type == st; }
132  bool operator!=(const StateType& st) const { return type != st; }
133 
135 
139  bool IsFinished() const { return type == FINISHED || type == KILLED || type == FAILED || type == DELETED; }
140 
142 
149  const std::string& operator()() const { return state; }
150 
152 
160  const std::string& GetGeneralState() const { return StateTypeString[type]; }
161 
163 
171  std::string GetSpecificState() const { return ssf(state); }
172 
173  static StateType GetStateType(const std::string& state);
174 
175  friend class Job;
176 
177  protected:
178  typedef std::string (*SpecificStateFormater)(const std::string&);
179  SpecificStateFormater ssf;
180  static std::string FormatSpecificState(const std::string& state) { return state; }
181 
182  JobState(const std::string& state, JobState::StateType (*map)(const std::string&), SpecificStateFormater ssf = FormatSpecificState)
183  : ssf(ssf), state(state), type((*map)(state)) {};
184  std::string state;
185  StateType type;
186  };
187 
192  typedef JobState::StateType (*JobStateMap)(const std::string&);
193 }
194 
195 #endif // __ARC_JOBSTATE_H__