Logo AND Algorithmique Numérique Distribuée

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