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 <string>
00059 #include <boost/date_time/posix_time/posix_time.hpp>
00060 #include <boost/filesystem/path.hpp>
00061 
00062 #include <openfluid/dllexport.hpp>
00063 #include <openfluid/base/EnvProperties.hpp>
00064 #include <openfluid/base/SimulationProfiler.hpp>
00065 #include <openfluid/core/DateTime.hpp>
00066 
00067 
00068 
00069 namespace openfluid { namespace base {
00070 
00071 
00072 // =====================================================================
00073 // =====================================================================
00074 
00075 
00079 class DLLEXPORT RuntimeEnvironment
00080 {
00081   private:
00082 
00083     static RuntimeEnvironment* mp_Singleton;
00084 
00085     std::string m_Version;
00086     std::string m_FullVersion;
00087     std::string m_MajorMinorVersion;
00088 
00089     std::string m_OutputDir;
00090     std::string m_InputDir;
00091     std::string m_UserDataDir;
00092     std::string m_TempDir;
00093     std::string m_HomeDir;
00094     std::string m_MarketBagDir;
00095     std::string m_MarketBagBinVersionDir;
00096     std::string m_MarketBagSrcVersionDir;
00097 
00098     std::string m_InstallPrefix;
00099 
00100     std::vector<std::string> m_DefaultPlugsDirs;
00101     std::vector<std::string> m_ExtraPlugsDirs;
00102 
00103     std::string m_UserID;
00104     std::string m_HostName;
00105     std::string m_Arch;
00106 
00107     unsigned int m_FunctionsMaxNumThreads;
00108 
00109     std::string m_DefaultConfigFilePath;
00110 
00111     bool m_ClearOutputDir;
00112 
00113     bool m_WriteResults;
00114 
00115     bool m_WriteSimReport;
00116 
00117     unsigned int m_ValuesBufferSize;
00118 
00119     bool m_IsUserValuesBufferSize;
00120 
00121     unsigned int m_FilesBufferSize;
00122 
00123     openfluid::base::EnvironmentProperties* mp_FuncEnv;
00124 
00125     openfluid::base::EnvironmentProperties m_ExtraProperties;
00126 
00127     boost::posix_time::ptime m_IgnitionDateTime;
00128 
00129     std::string m_SimulationID;
00130 
00131     boost::posix_time::time_duration m_EffectiveSimulationDuration;
00132 
00133     openfluid::core::DateTime m_StartTime;
00134 
00135     openfluid::core::DateTime m_EndTime;
00136 
00137     // TODO set correct type for time step
00138     int m_TimeStep;
00139 
00140     bool m_IsLinkedToProject;
00141 
00142 
00146     RuntimeEnvironment();
00147 
00148   public:
00149 
00150     static RuntimeEnvironment* getInstance();
00151 
00155     ~RuntimeEnvironment();
00156 
00157 
00162     std::string getVersion() const { return m_Version; };
00163 
00168     std::string getFullVersion() const { return m_FullVersion; };
00169 
00174     std::string getMajorMinorVersion() const { return m_MajorMinorVersion; };
00175 
00176 
00177 
00182     void setInputDir(const std::string InputDir)
00183       { m_InputDir = InputDir; mp_FuncEnv->setValue("dir.input",m_InputDir); };
00184 
00189     inline std::string getInputDir() const { return m_InputDir; };
00190 
00195     void setOutputDir(const std::string OutputDir)
00196       { m_OutputDir = OutputDir; mp_FuncEnv->setValue("dir.output",m_OutputDir); };
00197 
00202     inline std::string getOutputDir() const { return m_OutputDir; };
00203 
00207     void setDateTimeOutputDir();
00208 
00213     inline std::string getMarketBagDir() const { return m_MarketBagDir; };
00214 
00219     inline std::string getMarketBagBinVersionDir() const { return m_MarketBagBinVersionDir; };
00220 
00225     inline std::string getMarketBagSrcVersionDir() const { return m_MarketBagSrcVersionDir; };
00226 
00231     inline std::string getDefaultConfigFile() const
00232       { return m_DefaultConfigFilePath; };
00233 
00239     std::string getConfigFilePath(std::string Filename) const
00240       { return boost::filesystem::path(m_UserDataDir + "/" + Filename).string(); };
00241 
00247     std::string getUserDataPath(std::string RelativePath) const
00248       { return boost::filesystem::path(m_UserDataDir + "/" + RelativePath).string(); };
00249 
00254     inline std::string getTempDir() const
00255       { return m_TempDir; };
00256 
00262     std::string getInputFullPath(std::string Filename) const
00263       { return boost::filesystem::path(m_InputDir + "/" + Filename).string(); };
00264 
00270     inline std::string getOutputFullPath(std::string Filename) const
00271       { return boost::filesystem::path(m_OutputDir + "/" + Filename).string(); };
00272 
00278     std::string getPluginFullPath(std::string Filename);
00279 
00285     void addExtraPluginsPaths(std::string SemicolonSeparatedPaths);
00286 
00287     inline void resetExtraPluginsPaths() { m_ExtraPlugsDirs.clear(); };
00288 
00289     inline std::vector<std::string> getDefaultPluginsPaths() const  { return m_DefaultPlugsDirs;  };
00290 
00291     inline std::vector<std::string> getExtraPluginsPaths() const  { return m_ExtraPlugsDirs;  };
00292 
00297     inline std::vector<std::string> getPluginsPaths() const
00298     {
00299       std::vector<std::string> ComposedPaths(m_ExtraPlugsDirs);
00300       ComposedPaths.insert(ComposedPaths.end(), m_DefaultPlugsDirs.begin(), m_DefaultPlugsDirs.end());
00301       return ComposedPaths;
00302     };
00303 
00309     inline std::string getInstallPrefix() const
00310       { return m_InstallPrefix; };
00311 
00316     std::string getCommonResourcesDir() const;
00317 
00323     std::string getCommonResourceFilePath(std::string RelativeFilePath) const;
00324 
00330     std::string getAppResourcesDir(std::string AppName) const;
00331 
00338     std::string getAppResourceFilePath(std::string AppName, std::string RelativeFilePath) const;
00339 
00344     std::string getLocaleDir()const;
00345 
00350     inline openfluid::base::EnvironmentProperties& getExtraProperties()
00351       { return m_ExtraProperties; };
00352 
00356     inline bool isClearOutputDir() const { return m_ClearOutputDir; };
00357 
00362     inline void setClearOutputDir(bool ClearDir)
00363       { m_ClearOutputDir = ClearDir; mp_FuncEnv->setValue("mode.clearoutputdir",m_ClearOutputDir); };
00364 
00369     inline bool isWriteResults() const
00370       { return m_WriteResults; };
00371 
00376     void setWriteResults(bool WriteIt)
00377       { m_WriteResults = WriteIt; mp_FuncEnv->setValue("mode.saveresults",m_WriteResults); };
00378 
00383     inline bool isWriteSimReport() const { return m_WriteSimReport; };
00384 
00389     void setWriteSimReport(bool WriteIt)
00390       { m_WriteSimReport = WriteIt; mp_FuncEnv->setValue("mode.writereport",m_WriteSimReport); };
00391 
00392     openfluid::base::EnvironmentProperties* getFunctionEnvironment() const
00393       { return mp_FuncEnv; };
00394 
00395 
00396     boost::posix_time::ptime getIgnitionDateTime() const
00397       { return m_IgnitionDateTime; };
00398 
00399     inline std::string getSimulationID() const {return m_SimulationID; };
00400 
00401     void setSimulationID(const std::string SimID) { m_SimulationID = SimID; };
00402 
00403     boost::posix_time::time_duration getEffectiveSimulationDuration() const
00404       { return m_EffectiveSimulationDuration; };
00405 
00406     void setEffectiveSimulationDuration(const boost::posix_time::time_duration& TimeDuration)
00407       { m_EffectiveSimulationDuration = TimeDuration; };
00408 
00413     std::string getHostName() const {return m_HostName; };
00414 
00419     std::string getUserID() const {return m_UserID; };
00420 
00425     std::string getArch() const {return m_Arch; };
00426 
00427     unsigned int getFunctionsMaxNumThreads() const { return m_FunctionsMaxNumThreads; };
00428 
00429     void setFunctionsMaxNumThreads(const unsigned int& MaxNumThreads)
00430       { if (MaxNumThreads > 0) m_FunctionsMaxNumThreads = MaxNumThreads; };
00431 
00432 
00433     void setSimulationTimeInformation(openfluid::core::DateTime StartTime,
00434                                       openfluid::core::DateTime EndTime,
00435                                       int TimeStep);
00436 
00437     openfluid::core::DateTime getSimulationStartTime() const
00438       { return m_StartTime; };
00439 
00440     openfluid::core::DateTime getSimulationEndTime() const
00441       { return m_EndTime; };
00442 
00443     // TODO set correct type for time step
00444     int getSimulationTimeStep() const
00445       { return m_TimeStep; };
00446 
00447     void setValuesBufferSize(const unsigned int StepsNbr)
00448       { m_ValuesBufferSize = StepsNbr; m_IsUserValuesBufferSize = true; };
00449 
00450     inline unsigned int getValuesBufferSize() const
00451       { return m_ValuesBufferSize; };
00452 
00453     bool isUserValuesBufferSize() const { return m_IsUserValuesBufferSize; };
00454 
00455     void setFilesBufferSize(const unsigned int Bytes)
00456       { m_FilesBufferSize = Bytes; };
00457 
00458     inline unsigned int getFilesBufferSize() const
00459       { return m_FilesBufferSize; };
00460 
00461     inline void unsetUserValuesBufferSize()
00462       { m_IsUserValuesBufferSize = false; }
00463 
00464     void linkToProject();
00465 
00466     void detachFromProject();
00467 
00468     bool isLinkedToProject()
00469       { return m_IsLinkedToProject; };
00470 
00471     bool isSimulationProfilingEnabled() const { return SimulationProfiler::getInstance()->isEnabled(); };
00472 
00473     void setSimulationProfilingEnabled(bool Profiling) { SimulationProfiler::getInstance()->setEnabled(Profiling); };
00474 
00475 };
00476 
00477 
00478 } } //namespaces
00479 
00480 #endif
00481 
00482 
00483 

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