2011-09-08 02:11:48 +02:00
|
|
|
#include "buffer_manager.hh"
|
|
|
|
|
2011-09-09 20:40:59 +02:00
|
|
|
#include <cassert>
|
|
|
|
|
2011-09-08 02:11:48 +02:00
|
|
|
#include "buffer.hh"
|
|
|
|
#include "window.hh"
|
2011-09-09 20:40:59 +02:00
|
|
|
#include "exception.hh"
|
2011-09-08 02:11:48 +02:00
|
|
|
|
|
|
|
namespace Kakoune
|
|
|
|
{
|
|
|
|
|
2011-09-09 20:40:59 +02:00
|
|
|
struct name_not_unique : logic_error {};
|
2011-09-08 02:11:48 +02:00
|
|
|
|
|
|
|
BufferManager* BufferManager::ms_instance = nullptr;
|
|
|
|
|
|
|
|
BufferManager& BufferManager::instance()
|
|
|
|
{
|
|
|
|
if (not ms_instance)
|
|
|
|
ms_instance = new BufferManager();
|
|
|
|
|
|
|
|
return *ms_instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BufferManager::delete_instance()
|
|
|
|
{
|
|
|
|
delete ms_instance;
|
|
|
|
ms_instance = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
BufferManager::BufferManager()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void BufferManager::register_buffer(Buffer* buffer)
|
|
|
|
{
|
|
|
|
assert(buffer);
|
|
|
|
const std::string& name = buffer->name();
|
|
|
|
if (m_buffers.find(name) != m_buffers.end())
|
|
|
|
throw name_not_unique();
|
|
|
|
|
|
|
|
m_buffers[name] = std::unique_ptr<Buffer>(buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BufferManager::delete_buffer(Buffer* buffer)
|
|
|
|
{
|
|
|
|
assert(buffer);
|
|
|
|
auto buffer_it = m_buffers.find(buffer->name());
|
|
|
|
assert(buffer_it->second.get() == buffer);
|
|
|
|
m_buffers.erase(buffer_it);
|
|
|
|
}
|
|
|
|
|
|
|
|
Buffer* BufferManager::get_buffer(const std::string& name)
|
|
|
|
{
|
|
|
|
if (m_buffers.find(name) == m_buffers.end())
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
return m_buffers[name].get();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|