[MOAB-dev] r3720 - MOAB/trunk/src
kraftche at cae.wisc.edu
kraftche at cae.wisc.edu
Mon Mar 29 08:14:06 CDT 2010
Author: kraftche
Date: 2010-03-29 08:14:05 -0500 (Mon, 29 Mar 2010)
New Revision: 3720
Modified:
MOAB/trunk/src/Core.cpp
Log:
use switch statement rather than array indexing to convert moab::ErrorCode to string because a) performance should never be an issue for this function and b) it is safer
Modified: MOAB/trunk/src/Core.cpp
===================================================================
--- MOAB/trunk/src/Core.cpp 2010-03-29 13:11:11 UTC (rev 3719)
+++ MOAB/trunk/src/Core.cpp 2010-03-29 13:14:05 UTC (rev 3720)
@@ -2969,28 +2969,28 @@
return mError->get_last_error(info);
}
+#define MB_CASE_STRING(A) case A: return #A;
std::string Core::get_error_string(const ErrorCode code) const
{
- static const char* errorStrings[MB_FAILURE+1] = {
- "MB_SUCCESS",
- "MB_INDEX_OUT_OF_RANGE",
- "MB_TYPE_OUT_OF_RANGE",
- "MB_MEMORY_ALLOCATION_FAILED",
- "MB_ENTITY_NOT_FOUND",
- "MB_MULTIPLE_ENTITIES_FOUND",
- "MB_TAG_NOT_FOUND",
- "MB_FILE_DOES_NOT_EXIST",
- "MB_FILE_WRITE_ERROR",
- "MB_NOT_IMPLEMENTED",
- "MB_ALREADY_ALLOCATED",
- "MB_VARIABLE_DATA_LENGTH",
- "MB_INVALID_SIZE",
- "MB_UNSUPPORTED_OPERATION",
- "MB_UNHANDLED_OPTION",
- "MB_FAILURE",
- };
-
- return errorStrings[code];
+ switch (code) {
+ MB_CASE_STRING(MB_SUCCESS);
+ MB_CASE_STRING(MB_INDEX_OUT_OF_RANGE);
+ MB_CASE_STRING(MB_TYPE_OUT_OF_RANGE);
+ MB_CASE_STRING(MB_MEMORY_ALLOCATION_FAILED);
+ MB_CASE_STRING(MB_ENTITY_NOT_FOUND);
+ MB_CASE_STRING(MB_MULTIPLE_ENTITIES_FOUND);
+ MB_CASE_STRING(MB_TAG_NOT_FOUND);
+ MB_CASE_STRING(MB_FILE_DOES_NOT_EXIST);
+ MB_CASE_STRING(MB_FILE_WRITE_ERROR);
+ MB_CASE_STRING(MB_NOT_IMPLEMENTED);
+ MB_CASE_STRING(MB_ALREADY_ALLOCATED);
+ MB_CASE_STRING(MB_VARIABLE_DATA_LENGTH);
+ MB_CASE_STRING(MB_INVALID_SIZE);
+ MB_CASE_STRING(MB_UNSUPPORTED_OPERATION);
+ MB_CASE_STRING(MB_UNHANDLED_OPTION);
+ MB_CASE_STRING(MB_FAILURE);
+ default: assert(!"unknown error code"); return "(UNKNOWN ERROR CODE)";
+ }
}
void Core::print(const EntityHandle ms_handle, const char *prefix,
More information about the moab-dev
mailing list