HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FS_FileSystem.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: FS_FileSystem.h ( SI Library, C++)
7  *
8  * COMMENTS: This provides a "filesystem" interface that's used by
9  * SI_FileChooser.[Ch] This is used both by the Unix/NT file
10  * system and the Houdini OP "filesystem"
11  *
12  * This class does not ever include "." or ".." in the directory
13  * list.
14  */
15 
16 #ifndef __FS_FileSystem__
17 #define __FS_FileSystem__
18 
19 #include "FS_API.h"
20 #include <UT/UT_Array.h>
21 #include <UT/UT_NonCopyable.h>
22 #include <UT/UT_String.h>
23 #include <UT/UT_StringArray.h>
24 #include <time.h>
25 
26 class FS_Stat;
27 
28 typedef int (*FS_FileFilter)(const char *filename, void *data);
29 
31 {
32 public:
33  FS_FileSystem(const char *start_path="");
34  ~FS_FileSystem();
35 
37 
38  // When over-riding the changePath() method, make sure to harden the myPath
39  // member data.
40 
41  int changePath(const char *newpath);
42  const char *getPath(char *buffer=0, int len=0);
43  void setPattern(const char *p) { myPattern.harden(p); }
44 
45  int canCreateDir(const char *path);
46  int createDir(const char *path);
47 
48  int canViewFile() const;
49  void viewFile(const char *path);
50 
51  // The pollDirectory() call should be called to load up the
52  // directories, files, and respective stats. This is NOT done automatically
53  // when changePath() is called.
54  int pollDirectory();
55  void forceReload()
56  {
57  // Cause a reload of directory next poll
58  myLastReadTime = 0;
59  }
60 
61  // Both of these methods (stat/access) return 1 if successful, 0 on fail.
62  // This is not like the unix system calls stat()/access() which return 0 on
63  // success, -1 on fail.
64  int statFile(const char *name, FS_Stat *stats=0);
65  int accessFile(const char *name, int access_mode);
66 
67  void setFileFilter(FS_FileFilter filter, void *data);
68  void setDirectoryFilter(FS_FileFilter filter, void *data);
69 
71  { return myDirectories; }
73  { return myFilenames; }
74  //UT_ValArray<char *> &getHiddenFiles() { return myFilenames; }
75  UT_Array<FS_Stat> &getFileStats() { return myFileStats; }
76  UT_Array<FS_Stat> &getDirStats () { return myDirStats; }
77 
78  void setHidden (bool hidden) { myIgnoreHidden = hidden; }
79  // By default, isRoot() checks the current path to see if it's "/"
80  int isRoot(const char *otherpath = 0);
81 
82 protected:
83  // Stat should return the last modification date of a directory. This
84  // allows us to determine whether the directory has been modified
85  // externally or not.
86  time_t statDirectory();
87 
88  // The readContents() method should return 1 if the directory was read
89  // successfully, 0 if there was an error.
90  // As a note, the file/directory filters will always be set. By default,
91  // they will return the filename passed in.
92  int readContents();
93 
94  /// It would be nice to sort these as we read them in but then the
95  /// fileStats will not match up. Therefore, we append entries now and
96  /// sort them later.
97  void addDirectory(const char *name, const FS_Stat &fstat);
98  void addFilename(const char *name, const FS_Stat &fstat);
99 
100  UT_String myPath, myLastReadPath;
101 
103 
106 
109 
110 private:
111  void clearLists();
112 
113  time_t myLastReadTime;
114  UT_StringArray myDirectories;
115  UT_StringArray myFilenames;
116  UT_String myPattern;
117 
118  UT_Array<FS_Stat> myFileStats;
119  UT_Array<FS_Stat> myDirStats;
120 };
121 
122 #endif
typedef int(APIENTRYP RE_PFNGLXSWAPINTERVALSGIPROC)(int)
FS_FileFilter myFilter
GT_API const UT_StringHolder filename
UT_StringArray & getFiles()
Definition: FS_FileSystem.h:72
UT_StringArray & getDirectories()
Definition: FS_FileSystem.h:70
GLboolean * data
Definition: glcorearb.h:131
UT_Array< FS_Stat > & getFileStats()
Definition: FS_FileSystem.h:75
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
void setHidden(bool hidden)
Definition: FS_FileSystem.h:78
void setPattern(const char *p)
Definition: FS_FileSystem.h:43
Definition: core.h:760
#define UT_NON_COPYABLE(CLASS)
Define deleted copy constructor and assignment operator inside a class.
GLuint const GLchar * name
Definition: glcorearb.h:786
Helper class for encapsulating file information.
Definition: FS_Info.h:55
int(* FS_FileFilter)(const char *filename, void *data)
Definition: FS_FileSystem.h:28
UT_String myPath
void forceReload()
Definition: FS_FileSystem.h:55
FS_FileFilter myDirFilter
void * myFilterData
void * myDirFilterData
Definition: format.h:895
#define FS_API
Definition: FS_API.h:10
UT_Array< FS_Stat > & getDirStats()
Definition: FS_FileSystem.h:76
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition: glcorearb.h:1297