Logo AND Algorithmique Numérique Distribuée

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