FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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-2010 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
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your 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, see <http://www.gnu.org/licenses/>.
00023 
00024 Class
00025     Foam::fileName
00026 
00027 Description
00028     A class for handling file names.
00029 
00030     A fileName can be
00031       - constructed from a char*, a string or a word
00032       - concatenated by adding a '/' separator
00033       - decomposed into the path, name or component list
00034       - interrogated for type and access mode
00035 
00036     The string::expand() method expands environment variables, etc,
00037 
00038 SourceFiles
00039     fileName.C
00040     fileNameIO.C
00041 
00042 \*---------------------------------------------------------------------------*/
00043 
00044 #ifndef fileName_H
00045 #define fileName_H
00046 
00047 #include <OpenFOAM/word.H>
00048 
00049 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00050 
00051 namespace Foam
00052 {
00053 
00054 template<class T> class List;
00055 typedef List<word> wordList;
00056 
00057 // Forward declaration of friend functions and operators
00058 
00059 class fileName;
00060 
00061 Istream& operator>>(Istream&, fileName&);
00062 Ostream& operator<<(Ostream&, const fileName&);
00063 
00064 
00065 /*---------------------------------------------------------------------------*\
00066                           Class fileName Declaration
00067 \*---------------------------------------------------------------------------*/
00068 
00069 class fileName
00070 :
00071     public string
00072 {
00073     // Private member functions
00074 
00075         //- Strip invalid characters
00076         inline void stripInvalid();
00077 
00078 
00079 public:
00080 
00081     //- Enumerations to handle file types and modes.
00082     enum Type
00083     {
00084         UNDEFINED,
00085         FILE,
00086         DIRECTORY,
00087         LINK
00088     };
00089 
00090 
00091     // Static data members
00092 
00093         static const char* const typeName;
00094         static int debug;
00095         static const fileName null;
00096 
00097 
00098     // Constructors
00099 
00100         //- Construct null
00101         inline fileName();
00102 
00103         //- Construct as copy
00104         inline fileName(const fileName&);
00105 
00106         //- Construct as copy of word
00107         inline fileName(const word&);
00108 
00109         //- Construct as copy of string
00110         inline fileName(const string&);
00111 
00112         //- Construct as copy of std::string
00113         inline fileName(const std::string&);
00114 
00115         //- Construct as copy of character array
00116         inline fileName(const char*);
00117 
00118         //- Construct by concatenating elements of wordList separated by '/'
00119         explicit fileName(const wordList&);
00120 
00121         //- Construct from Istream
00122         fileName(Istream&);
00123 
00124 
00125     // Member functions
00126 
00127         //- Is this character valid for a fileName?
00128         inline static bool valid(char);
00129 
00130         //- Cleanup file name
00131         //  eg, remove repeated slashes, etc.
00132         bool clean();
00133 
00134         //- Cleanup file name
00135         //  eg, remove repeated slashes, etc.
00136         fileName clean() const;
00137 
00138         // Interogation
00139 
00140             //- Return the file type: FILE, DIRECTORY or UNDEFINED
00141             Type type() const;
00142 
00143         // Decomposition
00144 
00145             //- Return file name (part beyond last /)
00146             word name() const;
00147 
00148             //- Return directory path name (part before last /)
00149             fileName path() const;
00150 
00151             //- Return file name without extension (part before last .)
00152             fileName lessExt() const;
00153 
00154             //- Return file name extension (part after last .)
00155             word ext() const;
00156 
00157             //- Return path components as wordList
00158             wordList components(const char delimiter='/') const;
00159 
00160             //- Return a single component of the path
00161             word component(const size_type, const char delimiter='/') const;
00162 
00163     // Member operators
00164 
00165         // Assignment
00166 
00167             const fileName& operator=(const fileName&);
00168             const fileName& operator=(const word&);
00169             const fileName& operator=(const string&);
00170             const fileName& operator=(const std::string&);
00171             const fileName& operator=(const char*);
00172 
00173 
00174     // IOstream operators
00175 
00176         friend Istream& operator>>(Istream&, fileName&);
00177         friend Ostream& operator<<(Ostream&, const fileName&);
00178 };
00179 
00180 
00181 //- Assemble words and fileNames as pathnames by adding a '/' separator
00182 fileName operator/(const string&, const string&);
00183 
00184 
00185 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00186 
00187 } // End namespace Foam
00188 
00189 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00190 
00191 #include <OpenFOAM/fileNameI.H>
00192 
00193 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00194 
00195 #endif
00196 
00197 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines