FreeFOAM The Cross-Platform CFD Toolkit
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) 1991-2010 OpenCFD Ltd.
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 can be
31  - constructed from a char*, a string or a word
32  - concatenated by adding a '/' separator
33  - decomposed into the path, name or component list
34  - interrogated for type and access mode
35 
36  The string::expand() method expands environment variables, etc,
37 
38 SourceFiles
39  fileName.C
40  fileNameIO.C
41 
42 \*---------------------------------------------------------------------------*/
43 
44 #ifndef fileName_H
45 #define fileName_H
46 
47 #include <OpenFOAM/word.H>
48 
49 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
50 
51 namespace Foam
52 {
53 
54 template<class T> class List;
55 typedef List<word> wordList;
56 
57 // Forward declaration of friend functions and operators
58 
59 class fileName;
60 
61 Istream& operator>>(Istream&, fileName&);
62 Ostream& operator<<(Ostream&, const fileName&);
63 
64 
65 /*---------------------------------------------------------------------------*\
66  Class fileName Declaration
67 \*---------------------------------------------------------------------------*/
68 
69 class fileName
70 :
71  public string
72 {
73  // Private member functions
74 
75  //- Strip invalid characters
76  inline void stripInvalid();
77 
78 
79 public:
80 
81  //- Enumerations to handle file types and modes.
82  enum Type
83  {
88  };
89 
90 
91  // Static data members
92 
93  static const char* const typeName;
94  static int debug;
95  static const fileName null;
96 
97 
98  // Constructors
99 
100  //- Construct null
101  inline fileName();
102 
103  //- Construct as copy
104  inline fileName(const fileName&);
105 
106  //- Construct as copy of word
107  inline fileName(const word&);
108 
109  //- Construct as copy of string
110  inline fileName(const string&);
111 
112  //- Construct as copy of std::string
113  inline fileName(const std::string&);
114 
115  //- Construct as copy of character array
116  inline fileName(const char*);
117 
118  //- Construct by concatenating elements of wordList separated by '/'
119  explicit fileName(const wordList&);
120 
121  //- Construct from Istream
122  fileName(Istream&);
123 
124 
125  // Member functions
126 
127  //- Is this character valid for a fileName?
128  inline static bool valid(char);
129 
130  //- Cleanup file name
131  // eg, remove repeated slashes, etc.
132  bool clean();
133 
134  //- Cleanup file name
135  // eg, remove repeated slashes, etc.
136  fileName clean() const;
137 
138  // Interogation
139 
140  //- Return the file type: FILE, DIRECTORY or UNDEFINED
141  Type type() const;
142 
143  // Decomposition
144 
145  //- Return file name (part beyond last /)
146  word name() const;
147 
148  //- Return directory path name (part before last /)
149  fileName path() const;
150 
151  //- Return file name without extension (part before last .)
152  fileName lessExt() const;
153 
154  //- Return file name extension (part after last .)
155  word ext() const;
156 
157  //- Return path components as wordList
158  wordList components(const char delimiter='/') const;
159 
160  //- Return a single component of the path
161  word component(const size_type, const char delimiter='/') const;
162 
163  // Member operators
164 
165  // Assignment
166 
167  const fileName& operator=(const fileName&);
168  const fileName& operator=(const word&);
169  const fileName& operator=(const string&);
170  const fileName& operator=(const std::string&);
171  const fileName& operator=(const char*);
172 
173 
174  // IOstream operators
175 
176  friend Istream& operator>>(Istream&, fileName&);
177  friend Ostream& operator<<(Ostream&, const fileName&);
178 };
179 
180 
181 //- Assemble words and fileNames as pathnames by adding a '/' separator
182 fileName operator/(const string&, const string&);
183 
184 
185 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
186 
187 } // End namespace Foam
188 
189 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
190 
191 #include <OpenFOAM/fileNameI.H>
192 
193 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
194 
195 #endif
196 
197 // ************************ vim: set sw=4 sts=4 et: ************************ //