Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use pointers instead references.
[simgrid.git] / src / cxx / InvalidArgumentException.cxx
1 /*\r
2  * InvalidArgumentException.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  /* InvalidArgumentException member functions implementation.\r
14   */  \r
15 \r
16 \r
17 #include <InvalidArgumentException.hpp>\r
18 \r
19 #include <string.h>\r
20 #include <stdlib.h>\r
21 #include <stdio.h>\r
22 \r
23 namespace SimGrid\r
24 {\r
25         namespace Msg\r
26         {\r
27                 \r
28                         InvalidArgumentException::InvalidArgumentException()\r
29                         {\r
30                                 this->reason = (char*) calloc(strlen("Invalid argument : unknown") + 1, sizeof(char));\r
31                                 strcpy(this->reason, "Invalid argument : unknown");\r
32                         }\r
33                 \r
34                 \r
35                         InvalidArgumentException::InvalidArgumentException(const InvalidArgumentException& rInvalidArgumentException)\r
36                         {\r
37                                 const char* reason = rInvalidArgumentException.toString();\r
38                                 this->reason = (char*) calloc(strlen(reason) + 1, sizeof(char));\r
39                                 strcpy(this->reason, reason);\r
40                                 \r
41                         }\r
42                 \r
43                 \r
44                         InvalidArgumentException::InvalidArgumentException(const char* name)\r
45                         {\r
46                                 this->reason = (char*) calloc(strlen("Invalid argument : ") + strlen(name) + 1, sizeof(char));\r
47                                 sprintf(this->reason, "Invalid argument : %s", name);\r
48                         }\r
49                 \r
50                 \r
51                         InvalidArgumentException::~InvalidArgumentException()\r
52                         {\r
53                                 if(this->reason)\r
54                                         free(this->reason);\r
55                         }\r
56                                 \r
57                         const char* InvalidArgumentException::toString(void) const\r
58                         {\r
59                                 return (const char*)(this->reason);     \r
60                         }\r
61                 \r
62                 \r
63                         const InvalidArgumentException& InvalidArgumentException::operator = (const InvalidArgumentException& rInvalidArgumentException)\r
64                         {\r
65                                 const char* reason = rInvalidArgumentException.toString();\r
66                                 this->reason = (char*) calloc(strlen(reason) + 1, sizeof(char));\r
67                                 \r
68                                 return *this;\r
69                         }\r
70                 \r
71         } // namespace Msg      \r
72 \r
73 }// namespace SimGrid\r
74 \r
75 \r
76 \r