-/*\r
- * Environment.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
- /* Environment member functions implementation.\r
- */ \r
- \r
-#include <Environment.hpp>\r
-\r
-#include <sys/types.h>\r
-#include <sys/stat.h>\r
-\r
-#ifndef S_ISREG\r
- #define S_ISREG(__mode) (((__mode) & S_IFMT) == S_IFREG)\r
-#endif\r
-\r
-namespace SimGrid\r
-{\r
- namespace Msg\r
- {\r
- Environment::Environment()\r
- {\r
- this->file = NULL;\r
- this->loaded = false;\r
- }\r
- \r
- Environment::Environment(const Environment& rEnvironment);\r
- {\r
- this->file = rEnvironment.getFile();\r
- this->loaded = rEnvironment.isLoaded();\r
- }\r
- \r
- Environment::Environment(const char* file)\r
- throw(NullPointerException, InvalidArgumentException);\r
- {\r
- // check parameters\r
- \r
- if(!file)\r
- throw NullPointerException("file (must not be NULL");\r
- \r
- struct stat statBuf = {0};\r
- \r
- if(stat(statBuff, &info) < 0 || !S_ISREG(statBuff.st_mode))\r
- throw InvalidParameterException("file (file not found)");\r
- \r
- this->file = file;\r
- this->loaded = false;\r
- }\r
- \r
- Environment::~Environment()\r
- {\r
- // NOTHING TODO\r
- }\r
- \r
- // Operations.\r
- \r
- void Environment::load(void)\r
- throw(LogicException)\r
- {\r
- // check logic\r
- \r
- if(this->loaded)\r
- throw LogicException("environement already loaded");\r
- \r
- // check the parameters\r
- if(!this->file)\r
- throw LogicException("you must specify the xml file which describe the environment to load\nuse Environment::setFile()"); \r
- \r
- MSG_create_environment(file);\r
- \r
- this->loaded = true; \r
- }\r
- \r
- void Environment::load(const char* file)\r
- throw(NullPointerException, FileNotFoundException, LogicException)\r
- {\r
- // check logic\r
- \r
- if(this->loaded)\r
- throw LogicException("environment already loaded");\r
- \r
- // check the parameters\r
- \r
- if(!file)\r
- throw NullPointerException("file");\r
- \r
- struct stat statBuf = {0};\r
- \r
- if(stat(statBuff, &info) < 0 || !S_ISREG(statBuff.st_mode))\r
- throw FileNotFoundException(file);\r
- \r
- MSG_create_environment(file);\r
- \r
- this->file = file;\r
- this->loaded = true; \r
- }\r
- \r
- bool Environment::isLoaded(void) const\r
- {\r
- return this->loaded;\r
- }\r
- \r
- // Getters/setters\r
- void Environment::setFile(const char* file)\r
- throw(NullPointerException, FileNotFoundException, LogicException)\r
- {\r
- // check logic\r
- \r
- if(this->loaded)\r
- throw LogicException("your are trying to change the file of an already loaded environment");\r
- \r
- // check parameters\r
- \r
- if(!file)\r
- throw NullPointerException("file (must not be NULL");\r
- \r
- struct stat statBuf = {0};\r
- \r
- if(stat(statBuff, &info) < 0 || !S_ISREG(statBuff.st_mode))\r
- throw FileNotFoundException("file (file not found)");\r
- \r
- this->file = file;\r
- }\r
- \r
- const char* Environment::getFile(void) const\r
- {\r
- return this->file;\r
- }\r
- \r
- \r
- const Environment& Environment::operator = (const Environment& rEnvironment)\r
- throw(LogicException)\r
- {\r
- // check logic\r
- \r
- if(this->loaded)\r
- throw LogicException("environment already loaded");\r
- \r
- this->file = rEnvironment.getFile();\r
- this->loaded = rEnvironment.isLoaded();\r
- \r
- return *this;\r
- }\r
- \r
- } // namespace Msg\r
-} // namespace SimGrid
\ No newline at end of file
+/*
+ * Environment.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.
+ *
+ */
+
+ /* Environment member functions implementation.
+ */
+
+#include <Environment.hpp>
+
+#include <stdlib.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <msg/msg.h>
+
+#ifndef S_ISREG
+ #define S_ISREG(__mode) (((__mode) & S_IFMT) == S_IFREG)
+#endif
+
+namespace SimGrid
+{
+ namespace Msg
+ {
+ Environment::Environment()
+ {
+ this->file = NULL;
+ this->loaded = false;
+ }
+
+ Environment::Environment(const Environment& rEnvironment)
+ {
+ this->file = rEnvironment.getFile();
+ this->loaded = rEnvironment.isLoaded();
+ }
+
+ Environment::Environment(const char* file)
+ throw(NullPointerException, FileNotFoundException)
+ {
+ // check parameters
+
+ if(!file)
+ throw NullPointerException("file (must not be NULL");
+
+ struct stat statBuf = {0};
+
+ if(stat(file, &statBuf) < 0 || !S_ISREG(statBuf.st_mode))
+ throw FileNotFoundException("file (file not found)");
+
+ this->file = file;
+ this->loaded = false;
+ }
+
+ Environment::~Environment()
+ {
+ // NOTHING TODO
+ }
+
+ // Operations.
+
+ void Environment::load(void)
+ throw(LogicException)
+ {
+ // check logic
+
+ if(this->loaded)
+ throw LogicException("environement already loaded");
+
+ // check the parameters
+ if(!this->file)
+ throw LogicException("you must specify the xml file which describe the environment to load\nuse Environment::setFile()");
+
+ MSG_create_environment(file);
+
+ this->loaded = true;
+ }
+
+ void Environment::load(const char* file)
+ throw(NullPointerException, FileNotFoundException, LogicException)
+ {
+ // check logic
+
+ if(this->loaded)
+ throw LogicException("environment already loaded");
+
+ // check the parameters
+
+ if(!file)
+ throw NullPointerException("file");
+
+ struct stat statBuf = {0};
+
+ if(stat(file, &statBuf) < 0 || !S_ISREG(statBuf.st_mode))
+ throw FileNotFoundException(file);
+
+ MSG_create_environment(file);
+
+ this->file = file;
+ this->loaded = true;
+ }
+
+ bool Environment::isLoaded(void) const
+ {
+ return this->loaded;
+ }
+
+ // Getters/setters
+ void Environment::setFile(const char* file)
+ throw(NullPointerException, FileNotFoundException, LogicException)
+ {
+ // check logic
+
+ if(this->loaded)
+ throw LogicException("your are trying to change the file of an already loaded environment");
+
+ // check parameters
+
+ if(!file)
+ throw NullPointerException("file (must not be NULL");
+
+ struct stat statBuf = {0};
+
+ if(stat(file, &statBuf) < 0 || !S_ISREG(statBuf.st_mode))
+ throw FileNotFoundException("file (file not found)");
+
+ this->file = file;
+ }
+
+ const char* Environment::getFile(void) const
+ {
+ return this->file;
+ }
+
+
+ const Environment& Environment::operator = (const Environment& rEnvironment)
+ throw(LogicException)
+ {
+ // check logic
+
+ if(this->loaded)
+ throw LogicException("environment already loaded");
+
+ this->file = rEnvironment.getFile();
+ this->loaded = rEnvironment.isLoaded();
+
+ return *this;
+ }
+
+ } // namespace Msg
+} // namespace SimGrid
+