HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
UT_PathFile.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: UT_PathFile.h (Utility Library, C++)
7  *
8  * COMMENTS:
9  * This class is used to look for files using searchpaths.
10  * It has mechanisms for patternmatching, finding only the
11  * file that's highest in the searchpath, or combining them
12  * all, and so on. The way it searches for files is also
13  * special. Check out the .C file for more docs on that.
14  */
15 
16 #ifndef __UT_PathFile__
17 #define __UT_PathFile__
18 
19 #include "FS_API.h"
20 #include <UT/UT_Defines.h>
21 #include <UT/UT_String.h>
22 #include <UT/UT_ValArray.h>
23 
24 class UT_WorkBuffer;
25 class UT_PathSearch;
26 class UT_PathFileInfo;
27 class FS_Reader;
28 
29 #define UT_NOSAVE_HINT ".nosave"
30 #define UT_HIDE_HINT ".hide"
31 #define UT_APPEND_HINT ".append"
32 
34 
36 {
37 public:
38  UT_PathFile();
39  virtual ~UT_PathFile();
40 
41 
42  // You should call these three at least once before using this class
43  void setSearchPath(int path_id, const char *pattern);
44 
45  // Then you should call this method (or some subclass' equivalent)
46  void applyStandardFilter();
47 
48 
49  const char *getSearchPattern() { return mySearchPattern; }
50 
51  const char *getDefaultDir() { return myDefaultDir; }
52  int getDefaultDirIndex() { return myDefaultDirIndex; }
53  int getHomeDirIndex() { return myHomeIndex; }
54 
55 
56  // This is the simplest method of using this class, it just streams you
57  // all the lines in all the files that match your search.
58  bool getLine(UT_WorkBuffer &wbuf);
59 
60  // Some query methods for getting info about the current line of input
61  int getCurrentLineNumber() { return myCurrentLineNumber; }
62  const char *getCurrentFileName();
63 
64 
65  // Query methods for getting at the directory list.
66  // NOTE: getDir() indexes from the end of the list!
67  int getDirCount() const;
68  const char *getDir(int i) const;
69 
70  // if you set the filtered flag to zero, then you'll get all the matching
71  // files in the search path. ie hidden ones, overridden ones, etc
72  int getFileInfoCount(int filtered=1) const;
73  UT_PathFileInfo *getFileInfo(int i, int filtered=1) const;
75  { myFileInfos.append(info); }
76 
77  // note: no deleting done
78  void clearFileInfoList() { myFileInfos.entries(0); }
79 
80 
81  void sortFileInfos(int (*compare)(UT_PathFileInfo *const*t1,
82  UT_PathFileInfo *const*t2));
83 
84  virtual UT_PathFileInfo *createFileInfo();
85  UT_PathFileInfo *appendFileInfo(const char *fullpath, int level);
86  void removeFileInfo(int i); // NOT filtered
87  void removeFileInfo(UT_PathFileInfo *);
88  void removeFileInfo(const char *fullpath);
89 
90 protected:
91  // note: this is quite different from clearFileInfoList above
92  void clearFileList();
93  void computeFileList();
94 
95  void addMatchingFiles(char *fullpattern, int level);
96  void removeMatchingFiles(char *fullpattern, int level);
97 
98  unsigned int myBusyFlag:1,
99  myFilesFoundFlag:1;
100 private:
101  void computeDefaultDir();
102  const UT_PathSearch *myPathSearch;
103  UT_String mySearchPattern;
104  UT_String myDefaultDir;
105  int myDefaultDirIndex;
106  int myHomeIndex;
107  int myCurrentFileIndex;
108  int myCurrentLineNumber;
109 
110  UT_ValArray<UT_PathFileInfo *> myFileInfos;
111 
112  FS_Reader *myFile;
113  friend int utAddMatchingFiles(const char *file, void *data);
114  friend int utRemoveMatchingFiles(const char *file, void *data);
115 };
116 
117 FS_API extern bool UTfindPreferenceFile( int path_id,
118  const char *filename,
119  UT_String &result,
120  bool &no_save);
121 
122 
123 #endif
Class for reading files.
Definition: FS_Reader.h:30
int(* fs_path_compare_func_t)(UT_PathFileInfo *const *, UT_PathFileInfo *const *)
Definition: UT_PathFile.h:33
int getDefaultDirIndex()
Definition: UT_PathFile.h:52
int getHomeDirIndex()
Definition: UT_PathFile.h:53
GLint level
Definition: glcorearb.h:107
const char * getSearchPattern()
Definition: UT_PathFile.h:49
void clearFileInfoList()
Definition: UT_PathFile.h:78
png_uint_32 i
Definition: png.h:2877
FS_API bool UTfindPreferenceFile(int path_id, const char *filename, UT_String &result, bool &no_save)
void appendFileInfo(UT_PathFileInfo *info)
Definition: UT_PathFile.h:74
GLboolean * data
Definition: glcorearb.h:130
const char * getDefaultDir()
Definition: UT_PathFile.h:51
typedef int
Definition: png.h:1175
int getCurrentLineNumber()
Definition: UT_PathFile.h:61
#define FS_API
Definition: FS_API.h:10