1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 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, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 A class for handling file names.
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;
96 static const fileName null;
104 //- Construct as copy
105 inline fileName(const fileName&);
107 //- Construct as copy of word
108 inline fileName(const word&);
110 //- Construct as copy of string
111 inline fileName(const string&);
113 //- Construct as copy of std::string
114 inline fileName(const std::string&);
116 //- Construct as copy of character array
117 inline fileName(const char*);
119 //- Construct by concatenating elements of wordList separated by '/'
120 explicit fileName(const wordList&);
122 //- Construct from Istream
128 //- Is this character valid for a fileName?
129 inline static bool valid(char);
131 //- Cleanup file name
132 // eg, remove repeated slashes, etc.
135 //- Cleanup file name
136 // eg, remove repeated slashes, etc.
137 fileName clean() const;
141 //- Return the file type: FILE, DIRECTORY or UNDEFINED
146 //- Return file name (part beyond last /)
149 //- Return directory path name (part before last /)
150 fileName path() const;
152 //- Return file name without extension (part before last .)
153 fileName lessExt() const;
155 //- Return file name extension (part after last .)
158 //- Return path components as wordList
159 wordList components(const char delimiter='/') const;
161 //- Return a single component of the path
162 word component(const size_type, const char delimiter='/') const;
168 const fileName& operator=(const fileName&);
169 const fileName& operator=(const word&);
170 const fileName& operator=(const string&);
171 const fileName& operator=(const std::string&);
172 const fileName& operator=(const char*);
175 // IOstream operators
177 friend Istream& operator>>(Istream&, fileName&);
178 friend Ostream& operator<<(Ostream&, const fileName&);
182 //- Assemble words and fileNames as pathnames by adding a '/' separator
183 fileName operator/(const string&, const string&);
186 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
188 } // End namespace Foam
190 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
192 #include "fileNameI.H"
194 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
198 // ************************************************************************* //