From 4dfc910195985d5d345fb6800f09bd9de3acd487 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Thu, 28 Jun 2012 13:45:42 +0200 Subject: [PATCH] BufferManager use safe_ptr to reference the Buffers --- src/buffer.hh | 2 +- src/buffer_manager.cc | 6 +++--- src/buffer_manager.hh | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/buffer.hh b/src/buffer.hh index 30cc2af9..80807efe 100644 --- a/src/buffer.hh +++ b/src/buffer.hh @@ -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 diff --git a/src/buffer_manager.cc b/src/buffer_manager.cc index 77c50288..3aa64aaa 100644 --- a/src/buffer_manager.cc +++ b/src/buffer_manager.cc @@ -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); } 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, diff --git a/src/buffer_manager.hh b/src/buffer_manager.hh index beba6652..80198942 100644 --- a/src/buffer_manager.hh +++ b/src/buffer_manager.hh @@ -14,7 +14,7 @@ class Buffer; class BufferManager : public Singleton { public: - typedef std::unordered_map BufferMap; + typedef std::unordered_map> 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();