oaFile.h

Go to the documentation of this file.
00001 // *****************************************************************************
00002 // oaFile.h
00003 //
00004 // This file contains the definitions for the utility classes which implement
00005 // an interface on top of a file system component. The oaFSComponent class
00006 // implements a file system component, which may be either a file (oaFile) or a
00007 // directory (oaDir). The oaFile utility class isa oaFSComponent which
00008 // implements an interface for managing a disk file. The oaDir utility class isa
00009 // oaFSComponent which implements a class for managing a directory.
00010 //
00011 // The oaDirIter utility class implements a general iterator for iterating the
00012 // names of items in a directory. The oaDirIter may be customized by specifying
00013 // the type of objects returned to be restricted to files (oacFilesDirIterMode),
00014 // restricted to directories (oacDirsDirIterMode), or unrestricted
00015 // (oacAllDirIterMode). Additionally, the user may optionally specify a string
00016 // wildcard for name filtering. Note that the oaDirIter only returns names of
00017 // file system objects, and has no direct connection with the oaFSComponent
00018 // class objects.
00019 //
00020 // *****************************************************************************
00021 // Except as specified in the OpenAccess terms of use of Cadence or Silicon
00022 // Integration Initiative, this material may not be copied, modified,
00023 // re-published, uploaded, executed, or distributed in any way, in any medium,
00024 // in whole or in part, without prior written permission from Cadence.
00025 //
00026 //                Copyright 2002-2005 Cadence Design Systems, Inc.
00027 //                           All Rights Reserved.
00028 //
00029 //  $Author: icftcm $
00030 //  $Revision: #1 $
00031 //  $Date: 2010/08/09 $
00032 //  $State: Exp $
00033 // *****************************************************************************
00034 // *****************************************************************************
00035 
00036 
00037 
00038 #if !defined(oaFile_P)
00039 #define oaFile_P
00040 
00041 
00042 
00043 // *****************************************************************************
00044 // Nested includes
00045 // *****************************************************************************
00046 #include "oaString.h"
00047 
00048 #if defined(OA_WINDOWS)
00049 #include <WinSock2.h>
00050 #include <Windows.h>
00051 #else
00052 #include <dlfcn.h>
00053 #include <dirent.h>
00054 #include <fcntl.h>
00055 #endif
00056 
00057 #if defined(HPUX)
00058 #include <dl.h>
00059 #endif
00060 
00061 
00062 
00063 // *****************************************************************************
00064 // Declare and define types in the OpenAccess namespace.
00065 // *****************************************************************************
00066 BEGIN_OA_NAMESPACE
00067 
00068 
00069 
00070 // *****************************************************************************
00071 // oaFSComponent
00072 // *****************************************************************************
00073 class OA_BASE_DLL_API oaFSComponent {
00074 public:
00075                             oaFSComponent(const oaString &nameIn);
00076     virtual inline          ~oaFSComponent();
00077 
00078     void                    destroy();
00079     void                    rename(const oaString &newName);
00080 
00081     virtual oaBoolean       exists() const;
00082     oaBoolean               isFile() const;
00083     oaBoolean               isDir() const;
00084     oaBoolean               isReadable() const;
00085     oaBoolean               isWritable() const;
00086     oaBoolean               isInCWD() const;
00087     oaBoolean               isNFSFileSystem() const;
00088     oaBoolean               isAFSFileSystem() const;
00089     oaBoolean               isSameDiskFile(const oaFSComponent &file) const;
00090     oaBoolean               isSymbolicLink() const;
00091 
00092     const oaString          &getName() const;
00093     void                    getFullName(oaString &pathName) const;
00094     oaUInt4                 getRefCount() const;
00095 
00096 protected:
00097     oaString                name;
00098 #if defined(OA_WINDOWS)
00099     HANDLE                  handle;
00100 #else
00101     oaInt4                  fd;
00102 #endif
00103 };
00104 
00105 
00106 
00107 // *****************************************************************************
00108 // oaFile
00109 // *****************************************************************************
00110 class OA_BASE_DLL_API oaFile : public oaFSComponent {
00111 public:
00112                             oaFile(const oaString &nameIn);
00113     virtual                 ~oaFile();
00114 
00115     void                    open(oaChar modeIn);
00116     void                    close();
00117     void                    flush();
00118 
00119     oaUInt4                 read(void       *data,
00120                                  oaUInt4    numBytes);
00121     oaUInt4                 write(void      *data,
00122                                   oaUInt4   numBytes);
00123 
00124     virtual oaBoolean       exists() const;
00125     oaBoolean               isOpen() const;
00126     oaBoolean               isNonEmpty() const;
00127 
00128     oaChar                  getMode() const;
00129     oaUInt8                 getSize() const;
00130     oaTime                  getLastWriteTime() const;
00131     oaTime                  getCreateTime() const;
00132 
00133     static void             copyFile(const oaString &srcPath,
00134                                      const oaString &dstPath);
00135 protected:
00136     oaChar                  mode;
00137 
00138 private:
00139 #if !defined(OA_WINDOWS)
00140     static const mode_t     permFlags;
00141 #endif
00142 };
00143 
00144 
00145 
00146 // *****************************************************************************
00147 // oaDir
00148 // *****************************************************************************
00149 class OA_BASE_DLL_API oaDir : public oaFSComponent {
00150 public:
00151                             oaDir(const oaString &nameIn);
00152     virtual inline          ~oaDir();
00153 
00154     void                    create() const;
00155 
00156     virtual oaBoolean       exists() const;
00157     oaBoolean               isEmpty() const;
00158 
00159     oaBoolean               isCWD() const;
00160 
00161 private:
00162 #if !defined(OA_WINDOWS)
00163     static const mode_t     permFlags;
00164 #endif
00165 };
00166 
00167 
00168 
00169 
00170 // *****************************************************************************
00171 // enum oaDirIterMode
00172 // *****************************************************************************
00173 enum oaDirIterModeEnum {
00174     oacFilesDirIterMode = 0,
00175     oacDirsDirIterMode  = 1,
00176     oacAllDirIterMode   = 2
00177 };
00178 
00179 
00180 
00181 // *****************************************************************************
00182 // oaDirIter
00183 // *****************************************************************************
00184 class OA_BASE_DLL_API oaDirIter {
00185 public:
00186                             oaDirIter(const oaString    &dirPathIn,
00187                                       oaDirIterModeEnum modeIn = oacAllDirIterMode);
00188                             oaDirIter(const oaString    &dirPathIn,
00189                                       const oaString    &wildcardNameIn,
00190                                       oaDirIterModeEnum modeIn = oacAllDirIterMode);
00191                             ~oaDirIter();
00192 
00193     oaBoolean               getNext(oaString &name);
00194 
00195     void                    reset();
00196 
00197 private:
00198 #if defined(OA_WINDOWS)
00199     // Note that we define a handle as a void* in order to avoid a dependency
00200     // on Windows.h in the public headers. The handle will be cast to the
00201     // correct type of HANDLE when used in the private implementation.
00202     void                    *handle;
00203     char                    *dirPath;
00204     oaDirIterModeEnum       mode;
00205     oaBoolean               first;
00206 
00207 #else
00208     DIR                     *dir;
00209     char                    *dirPath;
00210     oaUInt4                 dirPathLen;
00211     oaByte                  *readdirBuf;
00212     oaString                wildcardName;
00213     oaDirIterModeEnum       mode;
00214 #endif
00215 };
00216 
00217 
00218 
00219 END_OA_NAMESPACE
00220 
00221 #endif

Return to top of page