diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2011-09-08 00:13:19 +0000 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2011-09-08 00:13:19 +0000 |
| commit | d3499ecd9cc7b2b685d1bc96ac7591f29a1752ce (patch) | |
| tree | f66659eac5163b4c27f599e3fe29b9a3f94d20c7 /src/buffer.cc | |
| parent | 535e2005870ce6e0822418307bde22b09b8db3df (diff) | |
Window lifetime is now handled by it's buffer.
A window cannot outlive it's buffer, so it makes sense to keep only a
reference on it hand have the buffer manage the window lifetime.
Diffstat (limited to 'src/buffer.cc')
| -rw-r--r-- | src/buffer.cc | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/buffer.cc b/src/buffer.cc index 2a09cc5b..81ba07e6 100644 --- a/src/buffer.cc +++ b/src/buffer.cc @@ -1,8 +1,10 @@ #include "buffer.hh" #include "buffer_manager.hh" +#include "window.hh" #include <cassert> +#include <algorithm> namespace Kakoune { @@ -314,4 +316,22 @@ void Buffer::append_modification(Modification&& modification) m_current_undo_group.push_back(modification); } +struct window_already_registered {}; + +void Buffer::register_window(Window* window) +{ + if (std::find(m_windows.begin(), m_windows.end(), window) != m_windows.end()) + throw window_already_registered(); + + m_windows.push_front(std::unique_ptr<Window>(window)); +} + +void Buffer::delete_window(Window* window) +{ + assert(&window->buffer() == this); + auto window_it = std::find(m_windows.begin(), m_windows.end(), window); + assert(window_it != m_windows.end()); + m_windows.erase(window_it); +} + } |
