BufferManager use safe_ptr to reference the Buffers
This commit is contained in:
parent
1289268174
commit
4dfc910195
|
@ -106,7 +106,7 @@ struct Modification
|
||||||
// The Buffer class permits to read and mutate this file
|
// The Buffer class permits to read and mutate this file
|
||||||
// representation. It also manage modifications undo/redo and
|
// representation. It also manage modifications undo/redo and
|
||||||
// provides tools to deal with the line/column nature of text.
|
// provides tools to deal with the line/column nature of text.
|
||||||
class Buffer
|
class Buffer : public SafeCountable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum class Type
|
enum class Type
|
||||||
|
|
|
@ -13,7 +13,7 @@ BufferManager::~BufferManager()
|
||||||
{
|
{
|
||||||
// delete remaining buffers
|
// delete remaining buffers
|
||||||
while (not m_buffers.empty())
|
while (not m_buffers.empty())
|
||||||
delete m_buffers.begin()->second;
|
delete m_buffers.begin()->second.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BufferManager::register_buffer(Buffer* buffer)
|
void BufferManager::register_buffer(Buffer* buffer)
|
||||||
|
@ -23,7 +23,7 @@ void BufferManager::register_buffer(Buffer* buffer)
|
||||||
if (m_buffers.find(name) != m_buffers.end())
|
if (m_buffers.find(name) != m_buffers.end())
|
||||||
throw name_not_unique();
|
throw name_not_unique();
|
||||||
|
|
||||||
m_buffers[name] = buffer;
|
m_buffers[name] = safe_ptr<Buffer>(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BufferManager::unregister_buffer(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())
|
if (m_buffers.find(name) == m_buffers.end())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
return m_buffers[name];
|
return m_buffers[name].get();
|
||||||
}
|
}
|
||||||
|
|
||||||
CandidateList BufferManager::complete_buffername(const String& prefix,
|
CandidateList BufferManager::complete_buffername(const String& prefix,
|
||||||
|
|
|
@ -14,7 +14,7 @@ class Buffer;
|
||||||
class BufferManager : public Singleton<BufferManager>
|
class BufferManager : public Singleton<BufferManager>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef std::unordered_map<String, Buffer*> BufferMap;
|
typedef std::unordered_map<String, safe_ptr<Buffer>> BufferMap;
|
||||||
|
|
||||||
struct iterator : public BufferMap::const_iterator
|
struct iterator : public BufferMap::const_iterator
|
||||||
{
|
{
|
||||||
|
@ -23,7 +23,7 @@ public:
|
||||||
iterator() {}
|
iterator() {}
|
||||||
iterator(const parent_type& other) : parent_type(other) {}
|
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; }
|
Buffer* operator->() const { return parent_type::operator*().second.get(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
~BufferManager();
|
~BufferManager();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user