libUTL++
Directory.h
1 #pragma once
2 
4 
5 #include <libutl/Collection.h>
6 #include <libutl/Factory.h>
7 #include <libutl/FSobject.h>
8 
10 
11 UTL_NS_BEGIN;
12 
14 
73 
75 class Directory : public FSobject
76 {
78 
79 public:
85  Directory(const String& path, const Directory* dir = nullptr)
86  : FSobject(path, dir)
87  {
88  init();
89  }
90 
91  virtual int compare(const Object& rhs) const;
92 
93  virtual void copy(const Object& rhs);
94 
96  virtual void dump(Stream& os, uint_t level = uint_t_max) const;
97 
98  virtual void serialize(Stream& stream, uint_t io, uint_t mode = ser_default);
99 
100  virtual void unlink();
101 
102  void unlinkRecursive();
103 
105  bool
106  isFlat() const
107  {
108  return getFlag(flg_flat);
109  }
110 
112  const Collection*
113  entries() const
114  {
115  return _entries;
116  }
117 
119  Collection*
121  {
122  return _entries;
123  }
124 
126  void takeEntries(Directory& rhs);
127 
135  FSobject* find(const Pathname& path, bool relative = true) const;
136 
138  void make(uint_t mode = uint_t_max) const;
139 
147  size_t
148  scan(uint_t flags = 0,
149  Factory* factory = nullptr,
150  const Predicate* pred = nullptr,
151  bool predVal = true)
152  {
153  return scan(flags, factory, pred, predVal, nullptr);
154  }
155 
162  void rescan(uint_t flags = 0,
163  Factory* factory = nullptr,
164  const Predicate* pred = nullptr,
165  bool predVal = true);
166 
168  enum scan_t
169  {
170  scan_recursive = 1,
171  scan_recursive_flat = 2,
172  scan_followLinks = 4,
173  scan_excludeDotDirs = 8,
174  scan_ignoreEx = 16,
175  scan_append = 32,
176  };
177 
178 private:
179  void
180  init()
181  {
182  _entries = nullptr;
183  }
184  void
185  deInit()
186  {
187  delete _entries;
188  }
189  void
190  setFlat(bool flat)
191  {
192  setFlag(flg_flat, flat);
193  }
194  size_t scan(uint_t flags,
195  Factory* factory,
196  const Predicate* pred,
197  bool predVal,
198  const Pathname* flatPrefix);
199 
200 private:
201  enum flg_t
202  {
203  flg_flat = 4
204  };
205 
206 private:
207  Collection* _entries;
208 };
209 
211 
212 UTL_NS_END;
void serialize(bool &b, Stream &stream, uint_t io, uint_t mode=ser_default)
Serialize a boolean.
void deInit()
De-initialize UTL++.
Filesystem pathname.
Definition: Pathname.h:32
const Collection * entries() const
Get the collection of entries.
Definition: Directory.h:113
default representation (via getSerializeMode())
Definition: util.h:75
#define UTL_CLASS_DECL(DC, BC)
Declaration of standard UTL++ functionality for a non-template class.
Definition: macros.h:688
Directory(const String &path, const Directory *dir=nullptr)
Constructor.
Definition: Directory.h:85
Character string.
Definition: String.h:31
size_t scan(uint_t flags=0, Factory *factory=nullptr, const Predicate *pred=nullptr, bool predVal=true)
Scan the directory to populate the entries collection.
Definition: Directory.h:148
Collection * entries()
Get the collection of entries.
Definition: Directory.h:120
void copy(T *dest, const T *src, size_t len)
Copy one array of objects to another.
Definition: util_inl.h:690
bool isFlat() const
Determine whether a flat scan was done.
Definition: Directory.h:106
Logical predicate abstraction.
Definition: Predicate.h:26
Filesystem object.
Definition: FSobject.h:35
unsigned int uint_t
Unsigned integer.
Definition: types.h:59
Directory filesystem object.
Definition: Directory.h:75
const uint_t uint_t_max
Maximum uint_t value.
scan_t
Scan flags.
Definition: Directory.h:168
Stream I/O abstraction.
Definition: Stream.h:68
Root of UTL++ class hierarchy.
Definition: Object.h:52
int compare(bool lhs, bool rhs)
Compare two boolean values.
void dump(const FwdIt &begin, const FwdIt &end, Stream &os, uint_t level=uint_t_max, bool key=false, bool printClassName=false, uint_t indent=0, const char *separator=nullptr)
Dump objects to the given stream (with Object::dump()).
void init()
Initialize UTL++.
Object creation abstraction.
Definition: Factory.h:24
A collection of objects.
Definition: Collection.h:62