メインページ   クラス階層   構成   ファイル一覧   構成メンバ   ファイルメンバ  

file-stat.h

解説を見る。
00001 /*
00002 
00003 Copyright (C) 1996, 1997 John W. Eaton
00004 
00005 This file is part of Octave.
00006 
00007 Octave is free software; you can redistribute it and/or modify it
00008 under the terms of the GNU General Public License as published by the
00009 Free Software Foundation; either version 2, or (at your option) any
00010 later version.
00011 
00012 Octave is distributed in the hope that it will be useful, but WITHOUT
00013 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00015 for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with Octave; see the file COPYING.  If not, write to the Free
00019 Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00020 
00021 */
00022 
00023 #if !defined (octave_file_stat_h)
00024 #define octave_file_stat_h 1
00025 
00026 #include <string>
00027 
00028 #include "oct-time.h"
00029 
00030 #ifdef HAVE_SYS_TYPES_H
00031 #include <sys/types.h>
00032 #endif
00033 
00034 class
00035 file_stat
00036 {
00037 public:
00038 
00039   file_stat (const std::string& n = std::string (), bool fl = true)
00040     : file_name (n), follow_links (fl), initialized (false)
00041       {
00042         if (! file_name.empty ())
00043           update_internal ();
00044       }
00045 
00046   file_stat (const file_stat& f) { copy (f); }
00047 
00048   file_stat& operator = (const file_stat& f)
00049     {
00050       if (this != &f)
00051         copy (f);
00052 
00053       return *this;
00054     }
00055 
00056   ~file_stat (void) { }
00057 
00058   void get_stats (bool force = false)
00059     {
00060       if (! initialized || force)
00061         update_internal (force);
00062     }
00063 
00064   void get_stats (const std::string& n, bool force = false)
00065     {
00066       if (n != file_name || ! initialized  || force)
00067         {
00068           initialized = false;
00069 
00070           file_name = n;
00071 
00072           update_internal (force);
00073         }
00074     }
00075 
00076   // File status and info.  These should only be called for objects
00077   // that are already properly initialized.
00078 
00079   bool is_blk (void) const;
00080   bool is_chr (void) const;
00081   bool is_dir (void) const;
00082   bool is_fifo (void) const;
00083   bool is_lnk (void) const;
00084   bool is_reg (void) const;
00085   bool is_sock (void) const;
00086 
00087   ino_t ino (void) const { return fs_ino; }
00088   dev_t dev (void) const { return fs_dev; }
00089 
00090   nlink_t nlink (void) const { return fs_nlink; }
00091 
00092   uid_t uid (void) const { return fs_uid; }
00093   gid_t gid (void) const { return fs_gid; }
00094 
00095   off_t size (void) const { return fs_size; }
00096 
00097   octave_time atime (void) const { return fs_atime; }
00098   octave_time mtime (void) const { return fs_mtime; }
00099   octave_time ctime (void) const { return fs_ctime; }
00100 
00101 #if defined (HAVE_STRUCT_STAT_ST_RDEV)
00102   dev_t rdev (void) const { return fs_rdev; }
00103 #endif
00104 
00105 #if defined (HAVE_STRUCT_STAT_ST_BLKSIZE)
00106   long blksize (void) const { return fs_blksize; }
00107 #endif
00108 
00109 #if defined (HAVE_STRUCT_STAT_ST_BLOCKS)
00110   long blocks (void) const { return fs_blocks; }
00111 #endif
00112 
00113   std::string mode_as_string (void) const;
00114 
00115   bool ok (void) const { return initialized && ! fail; }
00116 
00117   operator bool () const { return ok (); }
00118 
00119   bool exists (void) const { return ok (); }
00120 
00121   std::string error (void) const { return ok () ? std::string () : errmsg; }
00122 
00123   // Has the file referenced by this object been modified since TIME?
00124   bool is_newer (const octave_time& time) const { return fs_mtime > time; }
00125 
00126   // It's nice to be able to hide the file_stat object if we don't
00127   // really care about it.
00128   static int is_newer (const std::string&, const octave_time&);
00129 
00130 private:
00131 
00132   // Name of the file.
00133   std::string file_name;
00134 
00135   // TRUE means follow symbolic links to the ultimate file (stat).
00136   // FALSE means get information about the link itself (lstat).
00137   bool follow_links;
00138 
00139   // TRUE means we have already called stat.
00140   bool initialized;
00141 
00142   // TRUE means the stat for this file failed.
00143   bool fail;
00144 
00145   // If a failure occurs, this contains the system error text.
00146   std::string errmsg;
00147 
00148   // file type and permissions
00149   mode_t fs_mode;
00150 
00151   // serial number
00152   ino_t fs_ino;
00153 
00154   // device number
00155   dev_t fs_dev;
00156 
00157   // number of links
00158   nlink_t fs_nlink;
00159 
00160   // user ID of owner
00161   uid_t fs_uid;
00162 
00163   // group ID of owner
00164   gid_t fs_gid;
00165 
00166   // size in bytes, for regular files
00167   off_t fs_size;
00168 
00169   // time of last access
00170   octave_time fs_atime;
00171 
00172   // time of last modification
00173   octave_time fs_mtime;
00174 
00175   // time of last file status change
00176   octave_time fs_ctime;
00177 
00178 #if defined (HAVE_STRUCT_STAT_ST_RDEV)
00179   // device number for special files
00180   dev_t fs_rdev;
00181 #endif
00182 
00183 #if defined (HAVE_STRUCT_STAT_ST_BLKSIZE)
00184   // best I/O block size
00185   long fs_blksize;
00186 #endif
00187 
00188 #if defined (HAVE_STRUCT_STAT_ST_BLOCKS)
00189   // number of 512-byte blocks allocated
00190   long fs_blocks;
00191 #endif
00192 
00193   void update_internal (bool force = false);
00194 
00195   void copy (const file_stat&);
00196 };
00197 
00198 #endif
00199 
00200 /*
00201 ;;; Local Variables: ***
00202 ;;; mode: C++ ***
00203 ;;; End: ***
00204 */

Wed Dec 29 11:51:35 2004に生成されました。 doxygen1.2.18
SEO [PR] 爆速!無料ブログ 無料ホームページ開設 無料ライブ放送