Branch data Line data Source code
1 : : #include "iGeomError.h"
2 : : #include "iGeom.h"
3 : : #include <string>
4 : : #include <assert.h>
5 : :
6 : : #define iBase_SUCCESS_DESC "No Error"
7 : :
8 [ + - ]: 4 : std::string lastErrorDesc = iBase_SUCCESS_DESC;
9 : : iBase_ErrorType lastErrorType = iBase_SUCCESS;
10 : :
11 : : #ifdef __cplusplus
12 : : extern "C" {
13 : : #endif
14 : :
15 : 26 : void CGM_iGeom_clearLastError()
16 : : {
17 [ + + ]: 26 : if (lastErrorType != iBase_SUCCESS) { // don't copy string not needed
18 : 2 : lastErrorType = iBase_SUCCESS;
19 : 2 : lastErrorDesc = iBase_SUCCESS_DESC;
20 : : }
21 : 26 : }
22 : :
23 : 8065 : void CGM_iGeom_setLastError( int error_type, const char* description )
24 : : {
25 : : // don't do string copies for non-errors
26 [ + + ][ + + ]: 8065 : if (error_type == iBase_SUCCESS && lastErrorType == iBase_SUCCESS)
27 : 8042 : return;
28 : :
29 : 23 : lastErrorType = static_cast<iBase_ErrorType>(error_type);
30 [ + + ]: 23 : if (description) {
31 : 1 : lastErrorDesc = description;
32 : 1 : return;
33 : : }
34 : :
35 : : #define ERROR_DESC( A, B ) \
36 : : case iBase_ ## A : lastErrorDesc = B ; break;
37 : :
38 [ + - - - : 22 : switch (error_type) {
- - - - -
+ - - - -
+ - - - -
- - - -
- ]
39 : 5 : ERROR_DESC( SUCCESS , iBase_SUCCESS_DESC );
40 : 0 : ERROR_DESC( MESH_ALREADY_LOADED , "Mesh already loaded" );
41 : 0 : ERROR_DESC( FILE_NOT_FOUND , "Could not read file" );
42 : 0 : ERROR_DESC( FILE_WRITE_ERROR , "File write failed" );
43 : 0 : ERROR_DESC( NIL_ARRAY , "NULL or empty array" );
44 : 0 : ERROR_DESC( BAD_ARRAY_SIZE , "Invalid array size" );
45 : 0 : ERROR_DESC( BAD_ARRAY_DIMENSION , "Invalid array dimension" );
46 : 0 : ERROR_DESC( INVALID_ENTITY_HANDLE , "Invalid entity handle" );
47 : 0 : ERROR_DESC( INVALID_ENTITY_COUNT , "Invalid entity count" );
48 : 9 : ERROR_DESC( INVALID_ENTITY_TYPE , "Invalid entity type" );
49 : 0 : ERROR_DESC( INVALID_ENTITY_TOPOLOGY , "Invalid entity topology" );
50 : 0 : ERROR_DESC( BAD_TYPE_AND_TOPO , "Bad type and/or topology" );
51 : 0 : ERROR_DESC( ENTITY_CREATION_ERROR , "Entity creation failed" );
52 : 0 : ERROR_DESC( INVALID_TAG_HANDLE , "Invalid Tag" );
53 : 8 : ERROR_DESC( TAG_NOT_FOUND , "Tag does not exist" );
54 : 0 : ERROR_DESC( TAG_ALREADY_EXISTS , "Tag name conflict" );
55 : 0 : ERROR_DESC( TAG_IN_USE , "Tag name conflict" );
56 : 0 : ERROR_DESC( INVALID_ENTITYSET_HANDLE, "Invalid entity set handle" );
57 : 0 : ERROR_DESC( INVALID_ITERATOR_HANDLE , "Invalid iterator handle" );
58 : 0 : ERROR_DESC( INVALID_ARGUMENT , "Invalid argument" );
59 : 0 : ERROR_DESC( MEMORY_ALLOCATION_FAILED, "Out of memory" );
60 : 0 : ERROR_DESC( NOT_SUPPORTED , "Feature not supported" );
61 : 0 : ERROR_DESC( FAILURE , "Unknown failure or internal error" );
62 : : default:
63 : 0 : assert(false);
64 : : lastErrorDesc = "IVALID OR UNKNOWN ERROR CODE";
65 : : }
66 : : }
67 : :
68 : 12 : int CGM_iGeom_getLastErrorType()
69 : : {
70 : 12 : return lastErrorType;
71 : : }
72 : :
73 : 2 : void CGM_iGeom_getLastErrorDesc(char* description_buffer,
74 : : int description_buffer_length )
75 : : {
76 [ + - ][ + - ]: 2 : if (description_buffer && description_buffer_length > 0) {
77 : 2 : lastErrorDesc.copy( description_buffer, description_buffer_length );
78 [ + - ]: 2 : if (lastErrorDesc.length() < (unsigned)description_buffer_length)
79 : 2 : description_buffer[lastErrorDesc.length()] = '\0';
80 : : }
81 : 2 : }
82 : :
83 : : #ifdef __cplusplus
84 [ + - ][ + - ]: 16 : } // extern "C"
85 : : #endif
|