OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

fileName.H

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 Class
00026     Foam::fileName
00027 
00028 Description
00029     A class for handling file names.
00030 
00031     A fileName can be
00032       - constructed from a char*, a string or a word
00033       - concatenated by adding a '/' separator
00034       - decomposed into the path, name or component list
00035       - interrogated for type and access mode
00036 
00037     The string::expand() method expands environment variables, etc,
00038 
00039 SourceFiles
00040     fileName.C
00041     fileNameIO.C
00042 
00043 \*---------------------------------------------------------------------------*/
00044 
00045 #ifndef fileName_H
00046 #define fileName_H
00047 
00048 #include "word.H"
00049 
00050 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00051 
00052 namespace Foam
00053 {
00054 
00055 template<class T> class List;
00056 typedef List<word> wordList;
00057 
00058 // Forward declaration of friend functions and operators
00059 
00060 class fileName;
00061 
00062 Istream& operator>>(Istream&, fileName&);
00063 Ostream& operator<<(Ostream&, const fileName&);
00064 
00065 
00066 /*---------------------------------------------------------------------------*\
00067                           Class fileName Declaration
00068 \*---------------------------------------------------------------------------*/
00069 
00070 class fileName
00071 :
00072     public string
00073 {
00074     // Private member functions
00075 
00076         //- Strip invalid characters
00077         inline void stripInvalid();
00078 
00079 
00080 public:
00081 
00082     //- Enumerations to handle file types and modes.
00083     enum Type
00084     {
00085         UNDEFINED,
00086         FILE,
00087         DIRECTORY,
00088         LINK
00089     };
00090 
00091 
00092     // Static data members
00093 
00094         static const char* const typeName;
00095         static int debug;
00096         static const fileName null;
00097 
00098 
00099     // Constructors
00100 
00101         //- Construct null
00102         inline fileName();
00103 
00104         //- Construct as copy
00105         inline fileName(const fileName&);
00106 
00107         //- Construct as copy of word
00108         inline fileName(const word&);
00109 
00110         //- Construct as copy of string
00111         inline fileName(const string&);
00112 
00113         //- Construct as copy of std::string
00114         inline fileName(const std::string&);
00115 
00116         //- Construct as copy of character array
00117         inline fileName(const char*);
00118 
00119         //- Construct by concatenating elements of wordList separated by '/'
00120         explicit fileName(const wordList&);
00121 
00122         //- Construct from Istream
00123         fileName(Istream&);
00124 
00125 
00126     // Member functions
00127 
00128         //- Is this character valid for a fileName?
00129         inline static bool valid(char);
00130 
00131         //- Cleanup file name
00132         //  eg, remove repeated slashes, etc.
00133         bool clean();
00134 
00135         //- Cleanup file name
00136         //  eg, remove repeated slashes, etc.
00137         fileName clean() const;
00138 
00139         // Interogation
00140 
00141             //- Return the file type: FILE, DIRECTORY or UNDEFINED
00142             Type type() const;
00143 
00144         // Decomposition
00145 
00146             //- Return file name (part beyond last /)
00147             word name() const;
00148 
00149             //- Return directory path name (part before last /)
00150             fileName path() const;
00151 
00152             //- Return file name without extension (part before last .)
00153             fileName lessExt() const;
00154 
00155             //- Return file name extension (part after last .)
00156             word ext() const;
00157 
00158             //- Return path components as wordList
00159             wordList components(const char delimiter='/') const;
00160 
00161             //- Return a single component of the path
00162             word component(const size_type, const char delimiter='/') const;
00163 
00164     // Member operators
00165 
00166         // Assignment
00167 
00168             const fileName& operator=(const fileName&);
00169             const fileName& operator=(const word&);
00170             const fileName& operator=(const string&);
00171             const fileName& operator=(const std::string&);
00172             const fileName& operator=(const char*);
00173 
00174 
00175     // IOstream operators
00176 
00177         friend Istream& operator>>(Istream&, fileName&);
00178         friend Ostream& operator<<(Ostream&, const fileName&);
00179 };
00180 
00181 
00182 //- Assemble words and fileNames as pathnames by adding a '/' separator
00183 fileName operator/(const string&, const string&);
00184 
00185 
00186 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00187 
00188 } // End namespace Foam
00189 
00190 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00191 
00192 #include "fileNameI.H"
00193 
00194 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00195 
00196 #endif
00197 
00198 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd