TimePaths.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "TimePaths.H"
27 #include "IOstreams.H"
28 
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
30 
31 namespace Foam
32 {
33  const word TimePaths::systemName = "system";
34  const word TimePaths::constantName = "constant";
35 }
36 
37 
38 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
39 
41 (
42  const fileName& rootPath,
43  const fileName& caseName
44 )
45 :
46  processorCase_(false),
47  rootPath_(rootPath),
48  case_(caseName)
49 {
50  // Find out from case name whether a processor directory
51  std::string::size_type pos = caseName.find("processor");
52  if (pos != string::npos)
53  {
54  processorCase_ = true;
55 
56  if (pos == 0)
57  {
58  globalCaseName_ = ".";
59  }
60  else
61  {
62  globalCaseName_ = caseName(pos-1);
63  }
64  }
65  else
66  {
67  globalCaseName_ = caseName;
68  }
69 }
70 
71 
73 (
74  const bool processorCase,
75  const fileName& rootPath,
76  const fileName& globalCaseName,
77  const fileName& caseName
78 )
79 :
80  processorCase_(processorCase),
81  rootPath_(rootPath),
82  globalCaseName_(globalCaseName),
83  case_(caseName)
84 {
85  if (!processorCase)
86  {
87  // For convenience: find out from case name whether it is a
88  // processor directory and set processorCase flag so file searching
89  // goes up one level.
90  std::string::size_type pos = caseName.find("processor");
91 
92  if (pos != string::npos)
93  {
94  processorCase_ = true;
95 
96  if (pos == 0)
97  {
98  globalCaseName_ = ".";
99  }
100  else
101  {
102  globalCaseName_ = caseName(pos-1);
103  }
104  }
105  }
106 }
107 
108 
109 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
110 
112 {
113  if (processorCase_)
114  {
115  return ".."/system();
116  }
117  else
118  {
119  return system();
120  }
121 }
122 
123 
125 {
126  if (processorCase_)
127  {
128  return ".."/constant();
129  }
130  else
131  {
132  return constant();
133  }
134 }
135 
136 
137 
138 // ************************************************************************* //
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
graph_traits< Graph >::vertices_size_type size_type
Definition: SloanRenumber.C:73
static const word constantName
Definition: TimePaths.H:62
static const word systemName
Definition: TimePaths.H:61
TimePaths(const fileName &rootPath, const fileName &caseName)
Construct given database name, rootPath and casePath.
Definition: TimePaths.C:41
fileName caseConstant() const
Return constant name for the case.
Definition: TimePaths.C:124
fileName caseSystem() const
Return system name for the case.
Definition: TimePaths.C:111
bool processorCase() const
Return true if this is a processor case.
Definition: TimePaths.H:88
const fileName & caseName() const
Return case name.
Definition: TimePaths.H:106
A class for handling file names.
Definition: fileName.H:82
Namespace for OpenFOAM.
int system(const std::string &command)
Execute the specified command.
Definition: POSIX.C:1230
dimensionedScalar pos(const dimensionedScalar &ds)