From 2a932ef6df79436d0c2280283a64f6d45d1d342a Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Wed, 20 Apr 2016 22:37:23 +0100 Subject: Add operator for extracting nth element of a path --- gentoobrowse-api/service/fileUtils.cpp | 9 +++++++++ gentoobrowse-api/service/fileUtils.h | 4 ++++ 2 files changed, 13 insertions(+) diff --git a/gentoobrowse-api/service/fileUtils.cpp b/gentoobrowse-api/service/fileUtils.cpp index cfa02bc..05f797f 100644 --- a/gentoobrowse-api/service/fileUtils.cpp +++ b/gentoobrowse-api/service/fileUtils.cpp @@ -5,6 +5,15 @@ namespace Gentoo { namespace Utils { + namespace File { + boost::filesystem::path operator/(const boost::filesystem::path & p, unsigned int n) + { + auto pp = p.begin(); + while (n--) ++pp; + return *pp; + } + } + FileHandle::FileHandle(const std::string & path) : fh(open(path.c_str(), O_RDONLY)) { diff --git a/gentoobrowse-api/service/fileUtils.h b/gentoobrowse-api/service/fileUtils.h index 58d235f..c9a2ec4 100644 --- a/gentoobrowse-api/service/fileUtils.h +++ b/gentoobrowse-api/service/fileUtils.h @@ -6,6 +6,10 @@ namespace Gentoo { namespace Utils { + namespace File { + boost::filesystem::path operator/(const boost::filesystem::path & p, unsigned int n); + } + class FileHandle { public: FileHandle(const std::string & path); -- cgit v1.2.3