Root/src/filelister.h

Source at commit 7b10f9448bb9965e94f9a37a59f0999e9c51e68f created 7 years 5 months ago.
By Maarten ter Huurne, Suppress Clang analyzer warnings about dead assignments
1/***************************************************************************
2 * Copyright (C) 2006 by Massimiliano Torromeo *
3 * massimiliano.torromeo@gmail.com *
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 *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
20
21#ifndef FILELISTER_H
22#define FILELISTER_H
23
24#include <string>
25#include <vector>
26
27class FileLister {
28private:
29    std::vector<std::string> filter;
30    bool showDirectories, showUpdir, showFiles;
31
32    std::vector<std::string> directories, files;
33
34public:
35    FileLister();
36
37    /**
38     * Scans the given directory.
39     * @param clean If true, start a new result set, if false add to the
40     * results from the previous scan.
41     * @return True iff the given directory could be opened.
42     */
43    bool browse(const std::string& path, bool clean = true);
44
45    unsigned int size() { return files.size() + directories.size(); }
46    unsigned int dirCount() { return directories.size(); }
47    unsigned int fileCount() { return files.size(); }
48
49    std::string operator[](unsigned int);
50    bool isFile(unsigned int x) { return x >= directories.size(); }
51    bool isDirectory(unsigned int x) { return x < directories.size(); }
52
53    void setFilter(const std::string &filter);
54
55    void setShowDirectories(bool enabled) { showDirectories = enabled; }
56    void setShowUpdir(bool enabled) { showUpdir = enabled; }
57    void setShowFiles(bool enabled) { showFiles = enabled; }
58
59    const std::vector<std::string> &getDirectories() { return directories; }
60    const std::vector<std::string> &getFiles() { return files; }
61};
62
63#endif // FILELISTER_H
64

Archive Download this file



interactive