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 <sys/types.h>
\r
19 #include <sys/stat.h>
\r
22 #define S_ISREG(__mode) (((__mode) & S_IFMT) == S_IFREG)
\r
29 Environment::Environment()
\r
32 this->loaded = false;
\r
35 Environment::Environment(const Environment& rEnvironment);
\r
37 this->file = rEnvironment.getFile();
\r
38 this->loaded = rEnvironment.isLoaded();
\r
41 Environment::Environment(const char* file)
\r
42 throw(NullPointerException, InvalidArgumentException);
\r
47 throw NullPointerException("file (must not be NULL");
\r
49 struct stat statBuf = {0};
\r
51 if(stat(statBuff, &info) < 0 || !S_ISREG(statBuff.st_mode))
\r
52 throw InvalidParameterException("file (file not found)");
\r
55 this->loaded = false;
\r
58 Environment::~Environment()
\r
65 void Environment::load(void)
\r
66 throw(LogicException)
\r
71 throw LogicException("environement already loaded");
\r
73 // check the parameters
\r
75 throw LogicException("you must specify the xml file which describe the environment to load\nuse Environment::setFile()");
\r
77 MSG_create_environment(file);
\r
79 this->loaded = true;
\r
82 void Environment::load(const char* file)
\r
83 throw(NullPointerException, FileNotFoundException, LogicException)
\r
88 throw LogicException("environment already loaded");
\r
90 // check the parameters
\r
93 throw NullPointerException("file");
\r
95 struct stat statBuf = {0};
\r
97 if(stat(statBuff, &info) < 0 || !S_ISREG(statBuff.st_mode))
\r
98 throw FileNotFoundException(file);
\r
100 MSG_create_environment(file);
\r
103 this->loaded = true;
\r
106 bool Environment::isLoaded(void) const
\r
108 return this->loaded;
\r
112 void Environment::setFile(const char* file)
\r
113 throw(NullPointerException, FileNotFoundException, LogicException)
\r
118 throw LogicException("your are trying to change the file of an already loaded environment");
\r
120 // check parameters
\r
123 throw NullPointerException("file (must not be NULL");
\r
125 struct stat statBuf = {0};
\r
127 if(stat(statBuff, &info) < 0 || !S_ISREG(statBuff.st_mode))
\r
128 throw FileNotFoundException("file (file not found)");
\r
133 const char* Environment::getFile(void) const
\r
139 const Environment& Environment::operator = (const Environment& rEnvironment)
\r
140 throw(LogicException)
\r
145 throw LogicException("environment already loaded");
\r
147 this->file = rEnvironment.getFile();
\r
148 this->loaded = rEnvironment.isLoaded();
\r
154 } // namespace SimGrid