Go to the documentation of this file.00001
00018 #ifndef DOIL_DOIL_H
00019 #define DOIL_DOIL_H
00020
00021 #include <string>
00022 #include <vector>
00023
00024 namespace doil
00025 {
00051 #define UNUSED_ARG(a) do {} while (&a == 0)
00052
00053 enum ReturnCode_t
00054 {
00055 OK,
00056 NOT_FOUND,
00057 ALREADY_EXISTS,
00058 INVALID_ARGS,
00059 UNKNOWN,
00060 };
00061
00062 static const char* return_codes[] =
00063 {
00064 "OK",
00065 "NOT_FOUND",
00066 "ALREADY_EXISTS",
00067 "INVALID_ARGS",
00068 "UNKNOWN"
00069 };
00070
00071 struct NamedReturnCode
00072 {
00073 NamedReturnCode(const char* n, ReturnCode_t r)
00074 : key_(n), ret_(r)
00075 {}
00076 std::string key_;
00077 ReturnCode_t ret_;
00078 };
00079
00080 class ReturnCodes
00081 {
00082 public:
00083 ReturnCodes()
00084 {
00085 }
00086 ReturnCodes(ReturnCode_t ret)
00087 {
00088 push_back("", ret);
00089 }
00090 void push_back(NamedReturnCode nr)
00091 {
00092 retcodes_.push_back(nr);
00093 }
00094 void push_back(const char* key, ReturnCode_t ret)
00095 {
00096 retcodes_.push_back(NamedReturnCode(key, ret));
00097 }
00098
00099 bool isOK()
00100 {
00101 if (retcodes_.size() == 1) return (retcodes_[0].ret_ == OK);
00102 for (int i(0), len(retcodes_.size()); i < len; ++i)
00103 {
00104 ReturnCode_t ret(retcodes_[i].ret_);
00105 if (ret != OK) return false;
00106 }
00107 return true;
00108 }
00109 std::vector<NamedReturnCode> retcodes_;
00110 };
00111 };
00112
00113 #endif // DOIL_DOIL_H