|
|
@@ -19,14 +19,19 @@ Error_manager::Error_manager(const Error_manager & error_manager)
|
|
|
{
|
|
|
this->m_error_code = error_manager.m_error_code;
|
|
|
this->m_error_level = error_manager.m_error_level;
|
|
|
+ pm_error_description = NULL;
|
|
|
+ m_description_length = 0;
|
|
|
reallocate_memory_and_copy_string(error_manager.pm_error_description, error_manager.m_description_length);
|
|
|
return ;
|
|
|
}
|
|
|
//赋值构造
|
|
|
-Error_manager::Error_manager(Error_code error_code, Error_level error_level, char* p_error_description, int description_length)
|
|
|
+Error_manager::Error_manager(Error_code error_code, Error_level error_level,
|
|
|
+ char* p_error_description, int description_length)
|
|
|
{
|
|
|
m_error_code = error_code;
|
|
|
m_error_level = error_level;
|
|
|
+ pm_error_description = NULL;
|
|
|
+ m_description_length = 0;
|
|
|
reallocate_memory_and_copy_string(p_error_description, description_length);
|
|
|
return ;
|
|
|
}
|
|
|
@@ -35,6 +40,8 @@ Error_manager::Error_manager(Error_code error_code, Error_level error_level , st
|
|
|
{
|
|
|
m_error_code = error_code;
|
|
|
m_error_level = error_level;
|
|
|
+ pm_error_description = NULL;
|
|
|
+ m_description_length = 0;
|
|
|
reallocate_memory_and_copy_string(error_aggregate_string);
|
|
|
return ;
|
|
|
}
|
|
|
@@ -93,6 +100,52 @@ void Error_manager::error_manager_clear_all()
|
|
|
free_description();
|
|
|
}
|
|
|
|
|
|
+//重载=
|
|
|
+Error_manager& Error_manager::operator=(const Error_manager & error_manager)
|
|
|
+{
|
|
|
+ error_manager_reset(error_manager);
|
|
|
+}
|
|
|
+//重载=,支持Error_manager和Error_code的直接转化,会清空错误等级和描述
|
|
|
+Error_manager& Error_manager::operator=(Error_code error_code)
|
|
|
+{
|
|
|
+ error_manager_clear_all();
|
|
|
+ set_error_code(error_code);
|
|
|
+}
|
|
|
+//重载==
|
|
|
+bool Error_manager::operator==(const Error_manager & error_manager)
|
|
|
+{
|
|
|
+ is_equal_error_manager(error_manager);
|
|
|
+}
|
|
|
+//重载==,支持Error_manager和Error_code的直接比较
|
|
|
+bool Error_manager::operator==(Error_code error_code)
|
|
|
+{
|
|
|
+ if(m_error_code == error_code)
|
|
|
+ {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+//重载!=
|
|
|
+bool Error_manager::operator!=(const Error_manager & error_manager)
|
|
|
+{
|
|
|
+ ! is_equal_error_manager(error_manager);
|
|
|
+}
|
|
|
+//重载!=,支持Error_manager和Error_code的直接比较
|
|
|
+bool Error_manager::operator!=(Error_code error_code)
|
|
|
+{
|
|
|
+ if(m_error_code != error_code)
|
|
|
+ {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
//获取错误码
|
|
|
Error_code Error_manager::get_error_code()
|
|
|
@@ -326,7 +379,14 @@ void Error_manager::translate_error_to_string(std::string & error_aggregate_stri
|
|
|
sprintf(t_string_array, "error_code:0x%08x, error_level:%02d, error_description:", m_error_code , m_error_level );
|
|
|
|
|
|
error_aggregate_string = t_string_array ;
|
|
|
- error_aggregate_string += pm_error_description;
|
|
|
+ if(pm_error_description != NULL)
|
|
|
+ {
|
|
|
+ error_aggregate_string += pm_error_description;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ //error_aggregate_string += "NULL";
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
std::string Error_manager::to_string()
|
|
|
@@ -357,7 +417,7 @@ void Error_manager::reallocate_memory_and_copy_string(char* p_error_description,
|
|
|
if(p_error_description != NULL)
|
|
|
{
|
|
|
char* pt_source = p_error_description;
|
|
|
- char* pt_destination = pm_error_description;
|
|
|
+ char* pt_destination = NULL;
|
|
|
|
|
|
if(description_length == 0)
|
|
|
{
|
|
|
@@ -376,6 +436,7 @@ void Error_manager::reallocate_memory_and_copy_string(char* p_error_description,
|
|
|
}
|
|
|
|
|
|
pm_error_description = (char*) malloc(m_description_length );
|
|
|
+ pt_destination = pm_error_description;
|
|
|
|
|
|
for(int i=0;i<m_description_length; i++)
|
|
|
{
|