From 86f672af2b9b7ef645d4ebf325c5803e847202e2 Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Sat, 1 Oct 2016 10:44:11 -0700 Subject: [PATCH] File: Add misc useful API from C++17. --- firmware/application/file.cpp | 8 ++++++++ firmware/application/file.hpp | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/firmware/application/file.cpp b/firmware/application/file.cpp index e7fec84e4..46d5fe81a 100644 --- a/firmware/application/file.cpp +++ b/firmware/application/file.cpp @@ -251,6 +251,10 @@ path& path::replace_extension(const path& replacement) { return *this; } +bool operator<(const path& lhs, const path& rhs) { + return lhs.native() < rhs.native(); +} + bool operator>(const path& lhs, const path& rhs) { return lhs.native() > rhs.native(); } @@ -276,6 +280,10 @@ directory_iterator& directory_iterator::operator++() { return *this; } +bool is_directory(const file_status s) { + return (s & AM_DIR); +} + bool is_regular_file(const file_status s) { return !(s & AM_DIR); } diff --git a/firmware/application/file.hpp b/firmware/application/file.hpp index cca7f2203..57e63fd9d 100644 --- a/firmware/application/file.hpp +++ b/firmware/application/file.hpp @@ -158,6 +158,7 @@ private: string_type _s; }; +bool operator<(const path& lhs, const path& rhs); bool operator>(const path& lhs, const path& rhs); using file_status = BYTE; @@ -178,6 +179,10 @@ struct directory_entry : public FILINFO { return fattrib; } + std::uintmax_t size() const { + return fsize; + }; + const std::filesystem::path path() const noexcept { return { fname }; }; }; @@ -221,6 +226,7 @@ inline directory_iterator end(const directory_iterator&) noexcept { return { }; inline bool operator!=(const directory_iterator& lhs, const directory_iterator& rhs) { return lhs.impl != rhs.impl; }; +bool is_directory(const file_status s); bool is_regular_file(const file_status s); space_info space(const path& p);