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
18 #include <NullPointerException.hpp>
\r
19 #include <FileNotFoundException.hpp>
\r
20 #include <InvalidArgumentException.hpp>
\r
21 #include <LogicException.hpp>
\r
22 #include <MsgException.hpp>
\r
26 #include <sys/types.h>
\r
27 #include <sys/stat.h>
\r
29 #include <msg/msg.h>
\r
32 #define S_ISREG(__mode) (((__mode) & S_IFMT) == S_IFREG)
\r
39 Environment::Environment()
\r
42 this->loaded = false;
\r
45 Environment::Environment(const Environment& rEnvironment)
\r
47 this->file = rEnvironment.getFile();
\r
48 this->loaded = rEnvironment.isLoaded();
\r
51 Environment::Environment(const char* file)
\r
52 throw(NullPointerException, InvalidArgumentException)
\r
57 throw NullPointerException("file (must not be NULL");
\r
59 struct stat statBuf = {0};
\r
61 if(stat(file, &statBuf) < 0 || !S_ISREG(statBuf.st_mode))
\r
62 throw InvalidArgumentException("file (file not found)");
\r
65 this->loaded = false;
\r
68 Environment::~Environment()
\r
75 void Environment::load(void)
\r
76 throw(LogicException)
\r
81 throw LogicException("environement already loaded");
\r
83 // check the parameters
\r
85 throw LogicException("you must specify the xml file which describe the environment to load\nuse Environment::setFile()");
\r
87 MSG_create_environment(file);
\r
89 this->loaded = true;
\r
92 void Environment::load(const char* file)
\r
93 throw(NullPointerException, FileNotFoundException, LogicException)
\r
98 throw LogicException("environment already loaded");
\r
100 // check the parameters
\r
103 throw NullPointerException("file");
\r
105 struct stat statBuf = {0};
\r
107 if(stat(file, &statBuf) < 0 || !S_ISREG(statBuf.st_mode))
\r
108 throw FileNotFoundException(file);
\r
110 MSG_create_environment(file);
\r
113 this->loaded = true;
\r
116 bool Environment::isLoaded(void) const
\r
118 return this->loaded;
\r
122 void Environment::setFile(const char* file)
\r
123 throw(NullPointerException, FileNotFoundException, LogicException)
\r
128 throw LogicException("your are trying to change the file of an already loaded environment");
\r
130 // check parameters
\r
133 throw NullPointerException("file (must not be NULL");
\r
135 struct stat statBuf = {0};
\r
137 if(stat(file, &statBuf) < 0 || !S_ISREG(statBuf.st_mode))
\r
138 throw FileNotFoundException("file (file not found)");
\r
143 const char* Environment::getFile(void) const
\r
149 const Environment& Environment::operator = (const Environment& rEnvironment)
\r
150 throw(LogicException)
\r
155 throw LogicException("environment already loaded");
\r
157 this->file = rEnvironment.getFile();
\r
158 this->loaded = rEnvironment.isLoaded();
\r
164 } // namespace SimGrid