Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add a class of exception for file not found and Msg files containing the declarations...
authorcherierm <cherierm@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Wed, 21 May 2008 15:11:19 +0000 (15:11 +0000)
committercherierm <cherierm@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Wed, 21 May 2008 15:11:19 +0000 (15:11 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@5487 48e7efb5-ca39-0410-a469-dd3cf9ba447f

src/cxx/FileNotFoundException.cxx [new file with mode: 0644]
src/cxx/FileNotFoundException.hpp [new file with mode: 0644]
src/cxx/Msg.cxx [new file with mode: 0644]
src/cxx/Msg.hpp [new file with mode: 0644]

diff --git a/src/cxx/FileNotFoundException.cxx b/src/cxx/FileNotFoundException.cxx
new file mode 100644 (file)
index 0000000..713c153
--- /dev/null
@@ -0,0 +1,61 @@
+#include <FileNotFoundException.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
+                       FileNotFoundException::FileNotFoundException()\r
+                       {\r
+                               this->reason = (char*) calloc(strlen("File not found") + 1, sizeof(char));\r
+                               strcpy(this->reason, "File not found");\r
+                       }\r
+               \r
+               \r
+                       FileNotFoundException::FileNotFoundException(const FileNotFoundException& rFileNotFoundException)\r
+                       {\r
+                               const char* reason = rFileNotFoundException.toString();\r
+                               this->reason = (char*) calloc(strlen(reason) + 1, sizeof(char));\r
+                               strcpy(this->reason, reason);\r
+                               \r
+                       }\r
+               \r
+                       FileNotFoundException::FileNotFoundException(const char* file)\r
+                       {\r
+                               this->reason = (char*) calloc(strlen("File not found ") + strlen(file) + 1, sizeof(char));\r
+                               sprintf(this->reason, "File not found %s", file);\r
+                       }\r
+               \r
+               \r
+                       FileNotFoundException::~FileNotFoundException()\r
+                       {\r
+                               if(this->reason)\r
+                                       free(this->reason);\r
+                       }\r
+                               \r
+                       const char* FileNotFoundException::toString(void) const\r
+                       {\r
+                               return (const char*)(this->reason);     \r
+                       }\r
+               \r
+               \r
+                       const FileNotFoundException& FileNotFoundException::operator = (const FileNotFoundException& rFileNotFoundException)\r
+                       {\r
+                               const char* reason = rFileNotFoundException.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
diff --git a/src/cxx/FileNotFoundException.hpp b/src/cxx/FileNotFoundException.hpp
new file mode 100644 (file)
index 0000000..398f153
--- /dev/null
@@ -0,0 +1,64 @@
+/*\r
+ * FileNotFoundException.hpp\r
+ *\r
+ * Copyright 2006,2007 Martin Quinson, Malek Cherier           \r
+ * All right reserved. \r
+ *\r
+ * This program is free software; you can redistribute \r
+ * it and/or modify it under the terms of the license \r
+ *(GNU LGPL) which comes with this package. \r
+ *\r
+ */  \r
\r
+#ifndef MSG_FILENOTFOUND_HPP\r
+#define MSG_FILENOTFOUND_HPP\r
+\r
+#include <Exception.hp>\r
+\r
+namespace SimGrid\r
+{\r
+       namespace Msg\r
+       {\r
+               \r
+               class FileNotFoundException : public Exception\r
+               {\r
+                       public:\r
+                       \r
+                       // Default constructor.\r
+                               FileNotFoundException();\r
+                       \r
+                       // Copy constructor.\r
+                               FileNotFoundException(const FileNotFoundException& rFileNotFoundException);\r
+                       \r
+                       // This constructor takes the name of the file.\r
+                               FileNotFoundException(const char* file);\r
+                       \r
+                       // Destructor.\r
+                               virtual ~FileNotFoundException();\r
+                               \r
+                       // Operations.\r
+                                       \r
+                                       // Returns the reason of the exception :\r
+                                       // the message "File not found : `object name'"\r
+                                       const char* toString(void) const;\r
+                       \r
+                       // Operators.\r
+                               \r
+                               // Assignement.\r
+                               const FileNotFoundException& operator = (const FileNotFoundException& rFileNotFoundException);\r
+                               \r
+                       private :\r
+                       \r
+                       // Attributes.\r
+                               \r
+                               // A buffer used to build the message returned by the methode toString().\r
+                               char* reason;\r
+               };\r
+               \r
+               \r
+       } // namespace Msg      \r
+\r
+}// namespace SimGrid\r
+\r
+\r
+#endif // !MSG_MSGEXCEPTION_HPP\r
diff --git a/src/cxx/Msg.cxx b/src/cxx/Msg.cxx
new file mode 100644 (file)
index 0000000..94c7e81
--- /dev/null
@@ -0,0 +1,43 @@
+\r
+/*\r
+ * Msg.cxx\r
+ *\r
+ * Copyright 2006,2007 Martin Quinson, Malek Cherier           \r
+ * All right reserved. \r
+ *\r
+ * This program is free software; you can redistribute \r
+ * it and/or modify it under the terms of the license \r
+ *(GNU LGPL) which comes with this package. \r
+ *\r
+ */\r
\r
+ /* Msg functions implementation.\r
+  */  \r
+#include <Msg.hpp>\r
+\r
+namespace SimGrid\r
+{\r
+       namespace Msg\r
+       {\r
+               \r
+               void init(int argc, char** argv)\r
+               {\r
+                       MSG_global_init(&argc,argv);\r
+                       MSG_set_channel_number(10); // FIXME: this should not be fixed statically \r
+               }       \r
+               \r
+               void finalize(void)\r
+               throw (MsgException)\r
+               {\r
+                       if(MSG_OK != MSG_clean())\r
+                               throw MsgException("MSG_clean() failed");\r
+               }\r
+               \r
+               void info(const char* s)\r
+               {\r
+                        INFO1("%s",s);\r
+               }\r
+\r
+       } // namespace Msg\r
+\r
+} // namespace SimGrid
\ No newline at end of file
diff --git a/src/cxx/Msg.hpp b/src/cxx/Msg.hpp
new file mode 100644 (file)
index 0000000..6125156
--- /dev/null
@@ -0,0 +1,56 @@
+/*\r
+ * Msg.hpp\r
+ *\r
+ * This file contains the declaration of the wrapper class of the native MSG task type.\r
+ *\r
+ * Copyright 2006,2007 Martin Quinson, Malek Cherier           \r
+ * All right reserved. \r
+ *\r
+ * This program is free software; you can redistribute \r
+ * it and/or modify it under the terms of the license \r
+ *(GNU LGPL) which comes with this package. \r
+ *\r
+ */  \r
\r
+#ifndef MSG_HPP\r
+#define MSG_HPP\r
+\r
+// Compilation C++ recquise\r
+#ifndef __cplusplus\r
+       #error Msg.hpp requires C++ compilation (use a .cxx suffix)\r
+#endif\r
+\r
+#include <MsgException.hpp>\r
+\r
+namespace SimGrid\r
+{\r
+       namespace Msg\r
+       {\r
+               \r
+               /*! \brief init() - Initialize MSG (This function must be called at the begining of each simulation).\r
+                *\r
+                * \param argv                  A list of arguments.\r
+                * \param argc                  The number of arguments of the list.\r
+                */\r
+               static void init(int argc, char** argv);\r
+               \r
+               /* \brief finalize() - Finalize MSG (This function must be called at the end of each simulation).\r
+                *\r
+                * \exception                   If this function fails, it throws a exception describing the cause of the failure.\r
+                */\r
+               static void finalize(void)\r
+               throw (MsgException);\r
+               \r
+               /*! \brief info() - Display information (using xbt log format).\r
+                *\r
+                * \param s                             The information to display.\r
+                */\r
+               static void info(const char* s);\r
+               \r
+               \r
+               \r
+               \r
+       } // namespace Msg\r
+} // namespace SimGrid\r
+\r
+#endif // !MSG_HPP
\ No newline at end of file