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

fileStat.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::fileStat
00026 
00027 Description
00028     Wrapper for stat() system call.
00029 
00030 Warning
00031     on Linux (an maybe on others) a stat() of an nfs mounted (remote)
00032     file does never timeout and cannot be interrupted!
00033     So e.g. Foam::ping first and hope nfs is running.
00034 
00035 SourceFiles
00036     fileStat.C
00037 
00038 \*---------------------------------------------------------------------------*/
00039 
00040 #ifndef fileStat_H
00041 #define fileStat_H
00042 
00043 #include <sys/stat.h>
00044 #include <sys/types.h>
00045 
00046 #include <OpenFOAM/label.H>
00047 #include <OpenFOAM/fileName.H>
00048 
00049 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00050 
00051 namespace Foam
00052 {
00053 
00054 // Forward declaration of friend functions and operators
00055 
00056 class fileStat;
00057 
00058 Istream& operator>>(Istream&, fileStat&);
00059 Ostream& operator<<(Ostream&, const fileStat&);
00060 
00061 
00062 /*---------------------------------------------------------------------------*\
00063                            Class fileStat Declaration
00064 \*---------------------------------------------------------------------------*/
00065 
00066 class fileStat
00067 {
00068     // Private data
00069 
00070         struct stat status_;
00071 
00072         bool isValid_;
00073 
00074 
00075 public:
00076 
00077     // Constructors
00078 
00079         //- Empty constructor
00080         fileStat();
00081 
00082         //- Construct from components
00083         fileStat(const fileName& fName, const unsigned int maxTime=0);
00084 
00085         //- Construct from Istream
00086         fileStat(Istream&);
00087 
00088 
00089     // Member Functions
00090 
00091         // Access
00092 
00093             //- Raw status
00094             const struct stat& status() const
00095             {
00096                 return status_;
00097             }
00098 
00099             //- Did constructor fail
00100             bool isValid() const
00101             {
00102                 return isValid_;
00103             }
00104 
00105 
00106         // Check
00107 
00108             //- compare two fileStats for same device
00109             bool sameDevice(const fileStat& stat2) const;
00110 
00111             //- compare two fileStats for same Inode
00112             bool sameINode(const fileStat& stat2) const;
00113 
00114             //- compare state against inode
00115             bool sameINode(const label iNode) const;
00116 
00117 
00118     // IOstream Operators
00119 
00120         friend Istream& operator>>(Istream&, fileStat&);
00121         friend Ostream& operator<<(Ostream&, const fileStat&);
00122 };
00123 
00124 
00125 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00126 
00127 } // End namespace Foam
00128 
00129 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00130 
00131 #endif
00132 
00133 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines