Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Some new classes of CPP version of Msg
[simgrid.git] / src / cxx / NullPointerException.cxx
diff --git a/src/cxx/NullPointerException.cxx b/src/cxx/NullPointerException.cxx
new file mode 100644 (file)
index 0000000..e672c66
--- /dev/null
@@ -0,0 +1,60 @@
+#include <NullPointerException.hpp>\r
+\r
+#include <string.h>\r
+#include <stdlib.h>\r
+#include <stdio.h>\r
+\r
+namespace SimGrid\r
+{\r
+       namespace Msg\r
+       {\r
+               \r
+                       NullPointerException::NullPointerException()\r
+                       {\r
+                               this->reason = (char*) calloc(strlen("Null pointer : unknown") + 1, sizeof(char));\r
+                               strcpy(this->reason, "Null pointer : unknown");\r
+                       }\r
+               \r
+               \r
+                       NullPointerException::NullPointerException(const NullPointerException& rNullPointerException)\r
+                       {\r
+                               const char* reason = rNullPointerException.toString();\r
+                               this->reason = (char*) calloc(strlen(reason) + 1, sizeof(char));\r
+                               strcpy(this->reason, reason);\r
+                               \r
+                       }\r
+               \r
+               \r
+                       NullPointerException::NullPointerException(const char* name)\r
+                       {\r
+                               this->reason = (char*) calloc(strlen("Null pointer : ") + strlen(name) + 1, sizeof(char));\r
+                               sprintf(this->reason, "Null pointer : %s", name);\r
+                       }\r
+               \r
+               \r
+                       NullPointerException::~NullPointerException()\r
+                       {\r
+                               if(this->reason)\r
+                                       free(this->reason);\r
+                       }\r
+                               \r
+                       const char* NullPointerException::toString(void) const\r
+                       {\r
+                               return (const char*)(this->reason);     \r
+                       }\r
+               \r
+               \r
+                       const NullPointerException& NullPointerException::operator = (const NullPointerException& rNullPointerException)\r
+                       {\r
+                               const char* reason = rNullPointerException.toString();\r
+                               this->reason = (char*) calloc(strlen(reason) + 1, sizeof(char));\r
+                               \r
+                               return *this;\r
+                       }\r
+               \r
+       } // namespace Msg      \r
+\r
+}// namespace SimGrid\r
+\r
+\r
+\r