4 * Copyright 2006,2007 Martin Quinson, Malek Cherier
\r
5 * All right reserved.
\r
7 * This program is free software; you can redistribute
\r
8 * it and/or modify it under the terms of the license
\r
9 *(GNU LGPL) which comes with this package.
\r
13 /* Environment member functions implementation.
\r
16 #include <Environment.hpp>
\r
20 #include <sys/types.h>
\r
21 #include <sys/stat.h>
\r
23 #include <msg/msg.h>
\r
26 #define S_ISREG(__mode) (((__mode) & S_IFMT) == S_IFREG)
\r
33 Environment::Environment()
\r
36 this->loaded = false;
\r
39 Environment::Environment(const Environment& rEnvironment)
\r
41 this->file = rEnvironment.getFile();
\r
42 this->loaded = rEnvironment.isLoaded();
\r
45 Environment::Environment(const char* file)
\r
46 throw(NullPointerException, FileNotFoundException)
\r
51 throw NullPointerException("file (must not be NULL");
\r
53 struct stat statBuf = {0};
\r
55 if(stat(file, &statBuf) < 0 || !S_ISREG(statBuf.st_mode))
\r
56 throw FileNotFoundException("file (file not found)");
\r
59 this->loaded = false;
\r
62 Environment::~Environment()
\r
69 void Environment::load(void)
\r
70 throw(LogicException)
\r
75 throw LogicException("environement already loaded");
\r
77 // check the parameters
\r
79 throw LogicException("you must specify the xml file which describe the environment to load\nuse Environment::setFile()");
\r
81 MSG_create_environment(file);
\r
83 this->loaded = true;
\r
86 void Environment::load(const char* file)
\r
87 throw(NullPointerException, FileNotFoundException, LogicException)
\r
92 throw LogicException("environment already loaded");
\r
94 // check the parameters
\r
97 throw NullPointerException("file");
\r
99 struct stat statBuf = {0};
\r
101 if(stat(file, &statBuf) < 0 || !S_ISREG(statBuf.st_mode))
\r
102 throw FileNotFoundException(file);
\r
104 MSG_create_environment(file);
\r
107 this->loaded = true;
\r
110 bool Environment::isLoaded(void) const
\r
112 return this->loaded;
\r
116 void Environment::setFile(const char* file)
\r
117 throw(NullPointerException, FileNotFoundException, LogicException)
\r
122 throw LogicException("your are trying to change the file of an already loaded environment");
\r
124 // check parameters
\r
127 throw NullPointerException("file (must not be NULL");
\r
129 struct stat statBuf = {0};
\r
131 if(stat(file, &statBuf) < 0 || !S_ISREG(statBuf.st_mode))
\r
132 throw FileNotFoundException("file (file not found)");
\r
137 const char* Environment::getFile(void) const
\r
143 const Environment& Environment::operator = (const Environment& rEnvironment)
\r
144 throw(LogicException)
\r
149 throw LogicException("environment already loaded");
\r
151 this->file = rEnvironment.getFile();
\r
152 this->loaded = rEnvironment.isLoaded();
\r
158 } // namespace SimGrid
\r