OpenFOAM logo
Open Source CFD Toolkit

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-2005 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     fileName
00027 
00028 Description
00029     A class for handling file names.
00030     A fileName can be  constructed from a char* or a word.
00031     FileNames may be concaternated by adding a '/' separator.
00032     FileNames may be decomposed into the path, name or component
00033     list. FileNames may be interogated for type and access mode.
00034 
00035 SourceFiles
00036     fileName.C
00037     fileNameIO.C
00038 
00039 \*---------------------------------------------------------------------------*/
00040 
00041 #ifndef fileName_H
00042 #define fileName_H
00043 
00044 #include "word.H"
00045 
00046 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00047 
00048 namespace Foam
00049 {
00050 
00051 template<class T> class List;
00052 typedef List<word> wordList;
00053 
00054 /*---------------------------------------------------------------------------*\
00055                            Class fileName Declaration
00056 \*---------------------------------------------------------------------------*/
00057 
00058 class fileName
00059 :
00060     public string
00061 {
00062     // Private member functions
00063 
00064         //- Strip invalid characters from this word
00065         inline void stripInvalid();
00066 
00067 
00068 public:
00069 
00070     //- Enumerations to handle file types and modes.
00071     enum Type
00072     {
00073         UNDEFINED,
00074         FILE,
00075         DIRECTORY,
00076         LINK
00077     };
00078 
00079     //- Debug switch
00080     static int debug;
00081 
00082     //- Null fileName
00083     static const fileName null;
00084 
00085 
00086     // Constructors
00087 
00088         //- Construct null
00089         inline fileName();
00090 
00091         //- Construct as copy
00092         inline fileName(const fileName& fn);
00093 
00094         //- Construct as copy of word
00095         inline fileName(const word& w);
00096 
00097         //- Construct as copy of string
00098         inline fileName(const string& s);
00099 
00100         //- Construct as copy of std::string
00101         inline fileName(const std::string& s);
00102 
00103         //- Construct as copy of character array
00104         inline fileName(const char*);
00105 
00106         //- Construct by concatonating elements of wordList separated by '/'
00107         explicit fileName(const wordList&);
00108 
00109         //- Construct from Istream
00110         fileName(Istream&);
00111 
00112 
00113     // Member functions
00114 
00115         //- Is this character valid for a fileName
00116         inline static bool valid(char);
00117 
00118 
00119         // Decomposition
00120 
00121             //- Return file name (part beyond last /)
00122             word name() const;
00123 
00124             //- Return directory path name (part before last /)
00125             fileName path() const;
00126 
00127             //- Return file name without extension (part before last .)
00128             fileName lessExt() const;
00129 
00130             //- Return file name extension (part after last .)
00131             word ext() const;
00132 
00133             //- Return path components as wordList
00134             wordList components(const char delimiter='/') const;
00135 
00136             //- Return a component of the path
00137             word component(const size_t, const char delimiter='/') const;
00138 
00139 
00140         // Interogation
00141 
00142             //- Return file type
00143             Type type() const;
00144 
00145 
00146     // Member operators
00147 
00148         // Assignment
00149 
00150             void operator=(const fileName&);
00151             void operator=(const word&);
00152             void operator=(const string&);
00153             void operator=(const std::string&);
00154             void operator=(const char*);
00155 
00156 
00157     // IOstream operators
00158 
00159         friend Istream& operator>>(Istream&, fileName&);
00160         friend Ostream& operator<<(Ostream&, const fileName&);
00161 };
00162 
00163 
00164 //- Assemble words and fileNames as pathnames by adding a '/' separator
00165 fileName operator/(const string&, const string&);
00166 
00167 
00168 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00169 
00170 } // End namespace Foam
00171 
00172 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00173 
00174 #include "fileNameI.H"
00175 
00176 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00177 
00178 #endif
00179 
00180 // ************************************************************************* //
For further information go to www.openfoam.org