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