Mercurial > code
comparison C++/modules/Directory/Directory.h @ 334:0b576ee64d45
* Create brand new hierarchy
* Rename DynLib to Dynlib
* Remove some warnings
author | David Demelier <markand@malikania.fr> |
---|---|
date | Sun, 08 Mar 2015 14:26:33 +0100 |
parents | C++/Directory.h@24085fae3162 |
children | 83ef77841ff1 |
comparison
equal
deleted
inserted
replaced
333:412ca7a5e1ea | 334:0b576ee64d45 |
---|---|
1 /* | |
2 * Directory.h -- open and read directories | |
3 * | |
4 * Copyright (c) 2013, 2014 David Demelier <markand@malikania.fr> | |
5 * | |
6 * Permission to use, copy, modify, and/or distribute this software for any | |
7 * purpose with or without fee is hereby granted, provided that the above | |
8 * copyright notice and this permission notice appear in all copies. | |
9 * | |
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | |
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
17 */ | |
18 | |
19 #ifndef _DIRECTORY_H_ | |
20 #define _DIRECTORY_H_ | |
21 | |
22 #include <cstddef> | |
23 #include <string> | |
24 #include <vector> | |
25 | |
26 /** | |
27 * @class Directory | |
28 * @brief class to manipulate directories | |
29 * | |
30 * This class allow the user to iterate directories in a for range based | |
31 * loop using iterators. | |
32 */ | |
33 class Directory { | |
34 public: | |
35 /** | |
36 * @enum Flags | |
37 * @brief optional flags to read directories | |
38 */ | |
39 enum Flags { | |
40 NotDot = (1 << 0), | |
41 NotDotDot = (1 << 1) | |
42 }; | |
43 | |
44 /** | |
45 * @enum Type | |
46 * @brief Describe the type of an entry | |
47 */ | |
48 enum Type { | |
49 Unknown = 0, | |
50 File, | |
51 Dir, | |
52 Link | |
53 }; | |
54 | |
55 /** | |
56 * @struct Entry | |
57 * @brief entry in the directory list | |
58 */ | |
59 struct Entry { | |
60 std::string name; //! name of entry (base name) | |
61 Type type; //! type of file | |
62 | |
63 Entry(); | |
64 | |
65 friend bool operator==(const Entry &e1, const Entry &e2); | |
66 }; | |
67 | |
68 using List = std::vector<Entry>; | |
69 | |
70 // C++ Container compatibility | |
71 using value_type = List::value_type; | |
72 using iterator = List::iterator; | |
73 using const_iterator = List::const_iterator; | |
74 | |
75 private: | |
76 List m_list; | |
77 | |
78 void systemLoad(const std::string &path, int flags); | |
79 | |
80 public: | |
81 /** | |
82 * Default constructor, does nothing. | |
83 */ | |
84 Directory(); | |
85 | |
86 /** | |
87 * Open a directory and read all its content. | |
88 * @param path the path | |
89 * @param flags the optional flags | |
90 */ | |
91 Directory(const std::string &path, int flags = 0); | |
92 | |
93 /** | |
94 * Return an iterator the beginning. | |
95 * | |
96 * @return the iterator | |
97 */ | |
98 List::iterator begin(); | |
99 | |
100 /** | |
101 * Return a const iterator the beginning. | |
102 * | |
103 * @return the iterator | |
104 */ | |
105 List::const_iterator cbegin() const; | |
106 | |
107 /** | |
108 * Return an iterator to past the end. | |
109 * | |
110 * @return the iterator | |
111 */ | |
112 List::iterator end(); | |
113 | |
114 /** | |
115 * Return a const iterator to past the end. | |
116 * | |
117 * @return the iterator | |
118 */ | |
119 List::const_iterator cend() const; | |
120 | |
121 /** | |
122 * Get the number of entries in the directory. | |
123 * | |
124 * @return the number | |
125 */ | |
126 int count() const; | |
127 | |
128 friend bool operator==(const Directory &d1, const Directory &d2); | |
129 }; | |
130 | |
131 #endif // !_DIRECTORY_H_ |