Documentation for OpenFLUID 2.2.0
RunContextManager.hpp
Go to the documentation of this file.
1 /*
2 
3  This file is part of OpenFLUID software
4  Copyright(c) 2007, INRA - Montpellier SupAgro
5 
6 
7  == GNU General Public License Usage ==
8 
9  OpenFLUID is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  (at your option) any later version.
13 
14  OpenFLUID is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with OpenFLUID. If not, see <http://www.gnu.org/licenses/>.
21 
22 
23  == Other Usage ==
24 
25  Other Usage means a use of OpenFLUID that is inconsistent with the GPL
26  license, and requires a written agreement between You and INRA.
27  Licensees for Other Usage of OpenFLUID may use this file in accordance
28  with the terms contained in the written agreement between You and INRA.
29 
30 */
31 
32 
33 /**
34  @file RunContextManager.hpp
35 
36  @author Jean-Christophe FABRE <jean-christophe.fabre@inra.fr>
37  */
38 
39 
40 #ifndef __OPENFLUID_BASE_RUNCONTEXTMANAGER_HPP__
41 #define __OPENFLUID_BASE_RUNCONTEXTMANAGER_HPP__
42 
43 
44 #include <string>
45 
46 #include <openfluid/dllexport.hpp>
49 #include <openfluid/ware/TypeDefs.hpp>
53 
54 
55 namespace openfluid { namespace base {
56 
57 
59 {
60 
62 
63 
64  protected:
65 
66  std::string m_OutputDir;
67 
68  std::string m_InputDir;
69 
71 
73 
74  unsigned int m_ValuesBufferSize;
75 
76  unsigned int m_WaresMaxNumThreads;
77 
79 
81 
83 
84  std::string m_ProjectPath;
85 
86  std::string m_ProjectName;
87 
88  std::string m_ProjectDescription;
89 
90  std::string m_ProjectAuthors;
91 
92  std::string m_ProjectCreationDate;
93 
94  std::string m_ProjectLastModDate;
95 
97 
99 
100  static const std::vector<std::string> m_DeprecatedProjectFiles;
101 
103 
105 
107 
108  static std::string getFilePathFromProjectPath(const std::string& ProjectPath);
109 
110  static std::string getInputDirFromProjectPath(const std::string& ProjectPath);
111 
112  static std::string getOuputDirFromProjectPath(const std::string& ProjectPath);
113 
114  static void updateProjectFile(const std::string& ProjectPath);
115 
116  static bool checkProject(const std::string& ProjectPath);
117 
118 
119  public:
120 
121  /**
122  Returns the full path of the simulation input directory
123  @return the full path of the directory
124  */
125  std::string getInputDir() const
126  {
127  return m_InputDir;
128  }
129 
130  /**
131  Returns the full path of a file or directory relative to the simulation input directory
132  @param[in] Filename the path relative to the simulation input directory
133  @return the full path to the file or directory
134  */
135  std::string getInputFullPath(const std::string& Filename) const;
136 
137  /**
138  Sets the full path of the simulation input directory
139  @param[in] InputDir the full path of the directory
140  */
141  void setInputDir(const std::string& InputDir);
142 
143  /**
144  Returns the full path of the simulation output directory
145  @return the full path of the directory
146  */
147  std::string getOutputDir() const
148  {
149  return m_OutputDir;
150  }
151 
152  /**
153  Returns the full path of a file or directory relative to the simulation output directory
154  @param[in] Filename the path relative to the simulation output directory
155  @return the full path to the file or directory
156  */
157  std::string getOutputFullPath(const std::string& Filename) const;
158 
159  /**
160  Sets the full path of the simulation output directory
161  @param[in] OutputDir the full path of the directory
162  */
163  void setOutputDir(const std::string& OutputDir);
164 
166 
167  /**
168  Returns the status of automatic cleaning of output directory before simulation run
169  @return true if enabled, false if disabled
170  */
171  bool isClearOutputDir() const
172  {
173  return m_IsClearOutputDir;
174  }
175 
176  /**
177  Sets the status of automatic cleaning of output directory before simulation run
178  @param Enabled set to true to enable
179  */
180  void setClearOutputDir(bool Enabled)
181  {
182  m_IsClearOutputDir = Enabled;
183  }
184 
185  /**
186  Returns the status of simulation profiling
187  @return true if enabled, false if disabled
188  */
189  bool isProfiling() const
190  {
191  return m_IsProfiling;
192  }
193 
194  /**
195  Sets the status of simulation profiling
196  @param Enabled set to true to enable
197  */
198  void setProfiling(bool Enabled)
199  {
200  m_IsProfiling = Enabled;
201  }
202 
203  /**
204  Returns the size of the buffer set by the user for simulation variables values
205  @return the size of the buffer
206  */
207  unsigned int getValuesBufferUserSize() const
208  {
209  return m_ValuesBufferSize;
210  }
211 
212  /**
213  Sets the size of the buffer set by the user for simulation variables values
214  @param[in] Size the size of the buffer
215  */
216  void setValuesBufferUserSize(unsigned int Size)
217  {
218  m_ValuesBufferSize = Size;
219  }
220 
221  /**
222  Unsets the size of the buffer set by the user for simulation variables values
223  */
225  {
226  m_ValuesBufferSize = 0;
227  }
228 
229  /**
230  Returns true if the size of the buffer for simulation variables values has been set by the user
231  @return true if set by user (size > 0), false otherwise
232  */
234  {
235  return (m_ValuesBufferSize > 0);
236  }
237 
238  /**
239  Returns the value for maximum threads count to be used in OpenFLUID wares (simulators, observers, ...)
240  @return the maximum threads count
241  */
242  unsigned int getWaresMaxNumThreads() const
243  {
244  return m_WaresMaxNumThreads;
245  }
246 
247  /**
248  Sets the value for maximum threads count to be used in OpenFLUID wares (simulators, observers, ...)
249  @param[in] Num the maximum threads count
250  */
251  void setWaresMaxNumThreads(unsigned int Num)
252  {
253  m_WaresMaxNumThreads = Num;
254  }
255 
256  /**
257  Resets the value for maximum threads count to be used in OpenFLUID wares (simulators, observers, ...).
258  The value is reset to the ideal thread count given by the OpenFLUID environment
259  */
261 
263  {
264  return m_ExtraProperties;
265  }
266 
268  {
269  return m_WaresSharedEnvironment;
270  }
271 
273 
274  std::string getProjectPath() const
275  {
276  return m_ProjectPath;
277  }
278 
279  std::string getProjectName() const
280  {
281  return m_ProjectName;
282  }
283 
284  void setProjectName(const std::string& Name)
285  {
286  m_ProjectName = Name;
287  }
288 
289  std::string getProjectDescription() const
290  {
291  return m_ProjectDescription;
292  }
293 
294  void setProjectDescription(const std::string& Description)
295  {
296  m_ProjectDescription = Description;
297  }
298 
299  std::string getProjectAuthors() const
300  {
301  return m_ProjectAuthors;
302  }
303 
304  void setProjectAuthors(const std::string& Authors)
305  {
306  m_ProjectAuthors = Authors;
307  }
308 
309  std::string getProjectCreationDate() const
310  {
311  return m_ProjectCreationDate;
312  }
313 
314  void setProjectCreationDate(const std::string& CreationDate)
315  {
316  m_ProjectCreationDate = CreationDate;
317  }
318 
320  {
321  m_ProjectCreationDate = openfluid::tools::getNowAsString("%Y%m%dT%H%M%S");
322  }
323 
324  std::string getProjectLastModDate() const
325  {
326  return m_ProjectLastModDate;
327  }
328 
329  void setProjectLastModDate(const std::string& LastModDate)
330  {
331  m_ProjectLastModDate = LastModDate;
332  }
333 
335  {
336  return m_ProjectIncOutputDir;
337  }
338 
339  void setProjectIncrementalOutputDir(const bool Inc)
340  {
341  m_ProjectIncOutputDir = Inc;
342  }
343 
344  bool openProject(const std::string& Path);
345 
346  bool createProject(const std::string& Path, const std::string& Name,
347  const std::string& Description, const std::string& Authors,
348  const bool Inc);
349 
350  bool isProjectOpen() const
351  {
352  return m_ProjectIsOpen;
353  }
354 
355  bool saveProject();
356 
357  void closeProject();
358 
359  static bool isProject(const std::string& Path);
360 
361  static bool getProjectInfos(const std::string& Path,
362  std::string& Name, std::string& Description, std::string& Authors,
363  std::string& CreationDate, std::string& LastModDate);
364 
365  static bool projectContainsDeprecatedFile(const std::string& Path);
366 
368 
369  openfluid::tools::SettingValue getProjectContextValue(const std::string& Pointer) const;
370 
371  openfluid::tools::SettingValue getProjectContextValue(const std::string& ParentPointer,
372  const std::string& Key) const;
373 
374  void removeProjectContextValue(const std::string& Pointer);
375 
376  void setProjectContextValue(const std::string& ParentPointer, const std::string& Key,
377  const openfluid::tools::SettingValue& Value);
378 
379 };
380 
381 
382 } } //namespaces
383 
384 
385 #endif /* __OPENFLUID_BASE_RUNCONTEXTMANAGER_HPP__ */
#define OPENFLUID_SINGLETON_DEFINITION(T)
Definition: SingletonMacros.hpp:55
Definition: Environment.hpp:53
Definition: RunContextManager.hpp:59
bool isProjectOpen() const
Definition: RunContextManager.hpp:350
void setProjectLastModDate(const std::string &LastModDate)
Definition: RunContextManager.hpp:329
bool isProfiling() const
Definition: RunContextManager.hpp:189
std::string m_ProjectCreationDate
Definition: RunContextManager.hpp:92
openfluid::core::MapValue & extraProperties()
Definition: RunContextManager.hpp:262
unsigned int getWaresMaxNumThreads() const
Definition: RunContextManager.hpp:242
void setWaresMaxNumThreads(unsigned int Num)
Definition: RunContextManager.hpp:251
void setProjectDescription(const std::string &Description)
Definition: RunContextManager.hpp:294
static bool checkProject(const std::string &ProjectPath)
static std::string getInputDirFromProjectPath(const std::string &ProjectPath)
bool createProject(const std::string &Path, const std::string &Name, const std::string &Description, const std::string &Authors, const bool Inc)
openfluid::core::MapValue m_WaresSharedEnvironment
Definition: RunContextManager.hpp:78
std::string getInputDir() const
Definition: RunContextManager.hpp:125
openfluid::tools::SettingValue getProjectContextValue(const std::string &ParentPointer, const std::string &Key) const
void setProjectContextValue(const std::string &ParentPointer, const std::string &Key, const openfluid::tools::SettingValue &Value)
unsigned int m_WaresMaxNumThreads
Definition: RunContextManager.hpp:76
std::string m_OutputDir
Definition: RunContextManager.hpp:66
unsigned int m_ValuesBufferSize
Definition: RunContextManager.hpp:74
std::string m_ProjectAuthors
Definition: RunContextManager.hpp:90
void setProjectCreationDateAsNow()
Definition: RunContextManager.hpp:319
bool isClearOutputDir() const
Definition: RunContextManager.hpp:171
void setValuesBufferUserSize(unsigned int Size)
Definition: RunContextManager.hpp:216
std::string getInputFullPath(const std::string &Filename) const
openfluid::core::MapValue m_ExtraProperties
Definition: RunContextManager.hpp:80
openfluid::tools::SettingValue getProjectContextValue(const std::string &Pointer) const
std::string getProjectPath() const
Definition: RunContextManager.hpp:274
void removeProjectContextValue(const std::string &Pointer)
std::string m_ProjectDescription
Definition: RunContextManager.hpp:88
std::string m_InputDir
Definition: RunContextManager.hpp:68
std::string m_ProjectName
Definition: RunContextManager.hpp:86
bool m_ProjectIncOutputDir
Definition: RunContextManager.hpp:96
void setProjectName(const std::string &Name)
Definition: RunContextManager.hpp:284
void unsetValuesBufferUserSize()
Definition: RunContextManager.hpp:224
std::string getProjectLastModDate() const
Definition: RunContextManager.hpp:324
static bool projectContainsDeprecatedFile(const std::string &Path)
bool m_ProjectIsOpen
Definition: RunContextManager.hpp:98
std::string m_ProjectPath
Definition: RunContextManager.hpp:84
unsigned int getValuesBufferUserSize() const
Definition: RunContextManager.hpp:207
bool m_IsProfiling
Definition: RunContextManager.hpp:72
openfluid::tools::SettingsBackend * mp_ProjectFile
Definition: RunContextManager.hpp:82
std::string getProjectDescription() const
Definition: RunContextManager.hpp:289
std::string getOutputFullPath(const std::string &Filename) const
static bool getProjectInfos(const std::string &Path, std::string &Name, std::string &Description, std::string &Authors, std::string &CreationDate, std::string &LastModDate)
bool m_IsClearOutputDir
Definition: RunContextManager.hpp:70
static std::string getFilePathFromProjectPath(const std::string &ProjectPath)
void setClearOutputDir(bool Enabled)
Definition: RunContextManager.hpp:180
static bool isProject(const std::string &Path)
void setProjectCreationDate(const std::string &CreationDate)
Definition: RunContextManager.hpp:314
void setProfiling(bool Enabled)
Definition: RunContextManager.hpp:198
std::string getOutputDir() const
Definition: RunContextManager.hpp:147
void setProjectIncrementalOutputDir(const bool Inc)
Definition: RunContextManager.hpp:339
void processWareParams(openfluid::ware::WareParams_t &Params) const
bool isProjectIncrementalOutputDir() const
Definition: RunContextManager.hpp:334
bool openProject(const std::string &Path)
std::string getProjectCreationDate() const
Definition: RunContextManager.hpp:309
static std::string getOuputDirFromProjectPath(const std::string &ProjectPath)
std::string getProjectName() const
Definition: RunContextManager.hpp:279
std::string getProjectAuthors() const
Definition: RunContextManager.hpp:299
void setOutputDir(const std::string &OutputDir)
std::string m_ProjectLastModDate
Definition: RunContextManager.hpp:94
static const std::vector< std::string > m_DeprecatedProjectFiles
Definition: RunContextManager.hpp:100
void setInputDir(const std::string &InputDir)
void setProjectAuthors(const std::string &Authors)
Definition: RunContextManager.hpp:304
const openfluid::core::MapValue & getWaresEnvironment() const
Definition: RunContextManager.hpp:267
static void updateProjectFile(const std::string &ProjectPath)
bool isValuesBufferUserSize() const
Definition: RunContextManager.hpp:233
Definition: MapValue.hpp:93
Definition: SettingsBackend.hpp:61
Definition: SettingsBackend.hpp:215
#define OPENFLUID_API
Definition: dllexport.hpp:86
std::string OPENFLUID_API getNowAsString(const std::string &Format)
FilesystemPath Path
Definition: FilesystemPath.hpp:308
std::map< WareParamKey_t, WareParamValue_t > WareParams_t
Definition: TypeDefs.hpp:146
Definition: ApplicationException.hpp:47