From: cherierm Date: Wed, 21 May 2008 15:11:19 +0000 (+0000) Subject: Add a class of exception for file not found and Msg files containing the declarations... X-Git-Tag: v3.3~449 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/8b9f1461e3444561c67dbf0b688d69172b1a8d31?hp=d5ee9e974615a1c7f82bf9f86c5c71e00b8e61f4;ds=sidebyside Add a class of exception for file not found and Msg files containing the declarations and implementation of the function connected to MSG. git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@5487 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- diff --git a/src/cxx/FileNotFoundException.cxx b/src/cxx/FileNotFoundException.cxx new file mode 100644 index 0000000000..713c153ebc --- /dev/null +++ b/src/cxx/FileNotFoundException.cxx @@ -0,0 +1,61 @@ +#include + +#include +#include +#include + +using namespace std; + +namespace SimGrid +{ + namespace Msg + { + + FileNotFoundException::FileNotFoundException() + { + this->reason = (char*) calloc(strlen("File not found") + 1, sizeof(char)); + strcpy(this->reason, "File not found"); + } + + + FileNotFoundException::FileNotFoundException(const FileNotFoundException& rFileNotFoundException) + { + const char* reason = rFileNotFoundException.toString(); + this->reason = (char*) calloc(strlen(reason) + 1, sizeof(char)); + strcpy(this->reason, reason); + + } + + FileNotFoundException::FileNotFoundException(const char* file) + { + this->reason = (char*) calloc(strlen("File not found ") + strlen(file) + 1, sizeof(char)); + sprintf(this->reason, "File not found %s", file); + } + + + FileNotFoundException::~FileNotFoundException() + { + if(this->reason) + free(this->reason); + } + + const char* FileNotFoundException::toString(void) const + { + return (const char*)(this->reason); + } + + + const FileNotFoundException& FileNotFoundException::operator = (const FileNotFoundException& rFileNotFoundException) + { + const char* reason = rFileNotFoundException.toString(); + this->reason = (char*) calloc(strlen(reason) + 1, sizeof(char)); + + return *this; + } + + } // namespace Msg + +}// namespace SimGrid + + + diff --git a/src/cxx/FileNotFoundException.hpp b/src/cxx/FileNotFoundException.hpp new file mode 100644 index 0000000000..398f1536e9 --- /dev/null +++ b/src/cxx/FileNotFoundException.hpp @@ -0,0 +1,64 @@ +/* + * FileNotFoundException.hpp + * + * Copyright 2006,2007 Martin Quinson, Malek Cherier + * All right reserved. + * + * This program is free software; you can redistribute + * it and/or modify it under the terms of the license + *(GNU LGPL) which comes with this package. + * + */ + +#ifndef MSG_FILENOTFOUND_HPP +#define MSG_FILENOTFOUND_HPP + +#include + +namespace SimGrid +{ + namespace Msg + { + + class FileNotFoundException : public Exception + { + public: + + // Default constructor. + FileNotFoundException(); + + // Copy constructor. + FileNotFoundException(const FileNotFoundException& rFileNotFoundException); + + // This constructor takes the name of the file. + FileNotFoundException(const char* file); + + // Destructor. + virtual ~FileNotFoundException(); + + // Operations. + + // Returns the reason of the exception : + // the message "File not found : `object name'" + const char* toString(void) const; + + // Operators. + + // Assignement. + const FileNotFoundException& operator = (const FileNotFoundException& rFileNotFoundException); + + private : + + // Attributes. + + // A buffer used to build the message returned by the methode toString(). + char* reason; + }; + + + } // namespace Msg + +}// namespace SimGrid + + +#endif // !MSG_MSGEXCEPTION_HPP diff --git a/src/cxx/Msg.cxx b/src/cxx/Msg.cxx new file mode 100644 index 0000000000..94c7e8120e --- /dev/null +++ b/src/cxx/Msg.cxx @@ -0,0 +1,43 @@ + +/* + * Msg.cxx + * + * Copyright 2006,2007 Martin Quinson, Malek Cherier + * All right reserved. + * + * This program is free software; you can redistribute + * it and/or modify it under the terms of the license + *(GNU LGPL) which comes with this package. + * + */ + + /* Msg functions implementation. + */ +#include + +namespace SimGrid +{ + namespace Msg + { + + void init(int argc, char** argv) + { + MSG_global_init(&argc,argv); + MSG_set_channel_number(10); // FIXME: this should not be fixed statically + } + + void finalize(void) + throw (MsgException) + { + if(MSG_OK != MSG_clean()) + throw MsgException("MSG_clean() failed"); + } + + void info(const char* s) + { + INFO1("%s",s); + } + + } // namespace Msg + +} // namespace SimGrid \ No newline at end of file diff --git a/src/cxx/Msg.hpp b/src/cxx/Msg.hpp new file mode 100644 index 0000000000..61251569c1 --- /dev/null +++ b/src/cxx/Msg.hpp @@ -0,0 +1,56 @@ +/* + * Msg.hpp + * + * This file contains the declaration of the wrapper class of the native MSG task type. + * + * Copyright 2006,2007 Martin Quinson, Malek Cherier + * All right reserved. + * + * This program is free software; you can redistribute + * it and/or modify it under the terms of the license + *(GNU LGPL) which comes with this package. + * + */ + +#ifndef MSG_HPP +#define MSG_HPP + +// Compilation C++ recquise +#ifndef __cplusplus + #error Msg.hpp requires C++ compilation (use a .cxx suffix) +#endif + +#include + +namespace SimGrid +{ + namespace Msg + { + + /*! \brief init() - Initialize MSG (This function must be called at the begining of each simulation). + * + * \param argv A list of arguments. + * \param argc The number of arguments of the list. + */ + static void init(int argc, char** argv); + + /* \brief finalize() - Finalize MSG (This function must be called at the end of each simulation). + * + * \exception If this function fails, it throws a exception describing the cause of the failure. + */ + static void finalize(void) + throw (MsgException); + + /*! \brief info() - Display information (using xbt log format). + * + * \param s The information to display. + */ + static void info(const char* s); + + + + + } // namespace Msg +} // namespace SimGrid + +#endif // !MSG_HPP \ No newline at end of file