1 //****************************************************************************// 2 // error.cpp // 3 // Copyright (C) 2001, 2002 Bruno 'Beosil' Heidelberger // 4 //****************************************************************************// 5 // This library is free software; you can redistribute it and/or modify it // 6 // under the terms of the GNU Lesser General Public License as published by // 7 // the Free Software Foundation; either version 2.1 of the License, or (at // 8 // your option) any later version. // 9 //****************************************************************************// 10 11 #ifdef HAVE_CONFIG_H 12 #include "config.h" 13 #endif 14 15 #include "cal3d/error.h" 16 17 namespace 18 { 19 CalError::Code m_lastErrorCode = CalError::OK; 20 std::string m_strLastErrorFile; 21 int m_lastErrorLine = -1; 22 std::string m_strLastErrorText; 23 } 24 25 /*****************************************************************************/ 26 /** Returns the code of the last error. 27 * 28 * This function returns the code of the last error that occured inside the 29 * library. 30 * 31 * @return The code of the last error. 32 *****************************************************************************/ 33 getLastErrorCode()34CalError::Code CalError::getLastErrorCode() 35 { 36 return m_lastErrorCode; 37 } 38 39 /*****************************************************************************/ 40 /** Returns a description of the last error. 41 * 42 * This function returns a short description of the last error that occured 43 * inside the library. 44 * 45 * @return The description of the last error. 46 *****************************************************************************/ 47 getErrorDescription(Code code)48std::string CalError::getErrorDescription(Code code) 49 { 50 switch(code) 51 { 52 case OK: return "No error found"; 53 case INTERNAL: return "Internal error"; 54 case INVALID_HANDLE: return "Invalid handle as argument"; 55 case MEMORY_ALLOCATION_FAILED: return "Memory allocation failed"; 56 case FILE_NOT_FOUND: return "File not found"; 57 case INVALID_FILE_FORMAT: return "Invalid file format"; 58 case FILE_PARSER_FAILED: return "Parser failed to process file"; 59 case INDEX_BUILD_FAILED: return "Building of the index failed"; 60 case NO_PARSER_DOCUMENT: return "There is no document to parse"; 61 case INVALID_ANIMATION_DURATION: return "The duration of the animation is invalid"; 62 case BONE_NOT_FOUND: return "Bone not found"; 63 case INVALID_ATTRIBUTE_VALUE: return "Invalid attribute value"; 64 case INVALID_KEYFRAME_COUNT: return "Invalid number of keyframes"; 65 case INVALID_ANIMATION_TYPE: return "Invalid animation type"; 66 case FILE_CREATION_FAILED: return "Failed to create file"; 67 case FILE_WRITING_FAILED: return "Failed to write to file"; 68 case INCOMPATIBLE_FILE_VERSION: return "Incompatible file version"; 69 case NO_MESH_IN_MODEL: return "No mesh attached to the model"; 70 case BAD_DATA_SOURCE: return "Cannot read from data source"; 71 case NULL_BUFFER: return "Memory buffer is null"; 72 case INVALID_MIXER_TYPE: return "The CalModel mixer is not a CalMixer instance"; 73 default: return "Unknown error"; 74 } 75 } 76 77 /*****************************************************************************/ 78 /** Returns the name of the file where the last error occured. 79 * 80 * This function returns the name of the file where the last error occured. 81 * 82 * @return The name of the file where the last error occured. 83 *****************************************************************************/ 84 getLastErrorFile()85const std::string& CalError::getLastErrorFile() 86 { 87 return m_strLastErrorFile; 88 } 89 90 /*****************************************************************************/ 91 /** Returns the line number where the last error occured. 92 * 93 * This function returns the line number where the last error occured. 94 * 95 * @return The line number where the last error occured. 96 *****************************************************************************/ 97 getLastErrorLine()98int CalError::getLastErrorLine() 99 { 100 return m_lastErrorLine; 101 } 102 103 /*****************************************************************************/ 104 /** Returns the supplementary text of the last error. 105 * 106 * This function returns the suppementary text of the last error occured 107 * inside the library. 108 * 109 * @return The supplementary text of the last error. 110 *****************************************************************************/ 111 getLastErrorText()112const std::string& CalError::getLastErrorText() 113 { 114 return m_strLastErrorText; 115 } 116 117 /*****************************************************************************/ 118 /** Dumps all information about the last error to the standard output. 119 * 120 * This function dumps all the information about the last error that occured 121 * inside the library to the standard output. 122 *****************************************************************************/ 123 printLastError()124void CalError::printLastError() 125 { 126 std::cout << "cal3d : " << getLastErrorDescription(); 127 128 // only print supplementary information if there is some 129 if(m_strLastErrorText.size() > 0) 130 { 131 std::cout << " '" << m_strLastErrorText << "'"; 132 } 133 134 std::cout << " in " << m_strLastErrorFile << "(" << m_lastErrorLine << ")" << std::endl; 135 } 136 137 /*****************************************************************************/ 138 /** Sets all the information about the last error. 139 * 140 * This function sets all the information about the last error that occured 141 * inside the library. 142 * 143 * @param code The code of the last error. 144 * @param strFile The file where the last error occured. 145 * @param line The line number where the last error occured. 146 * @param strText The supplementary text of the last error. 147 *****************************************************************************/ 148 setLastError(Code code,const std::string & strFile,int line,const std::string & strText)149void CalError::setLastError(Code code, const std::string& strFile, int line, const std::string& strText) 150 { 151 if(code >= MAX_ERROR_CODE) code = INTERNAL; 152 153 m_lastErrorCode = code; 154 m_strLastErrorFile = strFile; 155 m_lastErrorLine = line; 156 m_strLastErrorText = strText; 157 } 158 159 //****************************************************************************// 160