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