Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add comment and exception mechanism to the Host class.
[simgrid.git] / src / cxx / MsgException.cxx
1 #include "MsgException.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                         MsgException::MsgException()\r
15                         {\r
16                                 this->reason = (char*) calloc(strlen("Internal exception : unknown reason") + 1, sizeof(char));\r
17                                 strcpy(this->reason, "Internal exception : unknown reason");\r
18                         }\r
19                 \r
20                 \r
21                         MsgException::MsgException(const MsgException& rMsgException)\r
22                         {\r
23                                 const char* reason = rMsgException.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                         MsgException::MsgException(const char* reason)\r
30                         {\r
31                                 this->reason = (char*) calloc(strlen("Internal exception : ") + strlen(reason) + 1, sizeof(char));\r
32                                 sprintf(this->reason, "Invalid exception : %s", reason);\r
33                         }\r
34                 \r
35                 \r
36                         MsgException::~MsgException()\r
37                         {\r
38                                 if(this->reason)\r
39                                         free(this->reason);\r
40                         }\r
41                                 \r
42                         const char* MsgException::toString(void) const\r
43                         {\r
44                                 return (const char*)(this->reason);     \r
45                         }\r
46                 \r
47                 \r
48                         const MsgException& MsgException::operator = (const MsgException& rMsgException)\r
49                         {\r
50                                 const char* reason = rMsgException.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