Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use pointers instead references.
[simgrid.git] / src / cxx / MsgException.cxx
1 /*\r
2  * MsgException.cxx\r
3  *\r
4  * Copyright 2006,2007 Martin Quinson, Malek Cherier           \r
5  * All right reserved. \r
6  *\r
7  * This program is free software; you can redistribute \r
8  * it and/or modify it under the terms of the license \r
9  *(GNU LGPL) which comes with this package. \r
10  *\r
11  */\r
12  \r
13  /* MsgException member functions implementation.\r
14   */  \r
15 \r
16 #include <MsgException.hpp>\r
17 \r
18 #include <string.h>\r
19 #include <stdlib.h>\r
20 #include <stdio.h>\r
21 \r
22 namespace SimGrid\r
23 {\r
24         namespace Msg\r
25         {\r
26                 \r
27                         MsgException::MsgException()\r
28                         {\r
29                                 this->reason = (char*) calloc(strlen("Internal exception : unknown reason") + 1, sizeof(char));\r
30                                 strcpy(this->reason, "Internal exception : unknown reason");\r
31                         }\r
32                 \r
33                 \r
34                         MsgException::MsgException(const MsgException& rMsgException)\r
35                         {\r
36                                 const char* reason = rMsgException.toString();\r
37                                 this->reason = (char*) calloc(strlen(reason) + 1, sizeof(char));\r
38                                 strcpy(this->reason, reason);\r
39                                 \r
40                         }\r
41                 \r
42                         MsgException::MsgException(const char* reason)\r
43                         {\r
44                                 this->reason = (char*) calloc(strlen("Internal exception : ") + strlen(reason) + 1, sizeof(char));\r
45                                 sprintf(this->reason, "Invalid exception : %s", reason);\r
46                         }\r
47                 \r
48                 \r
49                         MsgException::~MsgException()\r
50                         {\r
51                                 if(this->reason)\r
52                                         free(this->reason);\r
53                         }\r
54                                 \r
55                         const char* MsgException::toString(void) const\r
56                         {\r
57                                 return (const char*)(this->reason);     \r
58                         }\r
59                 \r
60                 \r
61                         const MsgException& MsgException::operator = (const MsgException& rMsgException)\r
62                         {\r
63                                 const char* reason = rMsgException.toString();\r
64                                 this->reason = (char*) calloc(strlen(reason) + 1, sizeof(char));\r
65                                 \r
66                                 return *this;\r
67                         }\r
68                 \r
69         } // namespace Msg      \r
70 \r
71 }// namespace SimGrid\r
72 \r
73 \r
74 \r