Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Some new files of the cxx version of the MSG API
[simgrid.git] / src / cxx / LogicException.cxx
diff --git a/src/cxx/LogicException.cxx b/src/cxx/LogicException.cxx
new file mode 100644 (file)
index 0000000..a7adcf2
--- /dev/null
@@ -0,0 +1,62 @@
+#include "LogicException.hpp"\r
+\r
+#include <string.h>\r
+#include <stdlib.h>\r
+#include <stdio.h>\r
+\r
+using namespace std;\r
+\r
+namespace SimGrid\r
+{\r
+       namespace Msg\r
+       {\r
+               \r
+                       LogicException::LogicException()\r
+                       {\r
+                               this->reason = (char*) calloc(strlen("Logic exception : no detail") + 1, sizeof(char));\r
+                               strcpy(this->reason, "Logic exception : no detail");\r
+                       }\r
+               \r
+               \r
+                       LogicException::LogicException(const LogicException& rLogicException)\r
+                       {\r
+                               const char* reason = rLogicException.toString();\r
+                               this->reason = (char*) calloc(strlen(reason) + 1, sizeof(char));\r
+                               strcpy(this->reason, reason);\r
+                               \r
+                       }\r
+               \r
+               \r
+                       LogicException::LogicException(const char* detail)\r
+                       {\r
+                               this->reason = (char*) calloc(strlen("Logic exception : ") + strlen(detail) + 1, sizeof(char));\r
+                               sprintf(this->reason, "Logic exception : %s", detail);\r
+                       }\r
+               \r
+               \r
+                       LogicException::~LogicException()\r
+                       {\r
+                               if(this->reason)\r
+                                       free(this->reason);\r
+                       }\r
+                               \r
+                       const char* LogicException::toString(void) const\r
+                       {\r
+                               return (const char*)(this->reason);     \r
+                       }\r
+               \r
+               \r
+                       const LogicException& LogicException::operator = (const LogicException& rLogicException)\r
+                       {\r
+                               const char* reason = rLogicException.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