Skip to content

Commit

Permalink
Allow use of static and global File, Directory objects (#2529)
Browse files Browse the repository at this point in the history
Added simple default filesystem mechanism for `FsBase` objects.
File system is passed to constructor, but null is now interpreted as 'default file system'.

Sming implements the `IFS::getDefaultFileSystem()` function.
  • Loading branch information
mikee47 authored Jul 20, 2022
1 parent afa167e commit fa95914
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Sming/Components/IFS
4 changes: 1 addition & 3 deletions Sming/Core/Data/Stream/FileStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@
class FileStream : public IFS::FileStream
{
public:
FileStream() : IFS::FileStream(::getFileSystem())
{
}
using IFS::FileStream::FileStream;

/** @brief Create a file stream
* @param fileName Name of file to open
Expand Down
9 changes: 9 additions & 0 deletions Sming/Core/FileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ namespace SmingInternal
IFS::FileSystem* activeFileSystem;
}

namespace IFS
{
FileSystem* getDefaultFileSystem()
{
return SmingInternal::activeFileSystem;
}

} // namespace IFS

void fileSetFileSystem(IFS::IFileSystem* fileSystem)
{
if(SmingInternal::activeFileSystem != fileSystem) {
Expand Down
22 changes: 2 additions & 20 deletions Sming/Core/FileSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ using FileAttribute = IFS::FileAttribute;
using FileAttributes = IFS::FileAttributes;
using FileStat = IFS::Stat;
using FileNameStat = IFS::NameStat;
using File = IFS::File;
using Directory = IFS::Directory;
constexpr int FS_OK = IFS::FS_OK;

namespace SmingInternal
Expand All @@ -45,26 +47,6 @@ extern IFS::FileSystem* activeFileSystem;

} // namespace SmingInternal

class File : public IFS::File
{
public:
File() : IFS::File(SmingInternal::activeFileSystem)
{
}
};

/**
* @brief Directory stream class
* @ingroup stream data
*/
class Directory : public IFS::Directory
{
public:
Directory() : IFS::Directory(SmingInternal::activeFileSystem)
{
}
};

/*
* Boilerplate check for file function wrappers to catch undefined filesystem.
*/
Expand Down

0 comments on commit fa95914

Please sign in to comment.