1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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.
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
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/>.
28 A class for handling file names.
30 A fileName is a string of characters without whitespace or quotes.
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
37 The string::expand() method expands environment variables, etc,
43 \*---------------------------------------------------------------------------*/
50 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
55 template<class T> class List;
56 typedef List<word> wordList;
58 // Forward declaration of friend functions and operators
62 Istream& operator>>(Istream&, fileName&);
63 Ostream& operator<<(Ostream&, const fileName&);
66 /*---------------------------------------------------------------------------*\
67 Class fileName Declaration
68 \*---------------------------------------------------------------------------*/
74 // Private Member Functions
76 //- Strip invalid characters
77 inline void stripInvalid();
82 //- Enumerations to handle file types and modes.
92 // Static data members
94 static const char* const typeName;
98 static const fileName null;
106 //- Construct as copy
107 inline fileName(const fileName&);
109 //- Construct as copy of word
110 inline fileName(const word&);
112 //- Construct as copy of string
113 inline fileName(const string&);
115 //- Construct as copy of std::string
116 inline fileName(const std::string&);
118 //- Construct as copy of character array
119 inline fileName(const char*);
121 //- Construct by concatenating elements of wordList separated by '/'
122 explicit fileName(const wordList&);
124 //- Construct from Istream
130 //- Is this character valid for a fileName?
131 inline static bool valid(char);
133 //- Cleanup file name
134 // eg, remove repeated slashes, etc.
137 //- Cleanup file name
138 // eg, remove repeated slashes, etc.
139 fileName clean() const;
144 //- Return the file type: FILE, DIRECTORY or UNDEFINED
147 //- Return true if file name is absolute
148 bool isAbsolute() const;
153 //- Return file name (part beyond last /)
156 //- Return file name, optionally without extension
157 word name(const bool noExt) const;
159 //- Return directory path name (part before last /)
160 fileName path() const;
162 //- Return file name without extension (part before last .)
163 fileName lessExt() const;
165 //- Return file name extension (part after last .)
168 //- Return path components as wordList
169 wordList components(const char delimiter='/') const;
171 //- Return a single component of the path
172 word component(const size_type, const char delimiter='/') const;
179 const fileName& operator=(const fileName&);
180 const fileName& operator=(const word&);
181 const fileName& operator=(const string&);
182 const fileName& operator=(const std::string&);
183 const fileName& operator=(const char*);
186 // IOstream operators
188 friend Istream& operator>>(Istream&, fileName&);
189 friend Ostream& operator<<(Ostream&, const fileName&);
193 //- Assemble words and fileNames as pathnames by adding a '/' separator
194 fileName operator/(const string&, const string&);
197 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
199 } // End namespace Foam
201 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
203 #include "fileNameI.H"
205 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
209 // ************************************************************************* //