Logo AND Algorithmique Numérique Distribuée

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