base/RuntimeEnv.hpp

Go to the documentation of this file.
00001 /*
00002   This file is part of OpenFLUID software
00003   Copyright (c) 2007-2010 INRA-Montpellier SupAgro
00004 
00005 
00006  == GNU General Public License Usage ==
00007 
00008   OpenFLUID is free software: you can redistribute it and/or modify
00009   it under the terms of the GNU General Public License as published by
00010   the Free Software Foundation, either version 3 of the License, or
00011   (at your option) any later version.
00012 
00013   OpenFLUID is distributed in the hope that it will be useful,
00014   but WITHOUT ANY WARRANTY; without even the implied warranty of
00015   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016   GNU General Public License for more details.
00017 
00018   You should have received a copy of the GNU General Public License
00019   along with OpenFLUID.  If not, see <http://www.gnu.org/licenses/>.
00020 
00021   In addition, as a special exception, INRA gives You the additional right
00022   to dynamically link the code of OpenFLUID with code not covered
00023   under the GNU General Public License ("Non-GPL Code") and to distribute
00024   linked combinations including the two, subject to the limitations in this
00025   paragraph. Non-GPL Code permitted under this exception must only link to
00026   the code of OpenFLUID dynamically through the OpenFLUID libraries
00027   interfaces, and only for building OpenFLUID plugins. The files of
00028   Non-GPL Code may be link to the OpenFLUID libraries without causing the
00029   resulting work to be covered by the GNU General Public License. You must
00030   obey the GNU General Public License in all respects for all of the
00031   OpenFLUID code and other code used in conjunction with OpenFLUID
00032   except the Non-GPL Code covered by this exception. If you modify
00033   this OpenFLUID, you may extend this exception to your version of the file,
00034   but you are not obligated to do so. If you do not wish to provide this
00035   exception without modification, you must delete this exception statement
00036   from your version and license this OpenFLUID solely under the GPL without
00037   exception.
00038 
00039 
00040  == Other Usage ==
00041 
00042   Other Usage means a use of OpenFLUID that is inconsistent with the GPL
00043   license, and requires a written agreement between You and INRA.
00044   Licensees for Other Usage of OpenFLUID may use this file in accordance
00045   with the terms contained in the written agreement between You and INRA.
00046 */
00047 
00048 
00055 #ifndef __RUNTIMEENV_HPP__
00056 #define __RUNTIMEENV_HPP__
00057 
00058 #include <openfluid/dllexport.hpp>
00059 #include <openfluid/tools.hpp>
00060 #include <openfluid/base/EnvProperties.hpp>
00061 #include <openfluid/base/SimulationProfiler.hpp>
00062 
00063 #include <boost/filesystem/path.hpp>
00064 #include <boost/date_time/posix_time/posix_time.hpp>
00065 
00066 
00067 namespace openfluid { namespace base {
00068 
00069 
00070 // =====================================================================
00071 // =====================================================================
00072 
00073 
00077 class DLLEXPORT RuntimeEnvironment
00078 {
00079   private:
00080 
00081     static RuntimeEnvironment* mp_Singleton;
00082 
00083     std::string m_Version;
00084     std::string m_FullVersion;
00085     std::string m_MajorMinorVersion;
00086 
00087     std::string m_OutputDir;
00088     std::string m_InputDir;
00089     std::string m_UserDataDir;
00090     std::string m_TempDir;
00091     std::string m_HomeDir;
00092     std::string m_MarketBagDir;
00093     std::string m_MarketBagBinVersionDir;
00094     std::string m_MarketBagSrcVersionDir;
00095 
00096     std::string m_InstallPrefix;
00097 
00098     std::vector<std::string> m_DefaultPlugsDirs;
00099     std::vector<std::string> m_ExtraPlugsDirs;
00100 
00101     std::string m_UserID;
00102     std::string m_HostName;
00103     std::string m_Arch;
00104 
00105     unsigned int m_FunctionsMaxNumThreads;
00106 
00107     std::string m_DefaultConfigFilePath;
00108 
00109     bool m_ClearOutputDir;
00110 
00111     bool m_WriteResults;
00112 
00113     bool m_WriteSimReport;
00114 
00115     unsigned int m_ValuesBufferSize;
00116 
00117     bool m_IsUserValuesBufferSize;
00118 
00119     unsigned int m_FilesBufferSize;
00120 
00121     openfluid::base::EnvironmentProperties* mp_FuncEnv;
00122 
00123     openfluid::base::EnvironmentProperties m_ExtraProperties;
00124 
00125     boost::posix_time::ptime m_IgnitionDateTime;
00126 
00127     std::string m_SimulationID;
00128 
00129     boost::posix_time::time_duration m_EffectiveSimulationDuration;
00130 
00131     openfluid::core::DateTime m_StartTime;
00132 
00133     openfluid::core::DateTime m_EndTime;
00134 
00135     // TODO set correct type for time step
00136     int m_TimeStep;
00137 
00138     bool m_IsLinkedToProject;
00139 
00140 
00144     RuntimeEnvironment();
00145 
00146   public:
00147 
00148     static RuntimeEnvironment* getInstance();
00149 
00153     ~RuntimeEnvironment();
00154 
00155 
00160     std::string getVersion() const { return m_Version; };
00161 
00166     std::string getFullVersion() const { return m_FullVersion; };
00167 
00172     std::string getMajorMinorVersion() const { return m_MajorMinorVersion; };
00173 
00174 
00175 
00180     void setInputDir(const std::string InputDir)
00181       { m_InputDir = InputDir; mp_FuncEnv->setValue("dir.input",m_InputDir); };
00182 
00187     inline std::string getInputDir() const { return m_InputDir; };
00188 
00193     void setOutputDir(const std::string OutputDir)
00194       { m_OutputDir = OutputDir; mp_FuncEnv->setValue("dir.output",m_OutputDir); };
00195 
00200     inline std::string getOutputDir() const { return m_OutputDir; };
00201 
00205     void setDateTimeOutputDir();
00206 
00211     inline std::string getMarketBagDir() const { return m_MarketBagDir; };
00212 
00217     inline std::string getMarketBagBinVersionDir() const { return m_MarketBagBinVersionDir; };
00218 
00223     inline std::string getMarketBagSrcVersionDir() const { return m_MarketBagSrcVersionDir; };
00224 
00229     inline std::string getDefaultConfigFile() const
00230       { return m_DefaultConfigFilePath; };
00231 
00237     std::string getConfigFilePath(std::string Filename) const
00238       { return boost::filesystem::path(m_UserDataDir + "/" + Filename).string(); };
00239 
00245     std::string getUserDataPath(std::string RelativePath) const
00246       { return boost::filesystem::path(m_UserDataDir + "/" + RelativePath).string(); };
00247 
00252     inline std::string getTempDir() const
00253       { return m_TempDir; };
00254 
00260     std::string getInputFullPath(std::string Filename) const
00261       { return boost::filesystem::path(m_InputDir + "/" + Filename).string(); };
00262 
00268     inline std::string getOutputFullPath(std::string Filename) const
00269       { return boost::filesystem::path(m_OutputDir + "/" + Filename).string(); };
00270 
00276     std::string getPluginFullPath(std::string Filename);
00277 
00283     void addExtraPluginsPaths(std::string SemicolonSeparatedPaths);
00284 
00285     inline void resetExtraPluginsPaths() { m_ExtraPlugsDirs.clear(); };
00286 
00287     inline std::vector<std::string> getDefaultPluginsPaths() const  { return m_DefaultPlugsDirs;  };
00288 
00289     inline std::vector<std::string> getExtraPluginsPaths() const  { return m_ExtraPlugsDirs;  };
00290 
00295     inline std::vector<std::string> getPluginsPaths() const
00296     {
00297       std::vector<std::string> ComposedPaths(m_ExtraPlugsDirs);
00298       ComposedPaths.insert(ComposedPaths.end(), m_DefaultPlugsDirs.begin(), m_DefaultPlugsDirs.end());
00299       return ComposedPaths;
00300     };
00301 
00307     inline std::string getInstallPrefix() const
00308       { return m_InstallPrefix; };
00309 
00314     std::string getCommonResourcesDir() const;
00315 
00321     std::string getCommonResourceFilePath(std::string RelativeFilePath) const;
00322 
00328     std::string getAppResourcesDir(std::string AppName) const;
00329 
00336     std::string getAppResourceFilePath(std::string AppName, std::string RelativeFilePath) const;
00337 
00342     std::string getLocaleDir()const;
00343 
00348     inline openfluid::base::EnvironmentProperties& getExtraProperties()
00349       { return m_ExtraProperties; };
00350 
00354     inline bool isClearOutputDir() const { return m_ClearOutputDir; };
00355 
00360     inline void setClearOutputDir(bool ClearDir)
00361       { m_ClearOutputDir = ClearDir; mp_FuncEnv->setValue("mode.clearoutputdir",m_ClearOutputDir); };
00362 
00367     inline bool isWriteResults() const
00368       { return m_WriteResults; };
00369 
00374     void setWriteResults(bool WriteIt)
00375       { m_WriteResults = WriteIt; mp_FuncEnv->setValue("mode.saveresults",m_WriteResults); };
00376 
00381     inline bool isWriteSimReport() const { return m_WriteSimReport; };
00382 
00387     void setWriteSimReport(bool WriteIt)
00388       { m_WriteSimReport = WriteIt; mp_FuncEnv->setValue("mode.writereport",m_WriteSimReport); };
00389 
00390     openfluid::base::EnvironmentProperties* getFunctionEnvironment() const
00391       { return mp_FuncEnv; };
00392 
00393 
00394     boost::posix_time::ptime getIgnitionDateTime() const
00395       { return m_IgnitionDateTime; };
00396 
00397     inline std::string getSimulationID() const {return m_SimulationID; };
00398 
00399     void setSimulationID(const std::string SimID) { m_SimulationID = SimID; };
00400 
00401     boost::posix_time::time_duration getEffectiveSimulationDuration() const
00402       { return m_EffectiveSimulationDuration; };
00403 
00404     void setEffectiveSimulationDuration(const boost::posix_time::time_duration& TimeDuration)
00405       { m_EffectiveSimulationDuration = TimeDuration; };
00406 
00411     std::string getHostName() const {return m_HostName; };
00412 
00417     std::string getUserID() const {return m_UserID; };
00418 
00423     std::string getArch() const {return m_Arch; };
00424 
00425     unsigned int getFunctionsMaxNumThreads() const { return m_FunctionsMaxNumThreads; };
00426 
00427     void setFunctionsMaxNumThreads(const unsigned int& MaxNumThreads)
00428       { if (MaxNumThreads > 0) m_FunctionsMaxNumThreads = MaxNumThreads; };
00429 
00430 
00431     void setSimulationTimeInformation(openfluid::core::DateTime StartTime,
00432                                       openfluid::core::DateTime EndTime,
00433                                       int TimeStep);
00434 
00435     openfluid::core::DateTime getSimulationStartTime() const
00436       { return m_StartTime; };
00437 
00438     openfluid::core::DateTime getSimulationEndTime() const
00439       { return m_EndTime; };
00440 
00441     // TODO set correct type for time step
00442     int getSimulationTimeStep() const
00443       { return m_TimeStep; };
00444 
00445     void setValuesBufferSize(const unsigned int StepsNbr)
00446       { m_ValuesBufferSize = StepsNbr; m_IsUserValuesBufferSize = true; };
00447 
00448     inline unsigned int getValuesBufferSize() const
00449       { return m_ValuesBufferSize; };
00450 
00451     bool isUserValuesBufferSize() const { return m_IsUserValuesBufferSize; };
00452 
00453     void setFilesBufferSize(const unsigned int Bytes)
00454       { m_FilesBufferSize = Bytes; };
00455 
00456     inline unsigned int getFilesBufferSize() const
00457       { return m_FilesBufferSize; };
00458 
00459     inline void unsetUserValuesBufferSize()
00460       { m_IsUserValuesBufferSize = false; }
00461 
00462     void linkToProject();
00463 
00464     void detachFromProject();
00465 
00466     bool isLinkedToProject()
00467       { return m_IsLinkedToProject; };
00468 
00469     bool isSimulationProfilingEnabled() const { return SimulationProfiler::getInstance()->isEnabled(); };
00470 
00471     void setSimulationProfilingEnabled(bool Profiling) { SimulationProfiler::getInstance()->setEnabled(Profiling); };
00472 
00473 };
00474 
00475 
00476 } } //namespaces
00477 
00478 #endif
00479 
00480 
00481 

Generated using Doxygen 1.7.3
Creative Commons License Creative Commons By-NC-ND license