]> git.lyx.org Git - lyx.git/blob - src/BufferList.h
listerrors.lyx : Update a link.
[lyx.git] / src / BufferList.h
1 // -*- C++ -*-
2 /**
3  * \file BufferList.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Lars Gullik Bjønnes
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef BUFFER_LIST_H
13 #define BUFFER_LIST_H
14
15 #include "support/docstring.h"
16
17 #include <vector>
18
19
20 namespace lyx {
21
22 class Author;
23 class Buffer;
24 class OutputParams;
25
26 namespace support {
27 class FileName;
28 class FileNameList;
29 }
30
31 /**
32  * The class holds all all open buffers, and handles construction
33  * and deletions of new ones.
34  */
35 class BufferList {
36 public:
37         typedef std::vector<Buffer *>::iterator iterator;
38         typedef std::vector<Buffer *>::const_iterator const_iterator;
39
40 public:
41         BufferList();
42         ~BufferList();
43
44         iterator begin();
45         const_iterator begin() const;
46
47         iterator end();
48         const_iterator end() const;
49
50         /// create a new buffer
51         /// \return 0 if the Buffer creation is not possible for whatever reason.
52         Buffer * newBuffer(std::string const & s, bool ronly = false);
53
54         /// delete a buffer
55         void release(Buffer * b);
56
57         /// Release \p child if it really is a child and is not used elsewhere.
58         /// \return true is the file was closed.
59         bool releaseChild(Buffer * parent, Buffer * child);
60
61         /// Close all open buffers.
62         void closeAll();
63
64         /// returns a vector with all the buffers filenames
65         support::FileNameList const & fileNames() const;
66
67         /// return true if no buffers loaded
68         bool empty() const;
69
70         /// return head of buffer list if any
71         Buffer * first();
72
73         /// return back of buffer list if any
74         Buffer * last();
75
76         /// returns true if the buffer exists already
77         bool exists(support::FileName const &) const;
78
79         /// returns true if the buffer is loaded
80         bool isLoaded(Buffer const * b) const;
81
82         /// \return index of named buffer in buffer list
83         int bufferNum(support::FileName const & name) const;
84
85         /** returns a pointer to the buffer with the given name
86          *
87          *  \param internal
88          *    If true, the buffer is searched also among internal buffers
89          */
90         Buffer * getBuffer(support::FileName const & name, bool internal = false) const;
91
92         /// \return a pointer to the buffer with the given number
93         Buffer * getBuffer(unsigned int);
94
95         /// \return a pointer to the buffer whose temppath matches the given path
96         Buffer * getBufferFromTmp(std::string const & path);
97
98         /** returns a pointer to the buffer that follows argument in
99          * buffer list. The buffer following the last in list is the
100          * first one.
101          */
102         Buffer * next(Buffer const *) const;
103
104         /** returns a pointer to the buffer that precedes argument in
105          * buffer list. The buffer preceding the first in list is the
106          * last one.
107          */
108         Buffer * previous(Buffer const *) const;
109
110         /// \name Functions that just operate on all buffers
111         //@{
112         /// reset current author for all buffers
113         void recordCurrentAuthor(Author const & author);
114         /// Call changed() on all buffers, internal or not
115         void changed(bool update_metrics) const;
116         /// emergency save for all buffers
117         void emergencyWriteAll();
118         /// FIXME
119         void updateIncludedTeXfiles(std::string const &, OutputParams const &);
120         //@}
121
122 private:
123         /// noncopiable
124         BufferList(BufferList const &);
125         void operator=(BufferList const &);
126
127         typedef std::vector<Buffer *> BufferStorage;
128
129         /// storage of all buffers
130         BufferStorage bstore;
131         /// storage of all internal buffers used for cut&paste, etc.
132         BufferStorage binternal;
133 };
134
135 /// Implementation is in LyX.cpp
136 extern BufferList & theBufferList();
137
138
139 } // namespace lyx
140
141 #endif // BUFFERLIST_H