1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-12-11 04:34:27 +03:00

BufferManager use safe_ptr to reference the Buffers

This commit is contained in:
Maxime Coste 2012-06-28 13:45:42 +02:00
parent 1289268174
commit 4dfc910195
3 changed files with 6 additions and 6 deletions

View File

@ -106,7 +106,7 @@ struct Modification
// The Buffer class permits to read and mutate this file
// representation. It also manage modifications undo/redo and
// provides tools to deal with the line/column nature of text.
class Buffer
class Buffer : public SafeCountable
{
public:
enum class Type

View File

@ -13,7 +13,7 @@ BufferManager::~BufferManager()
{
// delete remaining buffers
while (not m_buffers.empty())
delete m_buffers.begin()->second;
delete m_buffers.begin()->second.get();
}
void BufferManager::register_buffer(Buffer* buffer)
@ -23,7 +23,7 @@ void BufferManager::register_buffer(Buffer* buffer)
if (m_buffers.find(name) != m_buffers.end())
throw name_not_unique();
m_buffers[name] = buffer;
m_buffers[name] = safe_ptr<Buffer>(buffer);
}
void BufferManager::unregister_buffer(Buffer* buffer)
@ -42,7 +42,7 @@ Buffer* BufferManager::get_buffer(const String& name)
if (m_buffers.find(name) == m_buffers.end())
return nullptr;
return m_buffers[name];
return m_buffers[name].get();
}
CandidateList BufferManager::complete_buffername(const String& prefix,

View File

@ -14,7 +14,7 @@ class Buffer;
class BufferManager : public Singleton<BufferManager>
{
public:
typedef std::unordered_map<String, Buffer*> BufferMap;
typedef std::unordered_map<String, safe_ptr<Buffer>> BufferMap;
struct iterator : public BufferMap::const_iterator
{
@ -23,7 +23,7 @@ public:
iterator() {}
iterator(const parent_type& other) : parent_type(other) {}
Buffer& operator*() const { return *(parent_type::operator*().second); }
Buffer* operator->() const { return parent_type::operator*().second; }
Buffer* operator->() const { return parent_type::operator*().second.get(); }
};
~BufferManager();