Skip to content

C++ class: DirectoryTree

Index · Français

Description

Noncopyable lazily loaded directory tree.

Qualified name : gaspardos::desktop::DirectoryTree.

Header : bindings/cpp/file_explorer.hpp. C++98.

When to use it

Display a hierarchy without scanning the entire volume.

Simple program example

#include "desktop_native.hpp"
#include <cstdio>
#include <cstring>

int main()
{
    gaspardos::desktop::NativeFileAccess access;
    gaspardos::desktop::DirectoryTree    tree(access);
    if (!tree.open("/AHCIDISK0"))
        return 1;
    for (unsigned i = 0; i < 10000 && tree.loading(); ++i)
    {
        tree.tick();
        GO64_yield();
    }
    return tree.loading() ? 1 : 0;
}

Building from Windows

Save the program above as build/api-examples/DirectoryTree.cpp from the repository root. Create the directory if necessary.

PowerShell — from the repository root:

New-Item -ItemType Directory -Force build/api-examples | Out-Null
& .\build-x64-install\bin\x86_64-gaspardos-gcc.exe -std=gnu1x -O2 -mno-red-zone -c bindings/native/gaspardos_x64_syscall.c -o build/api-examples/syscall.o
if ($LASTEXITCODE -ne 0) { throw "C compilation failed" }
& .\build-x64-install\bin\x86_64-gaspardos-g++.exe -std=c++98 -O2 -Ibindings/cpp build/api-examples/DirectoryTree.cpp build/api-examples/syscall.o bindings/cpp/file_explorer.cpp bindings/cpp/desktop_native.cpp -o build/api-examples/DirectoryTree-x64.elf
if ($LASTEXITCODE -ne 0) { throw "C++ compilation/link failed" }

Run the ELF on GaspardOS, not Windows. The driver supplies CRT and libraries. Prepare the required volumes/services; examples bound their waits and may exit on backpressure rather than retry. Successful compilation does not validate kernel execution.

The headers, implementation files, native wrappers and complete examples are available under Source files.

Class methods

explicit DirectoryTree(FileAccess& access)

Backend reference; it must outlive the tree.

bool open(const std::string& root)

Open a root and reset cache.

void toggle(std::size_t index)

Expand/collapse the indexed row; may start loading.

bool tick()

Advance lazy loading and rebuild rows.

const std::string& root() const

Current root.

bool loading() const

Report an active directory read.

Public data

rows : vector ; message : string. Limites / limits: depth 32, 4096 visible rows, ~2 MiB cache.

Native contract

LP64 ABI, 32-bit wchar_t, no packing. Native negative results are not errno. Handle -11 with yield and an application limit. Referenced objects must outlive their users; do not copy handle owners. File uses stdio/errno and invalidates its stream on close, even on error.