summaryrefslogtreecommitdiff
path: root/src/lua/include/file_iterator.hpp
blob: 1632949ef5b9c4db5c9e7381147fa1bcb7e68845 (plain)
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
/*
 * Copyright 2023 ailurux <ailuruxx@gmail.com>
 *
 * SPDX-License-Identifier: GPL-3.0-only
 */

#pragma once 

#include <string>
#include <optional>

#include "ff.h"

namespace database {

// Note for when reading FILINFO, that we are in LFN mode:
// http://elm-chan.org/fsw/ff/doc/sfileinfo.html
struct FileEntry {
    bool isHidden;
    bool isDirectory;
    bool isTrack;
    std::string filepath;
};

class FileIterator {
 public:
  FileIterator(std::string filepath);
  ~FileIterator();

  auto value() const -> const std::optional<FileEntry>&;
  auto next() -> void;
  auto prev() -> void;

 private: 
  FF_DIR dir_;
  std::string original_path_;

  std::optional<FileEntry> current_;

  auto iterate(bool reverse = false) -> bool;
};

} // namespace database