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