kge/Buffer.h

59 lines
1.2 KiB
C++

///
/// \file Buffer.h
/// \author kyle
/// \date 2023-10-10
/// \brief A buffer is the basic document type.
///
#ifndef KEPP_FRAME_H
#define KEPP_FRAME_H
#include <vector>
#include "Defs.h"
#include "File.h"
typedef std::vector<std::vector<uint8_t>> BufferContents;
/// A Buffer is the atom of text editing. It represents a single document,
/// whether a memory-only buffer or a file-backed buffer.
///
/// \details
///
/// There are currently two main types of Buffers: file-backed and virtual.
/// A virtual buffer describes any buffer that isn't backed by a file.
///
/// A virtual buffer can be promoted to a file frame, but a file buffer
/// cannot be demoted to a virtual buffer.
class Buffer {
public:
/// The constructor with no arguments generates a new anonymous
/// buffer.
Buffer();
/// A single constructor generates a virtual buffer.
Buffer(std::string fName);
/// Instantiate a Buffer pointing to fPath.
Buffer(std::string fName, std::string fPath);
std::string Name() const { return this->name; }
int Flush(OptString altPath);
void ChangePath(std::string newPath);
private:
std::string name;
OptString path;
OptFile file;
BufferContents contents;
};
#endif // KEPP_FRAME_H