cgma
|
00001 #include "iGeomError.h" 00002 #include "iGeom.h" 00003 #include <string> 00004 #include <assert.h> 00005 00006 #define iBase_SUCCESS_DESC "No Error" 00007 00008 std::string lastErrorDesc = iBase_SUCCESS_DESC; 00009 iBase_ErrorType lastErrorType = iBase_SUCCESS; 00010 00011 #ifdef __cplusplus 00012 extern "C" { 00013 #endif 00014 00015 void CGM_iGeom_clearLastError() 00016 { 00017 if (lastErrorType != iBase_SUCCESS) { // don't copy string not needed 00018 lastErrorType = iBase_SUCCESS; 00019 lastErrorDesc = iBase_SUCCESS_DESC; 00020 } 00021 } 00022 00023 void CGM_iGeom_setLastError( int error_type, const char* description ) 00024 { 00025 // don't do string copies for non-errors 00026 if (error_type == iBase_SUCCESS && lastErrorType == iBase_SUCCESS) 00027 return; 00028 00029 lastErrorType = static_cast<iBase_ErrorType>(error_type); 00030 if (description) { 00031 lastErrorDesc = description; 00032 return; 00033 } 00034 00035 #define ERROR_DESC( A, B ) \ 00036 case iBase_ ## A : lastErrorDesc = B ; break; 00037 00038 switch (error_type) { 00039 ERROR_DESC( SUCCESS , iBase_SUCCESS_DESC ); 00040 ERROR_DESC( MESH_ALREADY_LOADED , "Mesh already loaded" ); 00041 ERROR_DESC( FILE_NOT_FOUND , "Could not read file" ); 00042 ERROR_DESC( FILE_WRITE_ERROR , "File write failed" ); 00043 ERROR_DESC( NIL_ARRAY , "NULL or empty array" ); 00044 ERROR_DESC( BAD_ARRAY_SIZE , "Invalid array size" ); 00045 ERROR_DESC( BAD_ARRAY_DIMENSION , "Invalid array dimension" ); 00046 ERROR_DESC( INVALID_ENTITY_HANDLE , "Invalid entity handle" ); 00047 ERROR_DESC( INVALID_ENTITY_COUNT , "Invalid entity count" ); 00048 ERROR_DESC( INVALID_ENTITY_TYPE , "Invalid entity type" ); 00049 ERROR_DESC( INVALID_ENTITY_TOPOLOGY , "Invalid entity topology" ); 00050 ERROR_DESC( BAD_TYPE_AND_TOPO , "Bad type and/or topology" ); 00051 ERROR_DESC( ENTITY_CREATION_ERROR , "Entity creation failed" ); 00052 ERROR_DESC( INVALID_TAG_HANDLE , "Invalid Tag" ); 00053 ERROR_DESC( TAG_NOT_FOUND , "Tag does not exist" ); 00054 ERROR_DESC( TAG_ALREADY_EXISTS , "Tag name conflict" ); 00055 ERROR_DESC( TAG_IN_USE , "Tag name conflict" ); 00056 ERROR_DESC( INVALID_ENTITYSET_HANDLE, "Invalid entity set handle" ); 00057 ERROR_DESC( INVALID_ITERATOR_HANDLE , "Invalid iterator handle" ); 00058 ERROR_DESC( INVALID_ARGUMENT , "Invalid argument" ); 00059 ERROR_DESC( MEMORY_ALLOCATION_FAILED, "Out of memory" ); 00060 ERROR_DESC( NOT_SUPPORTED , "Feature not supported" ); 00061 ERROR_DESC( FAILURE , "Unknown failure or internal error" ); 00062 default: 00063 assert(false); 00064 lastErrorDesc = "IVALID OR UNKNOWN ERROR CODE"; 00065 } 00066 } 00067 00068 int CGM_iGeom_getLastErrorType() 00069 { 00070 return lastErrorType; 00071 } 00072 00073 void CGM_iGeom_getLastErrorDesc(char* description_buffer, 00074 int description_buffer_length ) 00075 { 00076 if (description_buffer && description_buffer_length > 0) { 00077 lastErrorDesc.copy( description_buffer, description_buffer_length ); 00078 if (lastErrorDesc.length() < (unsigned)description_buffer_length) 00079 description_buffer[lastErrorDesc.length()] = '\0'; 00080 } 00081 } 00082 00083 #ifdef __cplusplus 00084 } // extern "C" 00085 #endif