/[svn]/linuxsampler/trunk/src/common/File.h
ViewVC logotype

Annotation of /linuxsampler/trunk/src/common/File.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1717 - (hide annotations) (download) (as text)
Sun Mar 16 17:43:20 2008 UTC (16 years, 1 month ago) by iliev
File MIME type: text/x-c++hdr
File size: 4333 byte(s)
* moved all OS dependent file operation to File class

1 iliev 1717 /***************************************************************************
2     * *
3     * Copyright (C) 2008 Grigor Iliev, Benno Senoner *
4     * *
5     * This program is free software; you can redistribute it and/or modify *
6     * it under the terms of the GNU General Public License as published by *
7     * the Free Software Foundation; either version 2 of the License, or *
8     * (at your option) any later version. *
9     * *
10     * This program is distributed in the hope that it will be useful, *
11     * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13     * GNU General Public License for more details. *
14     * *
15     * You should have received a copy of the GNU General Public License *
16     * along with this program; if not, write to the Free Software *
17     * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
18     * MA 02110-1301 USA *
19     ***************************************************************************/
20    
21     #ifndef LS_FILE_H
22     #define LS_FILE_H
23    
24     #include <string>
25     #include <vector>
26    
27     #include "Mutex.h"
28    
29     #if WIN32
30    
31     #else
32     #include <sys/stat.h>
33     #endif
34    
35     namespace LinuxSampler {
36    
37     typedef std::auto_ptr<std::vector<std::string> > FileListPtr;
38    
39     class File {
40     public:
41     class DirectoryWalker {
42     public:
43     virtual void DirectoryEntry(std::string Path) = 0;
44     virtual void FileEntry(std::string Path) = 0;
45     };
46    
47     File(std::string FileName);
48    
49     /**
50     * Tests whether the file exists.
51     */
52     bool Exist();
53    
54     /**
55     * Provides appropriate error message if failed to retrieve
56     * information about the specified file, in which case Exist() returns false.
57     */
58     std::string GetErrorMsg();
59    
60     /**
61     * Tests whether it's a regular file.
62     */
63     bool IsFile();
64    
65     /**
66     * Tests whether it's a directory.
67     */
68     bool IsDirectory();
69    
70     /**
71     * Returns the size of the file in bytes.
72     */
73     unsigned long GetSize();
74    
75     /**
76     * Returns the names of the regular files in the specified directory.
77     * @throws Exception If failed to list the directory content.
78     */
79     static FileListPtr GetFiles(std::string Dir);
80    
81     /**
82     * Walks through the directory tree that is located under the
83     * directory <b>Dir</b>, and calls <b>pWalker->DirectoryEntry()</b>
84     * once for each directory in the tree and <b>pWalker->FileEntry()</b>
85     * once for each file in the tree. Note that this method can be
86     * recursively invoked from within the callback functions
87     * <b>pWalker->DirectoryEntry()</b> and <b>pWalker->FileEntry()</b>.
88     * @throws Exception If the specified path is missing or is not a directory.
89     * Exception is also thrown, and the directory tree walk is stopped,
90     * if <b>pWalker->DirectoryEntry()</b> or <b>pWalker->FileEntry()</b>
91     * throws Exception.
92     */
93     static void WalkDirectoryTree(std::string Dir, DirectoryWalker* pWalker);
94    
95     static char DirSeparator;
96    
97     private:
98     bool bExist;
99     std::string ErrorMsg;
100     static Mutex DirectoryWalkerMutex;
101     static std::vector<DirectoryWalker*> DirectoryWalkers;
102     static std::string DWErrorMsg;
103    
104     #if WIN32
105    
106     #else
107     struct stat Status;
108     static int FtwCallback(const char* fpath, const struct stat* sb, int typeflag);
109     #endif
110     };
111     }
112    
113     #endif

  ViewVC Help
Powered by ViewVC