initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / OpenFOAM / primitives / strings / fileName / fileName.H
blob709e70920bd4713649b9a13ed4f935ac766acc80
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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
25 Class
26     Foam::fileName
28 Description
29     A class for handling file names.
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
37     The string::expand() method expands environment variables, etc,
39 SourceFiles
40     fileName.C
41     fileNameIO.C
43 \*---------------------------------------------------------------------------*/
45 #ifndef fileName_H
46 #define fileName_H
48 #include "word.H"
50 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
52 namespace Foam
55 template<class T> class List;
56 typedef List<word> wordList;
58 // Forward declaration of friend functions and operators
60 class fileName;
62 Istream& operator>>(Istream&, fileName&);
63 Ostream& operator<<(Ostream&, const fileName&);
66 /*---------------------------------------------------------------------------*\
67                           Class fileName Declaration
68 \*---------------------------------------------------------------------------*/
70 class fileName
72     public string
74     // Private member functions
76         //- Strip invalid characters
77         inline void stripInvalid();
80 public:
82     //- Enumerations to handle file types and modes.
83     enum Type
84     {
85         UNDEFINED,
86         FILE,
87         DIRECTORY,
88         LINK
89     };
92     // Static data members
94         static const char* const typeName;
95         static int debug;
96         static const fileName null;
99     // Constructors
101         //- Construct null
102         inline fileName();
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
123         fileName(Istream&);
126     // Member functions
128         //- Is this character valid for a fileName?
129         inline static bool valid(char);
131         //- Cleanup file name
132         //  eg, remove repeated slashes, etc.
133         bool clean();
135         //- Cleanup file name
136         //  eg, remove repeated slashes, etc.
137         fileName clean() const;
139         // Interogation
141             //- Return the file type: FILE, DIRECTORY or UNDEFINED
142             Type type() const;
144         // Decomposition
146             //- Return file name (part beyond last /)
147             word name() const;
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 .)
156             word ext() const;
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;
164     // Member operators
166         // Assignment
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 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
196 #endif
198 // ************************************************************************* //