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

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