Photon Editor Library 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
FileSystemExplorer.h
Go to the documentation of this file.
1#pragma once
2
3#include <DataIO/FileSystem/Path.h>
4#include <Utility/TUniquePtrVector.h>
5#include <Utility/TSpan.h>
6
7#include <vector>
8#include <memory>
9#include <string>
10#include <optional>
11#include <cstddef>
12
13namespace ph::editor
14{
15
19{
20 friend class FileSystemExplorer;
21
22private:
23 // A dummy struct to prevent the entry from being constructed by others (ctors are public for
24 // `unique_ptr` to access them)
25 struct CtorAccessToken
26 {};
27
28public:
29 FileSystemDirectoryEntry(FileSystemDirectoryEntry* parent, Path directoryPath, CtorAccessToken);
30
31 bool haveChildren() const;
33 FileSystemDirectoryEntry* getChild(std::size_t childIndex) const;
34 std::size_t numChildren() const;
35 const Path& getDirectoryPath() const;
36 const std::string& getDirectoryName() const;
37
38private:
39 inline FileSystemDirectoryEntry(FileSystemDirectoryEntry&& other) = default;
40 inline FileSystemDirectoryEntry& operator = (FileSystemDirectoryEntry&& rhs) = default;
41
42 void populateChildren();
43 void removeChildren();
44
46 TUniquePtrVector<FileSystemDirectoryEntry> m_children;
47 Path m_directoryPath;
48 std::string m_directoryName;
49 bool m_hasBeenPopulated;
50};
51
53{
54public:
56
57 std::optional<std::size_t> addRootPath(const Path& path);
58 void setCurrentRootPath(std::size_t rootPathIndex);
59 TSpanView<Path> getRootPaths() const;
60 const Path& getCurrentRootPath() const;
61
63
67 void expand(FileSystemDirectoryEntry* directoryEntry);
68
72 void collapse(FileSystemDirectoryEntry* directoryEntry);
73
74 std::vector<Path> makeItemListing(
75 FileSystemDirectoryEntry* directoryEntry,
76 bool withDirectories = true) const;
77
78private:
79 std::optional<std::size_t> findRootPathIndex(const Path& rootPath) const;
80
81 std::vector<Path> m_rootPaths;
82 TUniquePtrVector<FileSystemDirectoryEntry> m_rootDirectoryEntries;
83 std::size_t m_currentRootIndex;
84 FileSystemDirectoryEntry* m_currentDirectoryEntry;
85};
86
87}// end namespace ph::editor
Information for a filesystem directory.
Definition FileSystemExplorer.h:19
std::size_t numChildren() const
Definition FileSystemExplorer.cpp:44
bool haveChildren() const
Definition FileSystemExplorer.cpp:34
const std::string & getDirectoryName() const
Definition FileSystemExplorer.cpp:54
FileSystemDirectoryEntry * getChild(std::size_t childIndex) const
Definition FileSystemExplorer.cpp:39
FileSystemDirectoryEntry * getParent() const
Definition FileSystemExplorer.cpp:29
const Path & getDirectoryPath() const
Definition FileSystemExplorer.cpp:49
FileSystemDirectoryEntry(FileSystemDirectoryEntry *parent, Path directoryPath, CtorAccessToken)
Definition FileSystemExplorer.cpp:15
Definition FileSystemExplorer.h:53
std::optional< std::size_t > addRootPath(const Path &path)
Definition FileSystemExplorer.cpp:101
void expand(FileSystemDirectoryEntry *directoryEntry)
Expand the entry by linking it with potential child entries. Expanding an already-expanded entry has ...
Definition FileSystemExplorer.cpp:131
std::vector< Path > makeItemListing(FileSystemDirectoryEntry *directoryEntry, bool withDirectories=true) const
Definition FileSystemExplorer.cpp:143
const Path & getCurrentRootPath() const
Definition FileSystemExplorer.cpp:174
void collapse(FileSystemDirectoryEntry *directoryEntry)
Collapse the entry by removing all potential child entries. Collapsing an already-collapsed entry has...
Definition FileSystemExplorer.cpp:137
TSpanView< Path > getRootPaths() const
Definition FileSystemExplorer.cpp:169
void setCurrentRootPath(std::size_t rootPathIndex)
Definition FileSystemExplorer.cpp:122
FileSystemDirectoryEntry * getCurrentDirectoryEntry()
Definition FileSystemExplorer.cpp:180
FileSystemExplorer()
Definition FileSystemExplorer.cpp:90
Definition ph_editor.h:10