File: Dirlist.hh

package info (click to toggle)
rdfind 1.4.1-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, sid
  • size: 648 kB
  • sloc: cpp: 1,670; sh: 1,622; makefile: 32
file content (46 lines) | stat: -rw-r--r-- 1,225 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*
   copyright 20016-2017 Paul Dreik (earlier Paul Sundvall)
   Distributed under GPL v 2.0 or later, at your option.
   See LICENSE for further details.
*/

#ifndef Dirlist_hh
#define Dirlist_hh

#include <string>

/// class that traverses a directory
class Dirlist
{
public:
  // constructor
  explicit Dirlist(bool followsymlinks)
    : m_followsymlinks(followsymlinks)
    , m_callback(nullptr)
  {}

private:
  // follow symlinks or not
  bool m_followsymlinks;

  // where to report found files. this is called for every item in all
  // directories found by walk.
  typedef int (*reportfcntype)(const std::string&, const std::string&, int);

  // called when a regular file or a symlink is encountered
  reportfcntype m_callback;

  // a function that is called from walk when a non-directory is encountered
  // for instance,if walk("/path/to/a/file.ext") is called instead of
  // walk("/path/to/a/")
  int handlepossiblefile(const std::string& possiblefile, int recursionlevel);

public:
  // find all files on a specific place
  int walk(const std::string& dir, const int recursionlevel = 0);

  // to set the report functions
  void setcallbackfcn(reportfcntype reportfcn) { m_callback = reportfcn; }
};

#endif