diff --git a/lib/core/include/core/File.hh b/lib/core/include/core/File.hh index 5f84641..d47ae88 100644 --- a/lib/core/include/core/File.hh +++ b/lib/core/include/core/File.hh @@ -14,7 +14,6 @@ namespace erw { -namespace core { struct File { @@ -36,6 +35,8 @@ struct File /** Destructor. */ virtual ~File(); + String path() const noexcept; + /** Seek to an absolute position in the file. */ virtual File& seek(size_t pos) = 0; @@ -46,8 +47,12 @@ struct File virtual File& seek(ssize_t offset, SeekFrom from) = 0; protected: + const String mPath; + /** Convert a File::Mode to an iostream openmode bitset. */ virtual std::ios_base::openmode modeToIOSMode(Mode mode); + + File(const String& path); }; @@ -57,7 +62,7 @@ struct InFile { /** Open a file at `path` for reading. */ InFile(const String& path, File::Mode mode); - + /** Deleted copy constructor. File handles cannot be copied. */ InFile(const InFile& other) = delete; @@ -69,6 +74,8 @@ struct InFile /** Move `other` to this InFile. File handles cannot be copied. */ InFile& operator=(InFile& other); + String path() const; + /** Read up to `count` characters into the provided `buffer`. */ InFile& read(char* buffer, ssize_t count); @@ -79,6 +86,7 @@ struct InFile InFile& seek(ssize_t pos, File::SeekFrom from) override; private: + String mPath; std::ifstream mStream; std::ios_base::openmode modeToIOSMode(File::Mode mode) override; @@ -101,5 +109,4 @@ private: std::ofstream stream; }; -} /* namespace core */ } /* namespace erw */ diff --git a/lib/core/include/core/String.hh b/lib/core/include/core/String.hh index 0206db5..2e65fe4 100644 --- a/lib/core/include/core/String.hh +++ b/lib/core/include/core/String.hh @@ -10,9 +10,7 @@ namespace erw { -namespace core { typedef std::string String; -} /* namespace core */ } /* namespace erw */ diff --git a/lib/core/src/File.cc b/lib/core/src/File.cc index 68ec789..3fa3430 100644 --- a/lib/core/src/File.cc +++ b/lib/core/src/File.cc @@ -10,16 +10,37 @@ namespace erw { -namespace core { #pragma mark - File +/* + * File::File -- + */ +File::File(const String& path) + : mPath(path) +{ } + + +/* + * File::~File -- + */ File::~File() { } /* - * InFile::modeToIOSMode -- + * File::path -- + */ +String +File::path() + const noexcept +{ + return mPath; +} + + +/* + * File::modeToIOSMode -- */ std::ios_base::openmode File::modeToIOSMode(Mode mode) @@ -44,7 +65,8 @@ File::modeToIOSMode(Mode mode) */ InFile::InFile(const String& path, InFile::Mode mode) - : mStream(path, modeToIOSMode(mode)) + : File(path), + mStream(path, modeToIOSMode(mode)) { } @@ -52,7 +74,8 @@ InFile::InFile(const String& path, * InFile::InFile -- */ InFile::InFile(InFile&& other) - : mStream(std::move(other.mStream)) + : File(other.mPath), + mStream(std::move(other.mStream)) { } @@ -136,5 +159,4 @@ InFile::modeToIOSMode(File::Mode mode) #pragma mark - OutFile -} /* namespace core */ } /* namespace erw */