casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
DOos.h
Go to the documentation of this file.
00001 //# DOos.h: Functions used to implement the DO functionality
00002 //# Copyright (C) 1999,2000,2001
00003 //# Associated Universities, Inc. Washington DC, USA.
00004 //#
00005 //# This library is free software; you can redistribute it and/or modify it
00006 //# under the terms of the GNU Library General Public License as published by
00007 //# the Free Software Foundation; either version 2 of the License, or (at your
00008 //# option) any later version.
00009 //#
00010 //# This library is distributed in the hope that it will be useful, but WITHOUT
00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00013 //# License for more details.
00014 //#
00015 //# You should have received a copy of the GNU Library General Public License
00016 //# along with this library; if not, write to the Free Software Foundation,
00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00018 //#
00019 //# Correspondence concerning AIPS++ should be addressed as follows:
00020 //#        Internet email: aips2-request@nrao.edu.
00021 //#        Postal address: AIPS++ Project Office
00022 //#                        National Radio Astronomy Observatory
00023 //#                        520 Edgemont Road
00024 //#                        Charlottesville, VA 22903-2475 USA
00025 //#
00026 //#
00027 //# $Id: DOos.h 20551 2009-03-25 00:11:33Z Malte.Marquarding $
00028 
00029 #ifndef CASA_DOOS_H
00030 #define CASA_DOOS_H
00031 
00032 
00033 //# Includes
00034 #include <casa/aips.h>
00035 #include <casa/Arrays/Vector.h>
00036 
00037 namespace casa { //# NAMESPACE CASA - BEGIN
00038 
00039 //# Forward Declarations
00040 class String;
00041 
00042 
00043 // <summary>
00044 // DO for accessing os-specific functions
00045 // </summary>
00046 
00047 // <use visibility=export>
00048 
00049 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
00050 // </reviewed>
00051 
00052 // <prerequisite>
00053 //   <li> <linkto module=OS>OS</linkto>
00054 // </prerequisite>
00055 
00056 // <etymology>
00057 // </etymology>
00058 
00059 // <synopsis>
00060 // This class serves as the connection between the OS module and a tasking
00061 // interface in Glish or Python.
00062 // It is meant for access to OS-specific functions, in
00063 // particular file handling.
00064 // </synopsis>
00065 
00066 // <example>
00067 // </example>
00068 
00069 // <motivation>
00070 // </motivation>
00071 
00072 // <thrown>
00073 //    <li> AipsError if AIPSPATH or HOME is not defined
00074 // </thrown>
00075 
00076 // <todo asof="1997/09/16">
00077 //   <li> Check for feasable extensions
00078 // </todo>
00079 
00080 
00081 class DOos
00082 {
00083 public:
00084   // Are the given path names valid?
00085   // I.e. does a file with the given name exist or can it be created?
00086   static Vector<Bool> isValidPathName (const Vector<String>& pathName);
00087 
00088   // Do the given files exist?
00089   // If follow is False, symbolic links are not followed.
00090   static Vector<Bool> fileExists (const Vector<String>& fileName,
00091                                   Bool follow = True);
00092 
00093   // Give the type of the given files.
00094   static Vector<String> fileType (const Vector<String>& fileName,
00095                                   Bool follow = True);
00096 
00097   // Give all file names in the directory matching the given pattern
00098   // and file types.
00099   // <br>The pattern can be a string like the filename pattern given in
00100   // a shell (e.g. '*.cc'). If the string is empty, all files are taken
00101   // into account.
00102   // <br>Filetypes is a string determining which file types will be selected.
00103   // Each character in the string determines a file type. They are:
00104   // <dl>
00105   // <dt>r<dd>regular file
00106   // <dt>d<dd>directory
00107   // <dt>s<dd>symbolic link
00108   // <dt>R<dd>readable file
00109   // <dt>W<dd>writable file
00110   // <dt>X<dd>executable file
00111   // </dl>
00112   // The all flag determines if file names starting with a . will also
00113   // be selected.
00114   static Vector<String> fileNames (const String& directoryName,
00115                                    const String& fileNamePattern,
00116                                    const String& fileTypes,
00117                                    Bool all = False,
00118                                    Bool follow = True);
00119 
00120   // Make directories. It throws an exception if a file with that
00121   // name already exists.
00122   static void makeDirectory (const Vector<String>& directoryNames,
00123                              Bool makeParent = False);
00124 
00125   // Return the full absolute names for the given names.
00126   static Vector<String> fullName (const Vector<String>& fileName);
00127 
00128   // Return the full directory names of the given files.
00129   static Vector<String> dirName (const Vector<String>& fileName);
00130 
00131   // Return the base names of the given files.
00132   static Vector<String> baseName (const Vector<String>& fileName);
00133 
00134   // Get the time of the given files.
00135   // <src>whichTime</src> determines which time to return:
00136   // <br>1 = time of last access
00137   // <br>2 = time of last modification
00138   // <br>3 = time of last status change
00139   static Vector<Double> fileTime (const Vector<String>& fileName,
00140                                   Int whichTime = 1, Bool follow = True);
00141 
00142   // Return the total size (in bytes) for each file or directory given.
00143   // For a directory the size of all files (recursively) in it is given.
00144   // If follow is False, symbolic links are not followed.
00145   // <group>
00146   static Vector<Double> totalSize (const Vector<String>& fileName,
00147                                    Bool follow = True);
00148   static Double totalSize (const String& fileName, Bool follow = True);
00149   // </group>
00150 
00151   // Return the total size on the devices the given directories are on.
00152   // If follow is False, symbolic links are not followed.
00153   static Vector<Double> freeSpace (const Vector<String>& fileName,
00154                                    Bool follow = True);
00155 
00156   // Copy the file (or directory recursively).
00157   // If from is a symbolic link and follow is False, only the
00158   // symbolic link is copied.
00159   static void copy (const String& to, const String& from,
00160                     Bool overwrite = True, Bool follow = True);
00161 
00162   // Move the file or directory.
00163   // If from is a symbolic link and follow is False, only the
00164   // symbolic link is moved.
00165   static void move (const String& to, const String& from,
00166                     Bool overwrite = True, Bool follow = True);
00167 
00168   // Remove the files (or directories recursively).
00169   // If fileName is a symbolic link and follow is False, only the
00170   // symbolic link is removed.
00171   // <group>
00172   static void remove (const String& fileName, Bool recursive,
00173                       Bool mustExist = True, Bool follow = True);
00174   static void remove (const Vector<String>& fileNames, Bool recursive,
00175                       Bool mustExist = True, Bool follow = True);
00176   // </group>
00177 
00178   // Tell if a table is used or locked by another process.
00179   // It returns a vector containing 3 integers.
00180   // The first one tells if the table is in use or locked.
00181   // See <linkto class=LockFile>LockFile</linkto>::showLock for details.
00182   // The second one gives the pid of the process using/locking the table.
00183   // The third one tells if the table is permanently locked (0 = not).
00184   static Vector<Int> lockInfo (const String& tableName);
00185 };
00186 
00187 
00188 
00189 } //# NAMESPACE CASA - END
00190 
00191 #endif