src/ai/api/ai_error.cpp
branchnoai
changeset 9844 738b8f69675f
child 9849 edf90dda4ec4
equal deleted inserted replaced
9843:29f34a179daf 9844:738b8f69675f
       
     1 /* $Id$ */
       
     2 
       
     3 /** @file ai_error.cpp handles the commands-related functions of the AIError class */
       
     4 
       
     5 #include "ai_error.hpp"
       
     6 #include "table/strings.h"
       
     7 
       
     8 AIError::AIErrorMap AIError::error_map = AIError::AIErrorMap();
       
     9 AIError::AIErrorMapString AIError::error_map_string = AIError::AIErrorMapString();
       
    10 
       
    11 /* static */ uint AIError::GetLastError()
       
    12 {
       
    13 	if (AIObject::GetLastError() == STR_NULL) return ERR_NONE;
       
    14 
       
    15 	AIErrorMap::iterator it = error_map.find(AIObject::GetLastError());
       
    16 	if (it == error_map.end()) return ERR_UNKNOWN;
       
    17 	return (*it).second;
       
    18 }
       
    19 
       
    20 /* static */ const char *AIError::GetLastErrorString()
       
    21 {
       
    22 	if (AIObject::GetLastError() == STR_NULL) return strdup("ERR_NONE");
       
    23 
       
    24 	AIErrorMapString::iterator it = error_map_string.find(AIObject::GetLastError());
       
    25 	if (it == error_map_string.end()) return strdup("ERR_UNKNOWN");
       
    26 	return (*it).second;
       
    27 }
       
    28 
       
    29 /* static */ void AIError::RegisterErrorMap(uint internal_string_id, uint ai_error_msg)
       
    30 {
       
    31 	error_map[internal_string_id] = ai_error_msg;
       
    32 }
       
    33 
       
    34 /* static */ void AIError::RegisterErrorMapString(uint internal_string_id, const char *message)
       
    35 {
       
    36 	error_map_string[internal_string_id] = message;
       
    37 }
       
    38 
       
    39 /* static */ AIError::ErrorCategories AIError::GetErrorCategory() {
       
    40 	return (AIError::ErrorCategories)(GetLastError() >> (uint)ERR_CAT_BIT_SIZE);
       
    41 }