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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1782 - (show annotations) (download) (as text)
Tue Sep 30 02:16:41 2008 UTC (15 years, 6 months ago) by iliev
File MIME type: text/x-c++hdr
File size: 4339 byte(s)
* updated the lscp spec
* code cleanup in InstrumentsDb

1 /***************************************************************************
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 <memory>
25 #include <string>
26 #include <vector>
27
28 #include "Mutex.h"
29
30 #if WIN32
31
32 #else
33 #include <sys/stat.h>
34 #endif
35
36 namespace LinuxSampler {
37
38 typedef std::auto_ptr<std::vector<std::string> > FileListPtr;
39
40 class File {
41 public:
42 class DirectoryWalker {
43 public:
44 virtual void DirectoryEntry(std::string Path) = 0;
45 virtual void FileEntry(std::string Path) = 0;
46 };
47
48 File(std::string FileName);
49
50 /**
51 * Tests whether the file exists.
52 */
53 bool Exist();
54
55 /**
56 * Provides appropriate error message if failed to retrieve
57 * information about the specified file, in which case Exist() returns false.
58 */
59 std::string GetErrorMsg();
60
61 /**
62 * Tests whether it's a regular file.
63 */
64 bool IsFile();
65
66 /**
67 * Tests whether it's a directory.
68 */
69 bool IsDirectory();
70
71 /**
72 * Returns the size of the file in bytes.
73 */
74 unsigned long GetSize();
75
76 /**
77 * Returns the names of the regular files in the specified directory.
78 * @throws Exception If failed to list the directory content.
79 */
80 static FileListPtr GetFiles(std::string Dir);
81
82 /**
83 * Walks through the directory tree that is located under the
84 * directory <b>Dir</b>, and calls <b>pWalker->DirectoryEntry()</b>
85 * once for each directory in the tree and <b>pWalker->FileEntry()</b>
86 * once for each file in the tree. Note that this method can be
87 * recursively invoked from within the callback functions
88 * <b>pWalker->DirectoryEntry()</b> and <b>pWalker->FileEntry()</b>.
89 * @throws Exception If the specified path is missing or is not a directory.
90 * Exception is also thrown, and the directory tree walk is stopped,
91 * if <b>pWalker->DirectoryEntry()</b> or <b>pWalker->FileEntry()</b>
92 * throws Exception.
93 */
94 static void WalkDirectoryTree(std::string Dir, DirectoryWalker* pWalker);
95
96 static char DirSeparator;
97
98 private:
99 bool bExist;
100 std::string ErrorMsg;
101 static Mutex DirectoryWalkerMutex;
102 static std::vector<DirectoryWalker*> DirectoryWalkers;
103 static std::string DWErrorMsg;
104
105 #if WIN32
106
107 #else
108 struct stat Status;
109 static int FtwCallback(const char* fpath, const struct stat* sb, int typeflag);
110 #endif
111 };
112 }
113
114 #endif

  ViewVC Help
Powered by ViewVC