Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Code refactoring
[simgrid.git] / src / cxx / BadAllocException.cxx
1 #include "BadAllocException.hpp"\r
2 \r
3 #include <string.h>\r
4 #include <stdlib.h>\r
5 #include <stdio.h>\r
6 \r
7 using namespace std;\r
8 \r
9 namespace SimGrid\r
10 {\r
11         namespace Msg\r
12         {\r
13                 \r
14                         BadAllocException::BadAllocException()\r
15                         {\r
16                                 this->reason = (char*) calloc(strlen("Not enough memory") + 1, sizeof(char));\r
17                                 strcpy(this->reason, "Not enough memory");\r
18                         }\r
19                 \r
20                 \r
21                         BadAllocException::BadAllocException(const BadAllocException& rBadAllocException)\r
22                         {\r
23                                 const char* reason = rBadAllocException.toString();\r
24                                 this->reason = (char*) calloc(strlen(reason) + 1, sizeof(char));\r
25                                 strcpy(this->reason, reason);\r
26                                 \r
27                         }\r
28                 \r
29                         BadAllocException::BadAllocException(const char* objectName)\r
30                         {\r
31                                 this->reason = (char*) calloc(strlen("Not enough memory to allocate ") + strlen(objectName) + 1, sizeof(char));\r
32                                 sprintf(this->reason, "Not enough memory to allocate %s", objectName);\r
33                         }\r
34                 \r
35                 \r
36                         BadAllocException::~BadAllocException()\r
37                         {\r
38                                 if(this->reason)\r
39                                         free(this->reason);\r
40                         }\r
41                                 \r
42                         const char* BadAllocException::toString(void) const\r
43                         {\r
44                                 return (const char*)(this->reason);     \r
45                         }\r
46                 \r
47                 \r
48                         const BadAllocException& BadAllocException::operator = (const BadAllocException& rBadAllocException)\r
49                         {\r
50                                 const char* reason = rBadAllocException.toString();\r
51                                 this->reason = (char*) calloc(strlen(reason) + 1, sizeof(char));\r
52                                 \r
53                                 return *this;\r
54                         }\r
55                 \r
56         } // namespace Msg      \r
57 \r
58 }// namespace SimGrid\r
59 \r
60 \r
61 \r