COVISE Core
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
coFileUtil.h
Go to the documentation of this file.
1 /* This file is part of COVISE.
2 
3  You can use it under the terms of the GNU Lesser General Public License
4  version 2.1 or later, see lgpl-2.1.txt.
5 
6  * License: LGPL 2+ */
7 
8 #ifndef VR_FILE_UTIL_H
9 #define VR_FILE_UTIL_H
10 //**************************************************************************
11 //
12 // (C) 1996
13 // Computer Centre University of Stuttgart
14 // Allmandring 30
15 // D-70550 Stuttgart
16 // Germany
17 //
18 //
19 //
20 // COVISE Basic VR Environment Library
21 //
22 //
23 //
24 // Author: D.Rantzau
25 // Date : 04.05.96
26 // Last :
27 //**************************************************************************/
28 #include "common.h"
29 
30 #include <iostream>
31 #include <ctype.h>
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <string.h>
35 #include <fcntl.h>
36 #include <sys/stat.h>
37 #include <sys/types.h>
38 
39 #include "coExport.h"
40 
41 #ifdef _WIN32
42 #include <windows.h>
43 
44 #include <process.h>
45 #include <io.h>
46 #include <direct.h>
47 #else
48 #include <dirent.h>
49 #include <pwd.h>
50 #include <unistd.h>
51 #endif
52 
53 #ifndef S_ISDIR
54 #define S_ISDIR(mode) (((mode)&S_IFMT) == S_IFDIR)
55 #endif
56 
57 struct _finddata_t;
58 
59 namespace covise
60 {
61 
62 static const int path_buffer_size = 1024 + 1;
63 
64 class coFileInfo;
65 
66 //==========================================================================
67 //
68 //==========================================================================
70 {
71 protected:
72  coFile(coFileInfo *);
73 
74 public:
75  virtual ~coFile();
76 
77  virtual const char *name() const;
78  virtual long length() const;
79  virtual void close();
80 
81  virtual void limit(unsigned int buffersize);
82 
83  static bool exists(const char *fname);
84 
85 protected:
86  coFileInfo *rep() const;
87 
88 private:
90 
91 private:
92  /* not allowed */
93  void operator=(const coFile &);
94 };
95 
96 //==========================================================================
97 //
98 //==========================================================================
99 class coInputFile : public coFile
100 {
101 protected:
103 
104 public:
105  virtual ~coInputFile();
106 
107  static coInputFile *open(const char *name);
108 
109  virtual long read(const char *&start);
110 };
111 
112 //==========================================================================
113 //
114 //==========================================================================
116 {
117 public:
118  char *name_;
119  int fd_;
120  char *map_;
121 #ifdef _WIN32
122  struct _stat info_;
123 #else
124  struct stat info_;
125 #endif
126  off_t pos_;
127  char *buf_;
128  unsigned int limit_;
129 
130  coFileInfo(const char *, int fd);
131  ~coFileInfo();
132 };
133 
134 //==========================================================================
135 //
136 //==========================================================================
137 class coStdInput : public coInputFile
138 {
139 public:
140  coStdInput();
141  virtual ~coStdInput();
142 
143  virtual long length() const;
144  virtual long read(const char *&start);
145 };
146 
147 class coDirectoryImpl;
148 
149 //==========================================================================
150 //
151 //==========================================================================
153 {
154 
155  friend class coDirectoryImpl;
156 
157 protected:
158  coDirectory();
159 
160 public:
161  virtual ~coDirectory();
162 
163  static coDirectory *current();
164  static coDirectory *open(const char *);
165  virtual void close();
166 
167  virtual const char *path() const;
168  virtual int count() const;
169  virtual const char *name(int index) const;
170  virtual char *full_name(int index);
171  virtual int index(const char *) const;
172  virtual int is_directory(int index) const;
173  virtual int is_exe(int index) const;
174  virtual int getSize(int index) const;
175  virtual time_t getDate(int index) const;
176 
177  static char *canonical(const char *);
178  static int match(const char *name, const char *pattern);
179  static char *fileOf(const char *);
180  static char *dirOf(const char *);
181 private:
183 
184 private:
185  /* not allowed */
186  coDirectory(const coDirectory &);
187  void operator=(const coDirectory &);
188 };
189 
190 //==========================================================================
191 //
192 //==========================================================================
194 {
195 public:
196  const char *name() const;
198  {
199  name_ = NULL;
200  info_ = NULL;
201  }
202  // ~coDirectoryEntry() { delete name_; name_=NULL; delete info_; info_=NULL; }
203 private:
204  friend class coDirectory;
205  friend class coDirectoryImpl;
206 
207  char *name_;
208 #ifdef _WIN32
209  int attrib_;
210  struct _stat *info_;
211 #else
212  struct stat *info_;
213 #endif
214 };
215 
216 inline const char *coDirectoryEntry::name() const
217 {
218  return name_;
219 }
220 }
221 #endif
char * name_
Definition: coFileUtil.h:207
virtual ~coStdInput()
virtual ~coInputFile()
GLuint const GLchar * name
Definition: khronos-glext.h:6722
Definition: coFileUtil.h:137
Definition: coFileUtil.h:115
char * buf_
Definition: coFileUtil.h:127
coFileInfo(const char *, int fd)
Definition: coFileUtil.cpp:1195
virtual long length() const
Definition: coFileUtil.cpp:48
const char * name() const
Definition: coFileUtil.h:216
~coFileInfo()
Definition: coFileUtil.cpp:1207
#define NULL
Definition: covise_list.h:22
virtual long read(const char *&start)
GLuint GLuint GLsizei count
Definition: khronos-glext.h:6343
Definition: coFileUtil.h:193
char * map_
Definition: coFileUtil.h:120
static const int path_buffer_size
Definition: coFileUtil.h:62
Definition: coFileUtil.h:99
virtual long read(const char *&start)
GLsizei const GLchar ** path
Definition: khronos-glext.h:7952
GLuint start
Definition: khronos-glext.h:6343
Definition: coFileUtil.h:69
coDirectoryEntry()
Definition: coFileUtil.h:197
double length(EDGE_VECTOR &vector)
Definition: CuttingSurfaceGPMUtil.h:70
Definition: coFileUtil.h:152
GLuint index
Definition: khronos-glext.h:6722
int fd_
Definition: coFileUtil.h:119
coInputFile(coFileInfo *)
char * name_
Definition: coFileUtil.h:118
GLint limit
Definition: khronos-glext.h:11595
struct stat * info_
Definition: coFileUtil.h:212
coFileInfo * rep_
Definition: coFileUtil.h:89
#define UTILEXPORT
Definition: coExport.h:182
GLubyte * pattern
Definition: khronos-glext.h:8505
coDirectoryImpl * impl_
return the directory (without ending / ) of a canonical file with absolute path
Definition: coFileUtil.h:182
off_t pos_
Definition: coFileUtil.h:126
struct stat info_
Definition: coFileUtil.h:124
static coInputFile * open(const char *name)
unsigned int limit_
Definition: coFileUtil.h:128