libfoedus-core
FOEDUS Core Library
error_code.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014-2015, Hewlett-Packard Development Company, LP.
3  * This program is free software; you can redistribute it and/or modify it
4  * under the terms of the GNU General Public License as published by the Free
5  * Software Foundation; either version 2 of the License, or (at your option)
6  * any later version.
7  *
8  * This program is distributed in the hope that it will be useful, but WITHOUT
9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11  * more details. You should have received a copy of the GNU General Public
12  * License along with this program; if not, write to the Free Software
13  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
14  *
15  * HP designates this particular file as subject to the "Classpath" exception
16  * as provided by HP in the LICENSE.txt file that accompanied this code.
17  */
18 #ifndef FOEDUS_ERROR_CODE_HPP_
19 #define FOEDUS_ERROR_CODE_HPP_
20 
21 namespace foedus {
22 
75 #define X(a, b, c) a = b,
76 
85 enum ErrorCode {
88 #include "foedus/error_code.xmacro" // NOLINT
89 };
90 #undef X
91 
96 const char* get_error_name(ErrorCode code);
97 
102 const char* get_error_message(ErrorCode code);
103 
104 // A bit tricky to get "a" from a in C macro.
105 #define X_QUOTE(str) #str
106 #define X_EXPAND_AND_QUOTE(str) X_QUOTE(str)
107 #define X(a, b, c) case a: return X_EXPAND_AND_QUOTE(a);
108 inline const char* get_error_name(ErrorCode code) {
109  switch (code) {
110  case kErrorCodeOk: return "kErrorCodeOk";
111 #include "foedus/error_code.xmacro" // NOLINT
112  }
113  return "Unexpected error code";
114 }
115 #undef X
116 #undef X_EXPAND_AND_QUOTE
117 #undef X_QUOTE
119 #define X(a, b, c) case a: return c;
120 inline const char* get_error_message(ErrorCode code) {
121  switch (code) {
122  case kErrorCodeOk: return "no_error";
123 #include "foedus/error_code.xmacro" // NOLINT
124  }
125  return "Unexpected error code";
126 }
127 #undef X
128 } // namespace foedus
155 #define CHECK_ERROR_CODE(x)\
156 {\
157  foedus::ErrorCode __e = x;\
158  if (UNLIKELY(__e != kErrorCodeOk)) {\
159  return __e;\
160  }\
161 }
163 #endif // FOEDUS_ERROR_CODE_HPP_
Root package of FOEDUS (Fast Optimistic Engine for Data Unification Services).
Definition: assert_nd.hpp:44
const char * get_error_name(ErrorCode code)
Returns the names of ErrorCode enum defined in error_code.xmacro.
Definition: error_code.hpp:108
Error code/message definition in X-Macro style.
0 means no-error.
Definition: error_code.hpp:87
const char * get_error_message(ErrorCode code)
Returns the error messages corresponding to ErrorCode enum defined in error_code.xmacro.
Definition: error_code.hpp:120
ErrorCode
Enum of error codes defined in error_code.xmacro.
Definition: error_code.hpp:85