Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Some new classes of CPP version of Msg
[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 namespace SimGrid\r
8 {\r
9         namespace Msg\r
10         {\r
11                 \r
12                         BadAllocException::BadAllocException()\r
13                         {\r
14                                 this->reason = (char*) calloc(strlen("Not enough memory") + 1, sizeof(char));\r
15                                 strcpy(this->reason, "Not enough memory");\r
16                         }\r
17                 \r
18                 \r
19                         BadAllocException::BadAllocException(const BadAllocException& rBadAllocException)\r
20                         {\r
21                                 const char* reason = rBadAllocException.toString();\r
22                                 this->reason = (char*) calloc(strlen(reason) + 1, sizeof(char));\r
23                                 strcpy(this->reason, reason);\r
24                                 \r
25                         }\r
26                 \r
27                         BadAllocException::BadAllocException(const char* objectName)\r
28                         {\r
29                                 this->reason = (char*) calloc(strlen("Not enough memory to allocate ") + strlen(objectName) + 1, sizeof(char));\r
30                                 sprintf(this->reason, "Not enough memory to allocate %s", objectName);\r
31                         }\r
32                 \r
33                 \r
34                         BadAllocException::~BadAllocException()\r
35                         {\r
36                                 if(this->reason)\r
37                                         free(this->reason);\r
38                         }\r
39                                 \r
40                         const char* BadAllocException::toString(void) const\r
41                         {\r
42                                 return (const char*)(this->reason);     \r
43                         }\r
44                 \r
45                 \r
46                         const BadAllocException& BadAllocException::operator = (const BadAllocException& rBadAllocException)\r
47                         {\r
48                                 const char* reason = rBadAllocException.toString();\r
49                                 this->reason = (char*) calloc(strlen(reason) + 1, sizeof(char));\r
50                                 \r
51                                 return *this;\r
52                         }\r
53                 \r
54         } // namespace Msg      \r
55 \r
56 }// namespace SimGrid\r
57 \r
58 \r
59 \r