summaryrefslogtreecommitdiff
path: root/src/buffer_manager.hh
blob: e893d419eeede8f78e99e8e76139baba7825435d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#ifndef buffer_manager_hh_INCLUDED
#define buffer_manager_hh_INCLUDED

#include "completion.hh"
#include "utils.hh"

#include <unordered_map>

namespace Kakoune
{

class Buffer;

class BufferManager : public Singleton<BufferManager>
{
public:
    typedef std::unordered_map<String, Buffer*> BufferMap;

    struct iterator : public BufferMap::const_iterator
    {
        typedef BufferMap::const_iterator parent_type;

        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; }
    };

    void register_buffer(Buffer* buffer);
    void unregister_buffer(Buffer* buffer);

    iterator begin() const { return iterator(m_buffers.begin()); }
    iterator end() const { return iterator(m_buffers.end()); }
    size_t   count() const { return m_buffers.size(); }

    Buffer* get_buffer(const String& name);

    CandidateList complete_buffername(const String& prefix,
                                      size_t cursor_pos = String::npos);

private:
    BufferMap m_buffers;
};

}

#endif // buffer_manager_hh_INCLUDED