Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
The default alias name is now build from the name of the host of the process and...
[simgrid.git] / src / cxx / OutOfBoundsException.cxx
1 /*\r
2  * OutOfBoundsException.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  /* OutOfBoundsException member functions implementation.\r
14   */  \r
15 \r
16 #include <OutOfBoundsException.hpp>\r
17 \r
18 #include <string.h>\r
19 #include <stdlib.h>\r
20 #include <stdio.h>\r
21 \r
22 \r
23 namespace SimGrid\r
24 {\r
25         namespace Msg\r
26         {\r
27                 \r
28                         OutOfBoundsException::OutOfBoundsException()\r
29                         {\r
30                                 this->reason = (char*) calloc(strlen("Out of bounds") + 1, sizeof(char));\r
31                                 strcpy(this->reason, "Out of bounds");\r
32                         }\r
33                 \r
34                 \r
35                         OutOfBoundsException::OutOfBoundsException(const OutOfBoundsException& rOutOfBoundsException)\r
36                         {\r
37                                 const char* reason = rOutOfBoundsException.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                         OutOfBoundsException::OutOfBoundsException(int pos)\r
44                         {\r
45                                 this->reason = (char*) calloc(strlen("Out of bounds ") + 21 + 1, sizeof(char));\r
46                                 sprintf(this->reason, "Out of bounds %d", pos);\r
47                         }\r
48 \r
49                         OutOfBoundsException::OutOfBoundsException(int pos1, int pos2)\r
50                         {\r
51                                 this->reason = (char*) calloc(strlen("Out of bounds ") + (2*21) + 1, sizeof(char));\r
52                                 sprintf(this->reason, "Out of bounds %d : %d", pos1, pos2);\r
53                         }\r
54                 \r
55                 \r
56                         OutOfBoundsException::~OutOfBoundsException()\r
57                         {\r
58                                 if(this->reason)\r
59                                         free(this->reason);\r
60                         }\r
61                                 \r
62                         const char* OutOfBoundsException::toString(void) const\r
63                         {\r
64                                 return (const char*)(this->reason);     \r
65                         }\r
66                 \r
67                 \r
68                         const OutOfBoundsException& OutOfBoundsException::operator = (const OutOfBoundsException& rOutOfBoundsException)\r
69                         {\r
70                                 const char* reason = rOutOfBoundsException.toString();\r
71                                 this->reason = (char*) calloc(strlen(reason) + 1, sizeof(char));\r
72                                 \r
73                                 return *this;\r
74                         }\r
75                 \r
76         } // namespace Msg      \r
77 \r
78 }// namespace SimGrid\r
79 \r
80 \r
81 \r