路泰科技体检小程序UI设计新版本
1
wwl
6 天以前 a6cdbcfe28fcc40ebb4919f57d60fb20122e8e57
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
47
48
49
50
#ifndef DIR_TREE_H
#define DIR_TREE_H
 
#include <string>
#include <unordered_map>
#include <memory>
#include "Event.hh"
 
#ifdef _WIN32
#define DIR_SEP "\\"
#else
#define DIR_SEP "/"
#endif
 
struct DirEntry {
  std::string path;
  uint64_t mtime;
  bool isDir;
  mutable void *state;
 
  DirEntry(std::string p, uint64_t t, bool d);
  DirEntry(FILE *f);
  void write(FILE *f) const;
  bool operator==(const DirEntry &other) const {
    return path == other.path;
  }
};
 
class DirTree {
public:
  static std::shared_ptr<DirTree> getCached(std::string root);
  DirTree(std::string root) : root(root), isComplete(false) {}
  DirTree(std::string root, FILE *f);
  DirEntry *add(std::string path, uint64_t mtime, bool isDir);
  DirEntry *find(std::string path);
  DirEntry *update(std::string path, uint64_t mtime);
  void remove(std::string path);
  void write(FILE *f);
  void getChanges(DirTree *snapshot, EventList &events);
 
  std::mutex mMutex;
  std::string root;
  bool isComplete;
  std::unordered_map<std::string, DirEntry> entries;
 
private:
  DirEntry *_find(std::string path);
};
 
#endif