]> git.lyx.org Git - features.git/blob - src/BufferList.h
Write code in a language that everyone understands ?
[features.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 Buffer;
23 class OutputParams;
24
25 namespace support {
26 class FileName;
27 class FileNameList;
28 }
29
30 /**
31  * The class holds all all open buffers, and handles construction
32  * and deletions of new ones.
33  */
34 class BufferList {
35 public:
36         typedef std::vector<Buffer *>::iterator iterator;
37         typedef std::vector<Buffer *>::const_iterator const_iterator;
38
39 public:
40         BufferList();
41         ~BufferList();
42
43         iterator begin();
44         const_iterator begin() const;
45
46         iterator end();
47         const_iterator end() const;
48
49         /// create a new buffer
50         /// \return 0 if the Buffer creation is not possible for whatever reason.
51         Buffer * newBuffer(std::string const & s, bool ronly = false);
52
53         /// delete a buffer
54         void release(Buffer * b);
55
56         /// Release \p child if it really is a child and is not used elsewhere.
57         /// \return true is the file was closed.
58         bool releaseChild(Buffer * parent, Buffer * child);
59
60         /// Close all open buffers.
61         void closeAll();
62
63         /// returns a vector with all the buffers filenames
64         support::FileNameList const & fileNames() const;
65
66         /// return true if no buffers loaded
67         bool empty() const;
68
69         /// return head of buffer list if any
70         Buffer * first();
71
72         /// return back of buffer list if any
73         Buffer * last();
74
75         /// returns true if the buffer exists already
76         bool exists(support::FileName const &) const;
77
78         /// returns true if the buffer is loaded
79         bool isLoaded(Buffer const * b) const;
80
81         /// \return index of named buffer in buffer list
82         int bufferNum(support::FileName const & name) const;
83         /// \return a pointer to the buffer with the given name
84         Buffer * getBuffer(support::FileName const & name) const;
85         /// \return a pointer to the buffer with the given number
86         Buffer * getBuffer(unsigned int);
87         /// \return a pointer to the buffer whose temppath matches the given path
88         Buffer * getBufferFromTmp(std::string const & path);
89
90         /** returns a pointer to the buffer that follows argument in
91          * buffer list. The buffer following the last in list is the
92          * first one.
93          */
94         Buffer * next(Buffer const *) const;
95
96         /** returns a pointer to the buffer that precedes argument in
97          * buffer list. The buffer preceding the first in list is the
98          * last one.
99          */
100         Buffer * previous(Buffer const *) const;
101
102         /// \name Functions that just operate on all buffers
103         //@{
104         /// reset current author for all buffers
105         void setCurrentAuthor(docstring const & name, docstring const & email);
106         /// Call changed() on all buffers, internal or not
107         void changed(bool update_metrics) const;
108         /// emergency save for all buffers
109         void emergencyWriteAll();
110         /// FIXME
111         void updateIncludedTeXfiles(std::string const &, OutputParams const &);
112         //@}
113
114 private:
115         /// noncopiable
116         BufferList(BufferList const &);
117         void operator=(BufferList const &);
118
119         typedef std::vector<Buffer *> BufferStorage;
120
121         /// storage of all buffers
122         BufferStorage bstore;
123         /// storage of all internal buffers used for cut&paste, etc.
124         BufferStorage binternal;
125 };
126
127 /// Implementation is in LyX.cpp
128 extern BufferList & theBufferList();
129
130
131 } // namespace lyx
132
133 #endif // BUFFERLIST_H