00001 // -*- C++ -*- 00002 00003 //============================================================================= 00004 /** 00005 * @file Dirent.h 00006 * 00007 * $Id: Dirent.h 80826 2008-03-04 14:51:23Z wotte $ 00008 * 00009 * Define a portable C++ interface to ACE_OS_Dirent directory-entry 00010 * manipulation. 00011 * 00012 * @author Douglas C. Schmidt <schmidt@cs.wustl.edu> 00013 */ 00014 //============================================================================= 00015 00016 #ifndef ACE_DIRENT_H 00017 #define ACE_DIRENT_H 00018 #include /**/ "ace/pre.h" 00019 00020 #include /**/ "ace/ACE_export.h" 00021 00022 #if !defined (ACE_LACKS_PRAGMA_ONCE) 00023 # pragma once 00024 #endif /* ACE_LACKS_PRAGMA_ONCE */ 00025 00026 #include "ace/OS_NS_dirent.h" 00027 00028 ACE_BEGIN_VERSIONED_NAMESPACE_DECL 00029 00030 /** 00031 * @class ACE_Dirent 00032 * 00033 * @brief Define a portable C++ directory-entry iterator based on the POSIX API. 00034 */ 00035 class ACE_Export ACE_Dirent 00036 { 00037 public: 00038 // = Initialization and termination methods. 00039 /// Default constructor. 00040 ACE_Dirent (void); 00041 00042 /// Constructor calls <opendir> 00043 explicit ACE_Dirent (const ACE_TCHAR *dirname); 00044 00045 /// Opens the directory named by filename and associates a directory 00046 /// stream with it. 00047 int open (const ACE_TCHAR *filename); 00048 00049 /// Destructor calls <closedir>. 00050 ~ACE_Dirent (void); 00051 00052 /// Closes the directory stream and frees the <ACE_DIR> structure. 00053 void close (void); 00054 00055 // = Iterator methods. 00056 /** 00057 * Returns a pointer to a structure representing the directory entry 00058 * at the current position in the directory stream to which dirp 00059 * refers, and positions the directory stream at the next entry, 00060 * except on read-only filesystems. It returns a NULL pointer upon 00061 * reaching the end of the directory stream, or upon detecting an 00062 * invalid location in the directory. <readdir> shall not return 00063 * directory entries containing empty names. It is unspecified 00064 * whether entries are returned for dot or dot-dot. The pointer 00065 * returned by <readdir> points to data that may be overwritten by 00066 * another call to <readdir> on the same directory stream. This 00067 * data shall not be overwritten by another call to <readdir> on a 00068 * different directory stream. <readdir> may buffer several 00069 * directory entries per actual read operation; <readdir> marks for 00070 * update the st_atime field of the directory each time the 00071 * directory is actually read. 00072 */ 00073 ACE_DIRENT *read (void); 00074 00075 /** 00076 * Has the equivalent functionality as <readdir> except that an 00077 * @a entry and @a result buffer must be supplied by the caller to 00078 * store the result. 00079 */ 00080 int read (struct ACE_DIRENT *entry, 00081 struct ACE_DIRENT **result); 00082 00083 // = Manipulators. 00084 /// Returns the current location associated with the directory 00085 /// stream. 00086 long tell (void); 00087 00088 /** 00089 * Sets the position of the next <readdir> operation on the 00090 * directory stream. The new position reverts to the position 00091 * associated with the directory stream at the time the <telldir> 00092 * operation that provides loc was performed. Values returned by 00093 * <telldir> are good only for the lifetime of the <ACE_DIR> pointer from 00094 * which they are derived. If the directory is closed and then 00095 * reopened, the <telldir> value may be invalidated due to 00096 * undetected directory compaction. It is safe to use a previous 00097 * <telldir> value immediately after a call to <opendir> and before 00098 * any calls to readdir. 00099 */ 00100 void seek (long loc); 00101 00102 /** 00103 * Resets the position of the directory stream to the beginning of 00104 * the directory. It also causes the directory stream to refer to 00105 * the current state of the corresponding directory, as a call to 00106 * <opendir> would. 00107 */ 00108 void rewind (void); 00109 00110 private: 00111 /// Pointer to the directory stream. 00112 ACE_DIR *dirp_; 00113 }; 00114 00115 ACE_END_VERSIONED_NAMESPACE_DECL 00116 00117 #if defined (__ACE_INLINE__) 00118 #include "ace/Dirent.inl" 00119 #endif /* __ACE_INLINE__ */ 00120 00121 #include /**/ "ace/post.h" 00122 #endif /* ACE_DIRENT_H */