Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 #ifndef TASKRESULT_H_
00009 #define TASKRESULT_H_
00010
00011 #include <boost/thread.hpp>
00012 #include <deque>
00013 #include <vector>
00014 #include <boost/thread/mutex.hpp>
00015 #include <boost/thread/condition.hpp>
00016 #include <boost/shared_ptr.hpp>
00017
00018 namespace decision_making{
00019
00020 struct TaskResult{
00021 private:
00022 int error_;
00023 std::string description_;
00024 TaskResult(int er, std::string desc):error_(er),description_(desc){}
00025 static const int undefied_code = INT_MAX;
00026 static const int error_start_code = 2;
00027 static const int preempted_code = 1;
00028 public:
00029 TaskResult():error_(undefied_code),description_("UNDEF"){}
00030 static TaskResult SUCCESS(){ return TaskResult(0,"OK"); }
00031 static TaskResult FAIL(int er=error_start_code, std::string what="FIAL"){ return TaskResult(er, what); }
00032 static TaskResult FAIL(std::string what){ return TaskResult(error_start_code, what); }
00033 static TaskResult TERMINATED(){ return TaskResult(preempted_code, "TERMINATED"); }
00034 static TaskResult UNDEF(){ return TaskResult(undefied_code, "UNDEF"); }
00035 bool isFail()const{ return error_>=error_start_code and error_!=undefied_code; }
00036 bool isTermianted()const{ return error_==preempted_code; }
00037 bool isSuccess()const{ return error_<1; }
00038 bool isDefined()const{ return error_!=undefied_code; }
00039 bool isUndefined()const{ return not isDefined(); }
00040 int error()const{return error_;}
00041 std::string what()const{ return description_;}
00042
00043 static int rerangeErrorCode(int code){ return error_start_code-1+code; }
00044
00045 const bool operator==(const TaskResult& o)const{ return error_ == o.error_; }
00046 const bool operator!=(const TaskResult& o)const{ return error_ != o.error_; }
00047 };
00048 static std::ostream& operator<<(std::ostream& out, const TaskResult& res){
00049 out<<"Result{";
00050 if(res.isSuccess()) return out<<"SUCCESS}";
00051 if(res.isTermianted()) return out<<"TERMINATED}";
00052 if(res.isFail()) return out<<"Fail,"<<res.error()<<","<<res.what()<<"}";
00053 if(res.isUndefined()) return out<<"UNDEF}";
00054 return out<<"UNKNOWN,"<<res.error()<<","<<res.what()<<"}";
00055 }
00056
00057 static string str(const TaskResult& res){
00058 stringstream s; s<<res; return s.str();
00059 }
00060
00061 }
00062
00063
00064 #endif