Skip to content

Commit

Permalink
libcore|FS: Added utility methods
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Jan 6, 2017
1 parent 464401e commit 1ecc1ae
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions doomsday/sdk/libcore/include/de/data/path.h
Expand Up @@ -409,6 +409,8 @@ class DENG2_PUBLIC Path : public ISerializable, public LogEntry::Arg::Base
*/
Segment const &reverseSegment(int reverseIndex) const;

Path subPath(Rangei const &range) const;

/**
* @return Total number of segments in the segment map. There is always
* at least one segment.
Expand Down
6 changes: 6 additions & 0 deletions doomsday/sdk/libcore/include/de/filesys/filesystem.h
Expand Up @@ -350,6 +350,12 @@ class DENG2_PUBLIC FileSystem : public System

void timeChanged(Clock const &);

public:
template <typename T>
static T &locate(String const &path) {
return FileSystem::get().root().locate<T>(path);
}

private:
DENG2_PRIVATE(d)
};
Expand Down
14 changes: 14 additions & 0 deletions doomsday/sdk/libcore/src/data/path.cpp
Expand Up @@ -322,6 +322,20 @@ Path::Segment const &Path::reverseSegment(int reverseIndex) const
return *d->extraSegments[reverseIndex - SEGMENT_BUFFER_SIZE];
}

Path Path::subPath(Rangei const &range) const
{
if (range.isEmpty())
{
return Path("", d->separator);
}
Path sub(segment(range.start), d->separator);
for (int i = range.start + 1; i < range.end; ++i)
{
sub = sub / segment(i);
}
return sub;
}

bool Path::operator == (Path const &other) const
{
if (this == &other) return true;
Expand Down

0 comments on commit 1ecc1ae

Please sign in to comment.