Putting Buffers in main to test things out.
This commit is contained in:
76
Buffer.cc
76
Buffer.cc
@@ -22,10 +22,11 @@
|
||||
///
|
||||
|
||||
|
||||
#include <filesystem>
|
||||
#include <iterator>
|
||||
#include <optional>
|
||||
#include <random>
|
||||
#include <sstream>
|
||||
#include <iterator>
|
||||
|
||||
#include "Buffer.h"
|
||||
|
||||
@@ -56,6 +57,17 @@ Buffer::Buffer(std::string fName)
|
||||
}
|
||||
|
||||
|
||||
Buffer::Buffer(std::filesystem::path fPath)
|
||||
: dirty(false), path(OptString(fPath.string()))
|
||||
{
|
||||
this->name = fPath.filename().string();
|
||||
this->Cursor() = Cursor();
|
||||
|
||||
this->file = OptFile(fPath.string());
|
||||
}
|
||||
|
||||
|
||||
|
||||
Buffer::Buffer(std::string fName, std::string fPath)
|
||||
: dirty(false), name(std::move(fName)), path(fPath)
|
||||
{
|
||||
@@ -141,12 +153,23 @@ Buffer::Refresh()
|
||||
return FileStatus::FileStatusIOFailed;
|
||||
}
|
||||
|
||||
size_t currentLine = 0;
|
||||
|
||||
while (realHandle->good()) {
|
||||
std::string temp;
|
||||
while (std::getline(*realHandle, temp)) {
|
||||
std::vector<uint8_t> row(temp.begin(), temp.end());
|
||||
row.push_back('\n');
|
||||
this->contents.push_back(row);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
auto status = Buffer::FileStatus::FileStatusOK;
|
||||
if (!realHandle->eof()) {
|
||||
status = FileStatus::FileStatusIOFailed;
|
||||
}
|
||||
realHandle->close();
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
@@ -178,3 +201,48 @@ Buffer::MarkDirty()
|
||||
}
|
||||
|
||||
|
||||
size_t
|
||||
Buffer::Size()
|
||||
{
|
||||
size_t size = 0;
|
||||
|
||||
for (const auto& line : this->contents) {
|
||||
size += line.size();
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Buffer::Close()
|
||||
{
|
||||
this->clearContents();
|
||||
this->dirty = false;
|
||||
this->file = std::nullopt;
|
||||
this->path = std::nullopt;
|
||||
this->name = std::string("deleted buffer (" + this->name + ")");
|
||||
}
|
||||
|
||||
|
||||
std::string
|
||||
Buffer::FileStatusToString(Buffer::FileStatus status)
|
||||
{
|
||||
switch (status) {
|
||||
case FileStatus::FileStatusOK:
|
||||
return std::string("OK");
|
||||
case FileStatus::FileStatusReadOnly:
|
||||
return std::string("read-only file");
|
||||
case FileStatus::FileStatusIOFailed:
|
||||
return std::string("I/O failure");
|
||||
case FileStatus::FileStatusVirtual:
|
||||
return std::string("virtual buffer");
|
||||
case FileStatus::FileStatusInvalidPermissions:
|
||||
return std::string("invalid permissions");
|
||||
case FileStatus::FileStatusNonExistent:
|
||||
return std::string("file does not exist");
|
||||
default:
|
||||
abort();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user