fileName.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011-2014 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 Class
25  Foam::fileName
26 
27 Description
28  A class for handling file names.
29 
30  A fileName is a string of characters without whitespace or quotes.
31  A fileName can be
32  - constructed from a char*, a string or a word
33  - concatenated by adding a '/' separator
34  - decomposed into the path, name or component list
35  - interrogated for type and access mode
36 
37  The string::expand() method expands environment variables, etc,
38 
39 SourceFiles
40  fileName.C
41  fileNameIO.C
42 
43 \*---------------------------------------------------------------------------*/
44 
45 #ifndef fileName_H
46 #define fileName_H
47 
48 #include "word.H"
49 
50 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
51 
52 namespace Foam
53 {
54 
55 template<class T> class List;
56 typedef List<word> wordList;
57 
58 // Forward declaration of friend functions and operators
59 
60 class fileName;
61 
64 
65 
66 /*---------------------------------------------------------------------------*\
67  Class fileName Declaration
68 \*---------------------------------------------------------------------------*/
69 
70 class fileName
71 :
72  public string
73 {
74  // Private Member Functions
75 
76  //- Strip invalid characters
77  inline void stripInvalid();
78 
79 
80 public:
81 
82  //- Enumerations to handle file types and modes.
83  enum Type
84  {
88  LINK
89  };
90 
91 
92  // Static data members
93 
94  static const char* const typeName;
95  static int debug;
96 
97  //- An empty fileName
98  static const fileName null;
99 
100 
101  // Constructors
102 
103  //- Construct null
104  inline fileName();
105 
106  //- Construct as copy
107  inline fileName(const fileName&);
108 
109  //- Construct as copy of word
110  inline fileName(const word&);
111 
112  //- Construct as copy of string
113  inline fileName(const string&);
114 
115  //- Construct as copy of std::string
116  inline fileName(const std::string&);
117 
118  //- Construct as copy of character array
119  inline fileName(const char*);
120 
121  //- Construct by concatenating elements of wordList separated by '/'
122  explicit fileName(const wordList&);
123 
124  //- Construct from Istream
125  fileName(Istream&);
126 
127 
128  // Member functions
129 
130  //- Is this character valid for a fileName?
131  inline static bool valid(char);
132 
133  //- Cleanup file name
134  // eg, remove repeated slashes, etc.
135  bool clean();
136 
137  //- Cleanup file name
138  // eg, remove repeated slashes, etc.
139  fileName clean() const;
140 
141 
142  // Interrogation
143 
144  //- Return the file type: FILE, DIRECTORY or UNDEFINED
145  Type type() const;
146 
147  //- Return true if file name is absolute
148  bool isAbsolute() const;
149 
150  //- Convert from relative to absolute
151  fileName& toAbsolute();
152 
153 
154  // Decomposition
155 
156  //- Return file name (part beyond last /)
157  word name() const;
158 
159  //- Return file name (part beyond last /), subsitute for FOAM_CASE
160  string caseName() const;
161 
162  //- Return file name, optionally without extension
163  word name(const bool noExt) const;
164 
165  //- Return directory path name (part before last /)
166  fileName path() const;
167 
168  //- Return file name without extension (part before last .)
169  fileName lessExt() const;
170 
171  //- Return file name extension (part after last .)
172  word ext() const;
173 
174  //- Return path components as wordList
175  wordList components(const char delimiter='/') const;
176 
177  //- Return a single component of the path
178  word component(const size_type, const char delimiter='/') const;
179 
180 
181  // Member operators
182 
183  // Assignment
184 
185  const fileName& operator=(const fileName&);
186  const fileName& operator=(const word&);
187  const fileName& operator=(const string&);
188  const fileName& operator=(const std::string&);
189  const fileName& operator=(const char*);
190 
191 
192  // IOstream operators
193 
194  friend Istream& operator>>(Istream&, fileName&);
195  friend Ostream& operator<<(Ostream&, const fileName&);
196 };
197 
198 
199 //- Assemble words and fileNames as pathnames by adding a '/' separator
200 fileName operator/(const string&, const string&);
201 
202 
203 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
204 
205 } // End namespace Foam
206 
207 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
208 
209 #include "fileNameI.H"
210 
211 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
212 
213 #endif
214 
215 // ************************************************************************* //
Foam::fileName::FILE
@ FILE
Definition: fileName.H:85
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
Foam::fileName::components
wordList components(const char delimiter='/') const
Return path components as wordList.
Definition: fileName.C:357
Foam::fileName::path
fileName path() const
Return directory path name (part before last /)
Definition: fileName.C:293
Foam::fileName::debug
static int debug
Definition: fileName.H:94
Foam::fileName::isAbsolute
bool isAbsolute() const
Return true if file name is absolute.
Definition: fileName.C:57
Foam::fileName::Type
Type
Enumerations to handle file types and modes.
Definition: fileName.H:82
Foam::fileName::lessExt
fileName lessExt() const
Return file name without extension (part before last .)
Definition: fileName.C:313
Foam::string
A class for handling character strings derived from std::string.
Definition: string.H:74
Foam::fileName::fileName
fileName()
Construct null.
Definition: fileNameI.H:52
Foam::fileName::toAbsolute
fileName & toAbsolute()
Convert from relative to absolute.
Definition: fileName.C:69
Foam::fileName::name
word name() const
Return file name (part beyond last /)
Definition: fileName.C:212
Foam::fileName::component
word component(const size_type, const char delimiter='/') const
Return a single component of the path.
Definition: fileName.C:386
Foam::wordList
List< word > wordList
A List of words.
Definition: fileName.H:54
Foam::fileName::type
Type type() const
Return the file type: FILE, DIRECTORY or UNDEFINED.
Definition: fileName.C:51
Foam::fileName::typeName
static const char *const typeName
Definition: fileName.H:93
Foam::fileName::operator=
const fileName & operator=(const fileName &)
Definition: fileName.C:397
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:57
size_type
graph_traits< Graph >::vertices_size_type size_type
Definition: SloanRenumber.C:73
Foam::operator<<
Ostream & operator<<(Ostream &, const edgeMesh &)
Definition: edgeMeshIO.C:130
Foam::fileName::operator>>
friend Istream & operator>>(Istream &, fileName &)
fileNameI.H
Foam::fileName::ext
word ext() const
Return file name extension (part after last .)
Definition: fileName.C:329
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::operator/
dimensionedScalar operator/(const scalar s1, const dimensionedScalar &ds2)
Definition: dimensionedScalar.C:65
Foam::fileName::stripInvalid
void stripInvalid()
Strip invalid characters.
Definition: fileNameI.H:28
Foam::fileName::LINK
@ LINK
Definition: fileName.H:87
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Foam::fileName::operator<<
friend Ostream & operator<<(Ostream &, const fileName &)
Foam::fileName::DIRECTORY
@ DIRECTORY
Definition: fileName.H:86
Foam::operator>>
Istream & operator>>(Istream &, edgeMesh &)
Definition: edgeMeshIO.C:141
Foam::fileName::caseName
string caseName() const
Return file name (part beyond last /), subsitute for FOAM_CASE.
Definition: fileName.C:227
Foam::fileName::valid
static bool valid(char)
Is this character valid for a fileName?
Definition: fileNameI.H:94
Foam::fileName::clean
bool clean()
Cleanup file name.
Definition: fileName.C:97
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:53
word.H
Foam::fileName::UNDEFINED
@ UNDEFINED
Definition: fileName.H:84