Add a PieceTable to Buffer
This commit is contained in:
parent
2805ac36d3
commit
aa45f6d6dc
@ -8,6 +8,7 @@ Buffer::Buffer()
|
||||
{
|
||||
m_file_buffer = nullptr;
|
||||
m_file_buffer_size = 0u;
|
||||
m_piece_table = std::make_shared<PieceTable>(nullptr, 0u);
|
||||
}
|
||||
|
||||
Buffer::~Buffer()
|
||||
@ -52,6 +53,21 @@ bool Buffer::load_from_file(const char * filename)
|
||||
m_lines.push_back(std::make_shared<Text>(it->first, it->second));
|
||||
}
|
||||
|
||||
m_piece_table = std::make_shared<PieceTable>(m_file_buffer, m_file_buffer_size);
|
||||
for (auto it = text_loader.begin(); it != text_loader.end(); it++)
|
||||
{
|
||||
auto pd_n = m_piece_table->add_piece_descriptor();
|
||||
PieceTable::PieceDescriptor & pd = pd_n.second;
|
||||
pd.prev = m_piece_table->end_descriptor->prev;
|
||||
pd.next = PIECE_DESCRIPTOR_INDEX_END;
|
||||
pd.start = it->first - m_file_buffer;
|
||||
pd.length = it->second;
|
||||
pd.n_chars = it->second; /* TODO: fix this for other encodings */
|
||||
pd.eol = 1u;
|
||||
(*m_piece_table)[m_piece_table->end_descriptor->prev].next = pd_n.first;
|
||||
m_piece_table->end_descriptor->prev = pd_n.first;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <list>
|
||||
#include <memory>
|
||||
#include "Text.h"
|
||||
#include "PieceTable.h"
|
||||
|
||||
class Buffer
|
||||
{
|
||||
@ -30,6 +31,7 @@ protected:
|
||||
LinesType m_lines;
|
||||
uint8_t * m_file_buffer;
|
||||
unsigned long m_file_buffer_size;
|
||||
std::shared_ptr<PieceTable> m_piece_table;
|
||||
|
||||
void free_file_buffer();
|
||||
};
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
#include <stdint.h>
|
||||
#include "PagedBuffer.h"
|
||||
#include <utility>
|
||||
|
||||
#define PIECE_DESCRIPTOR_INDEX_START 0u
|
||||
#define PIECE_DESCRIPTOR_INDEX_END 1u
|
||||
@ -30,9 +31,17 @@ public:
|
||||
|
||||
PieceTable(const uint8_t * file_buffer, unsigned long file_buffer_size);
|
||||
|
||||
PieceDescriptor & add_piece_descriptor()
|
||||
std::pair<uint32_t, PieceDescriptor &> add_piece_descriptor()
|
||||
{
|
||||
return m_piece_descriptors[m_piece_descriptor_index++];
|
||||
uint32_t index = m_piece_descriptor_index;
|
||||
m_piece_descriptor_index++;
|
||||
PieceDescriptor & pd = m_piece_descriptors[index];
|
||||
return std::pair<uint32_t, PieceDescriptor &>(index, pd);
|
||||
}
|
||||
|
||||
PieceDescriptor & operator[](uint32_t index)
|
||||
{
|
||||
return m_piece_descriptors[index];
|
||||
}
|
||||
|
||||
PieceDescriptor * start_descriptor;
|
||||
|
Loading…
x
Reference in New Issue
Block a user