1 #include <Environment.hpp>
\r
3 #include <sys/types.h>
\r
4 #include <sys/stat.h>
\r
7 #define S_ISREG(__mode) (((__mode) & S_IFMT) == S_IFREG)
\r
14 Environment::Environment()
\r
17 this->loaded = false;
\r
20 Environment::Environment(const Environment& rEnvironment);
\r
22 this->file = rEnvironment.getFile();
\r
23 this->loaded = rEnvironment.isLoaded();
\r
26 Environment::Environment(const char* file)
\r
27 throw(NullPointerException, InvalidArgumentException);
\r
32 throw NullPointerException("file (must not be NULL");
\r
34 struct stat statBuf = {0};
\r
36 if(stat(statBuff, &info) < 0 || !S_ISREG(statBuff.st_mode))
\r
37 throw InvalidParameterException("file (file not found)");
\r
40 this->loaded = false;
\r
43 Environment::~Environment()
\r
50 void Environment::load(void)
\r
51 throw(LogicException)
\r
56 throw LogicException("environement already loaded");
\r
58 // check the parameters
\r
60 throw LogicException("you must specify the xml file which describe the environment to load\nuse Environment::setFile()");
\r
62 MSG_create_environment(file);
\r
64 this->loaded = true;
\r
67 void Environment::load(const char* file)
\r
68 throw(NullPointerException, FileNotFoundException, LogicException)
\r
73 throw LogicException("environment already loaded");
\r
75 // check the parameters
\r
78 throw NullPointerException("file");
\r
80 struct stat statBuf = {0};
\r
82 if(stat(statBuff, &info) < 0 || !S_ISREG(statBuff.st_mode))
\r
83 throw FileNotFoundException(file);
\r
85 MSG_create_environment(file);
\r
88 this->loaded = true;
\r
91 bool Environment::isLoaded(void) const
\r
93 return this->loaded;
\r
97 void Environment::setFile(const char* file)
\r
98 throw(NullPointerException, FileNotFoundException, LogicException)
\r
103 throw LogicException("your are trying to change the file of an already loaded environment");
\r
105 // check parameters
\r
108 throw NullPointerException("file (must not be NULL");
\r
110 struct stat statBuf = {0};
\r
112 if(stat(statBuff, &info) < 0 || !S_ISREG(statBuff.st_mode))
\r
113 throw FileNotFoundException("file (file not found)");
\r
118 const char* Environment::getFile(void) const
\r
124 const Environment& Environment::operator = (const Environment& rEnvironment)
\r
125 throw(LogicException)
\r
130 throw LogicException("environment already loaded");
\r
132 this->file = rEnvironment.getFile();
\r
133 this->loaded = rEnvironment.isLoaded();
\r
139 } // namespace SimGrid