]> git.lyx.org Git - lyx.git/blob - src/bufferlist.h
1c59ea8c3a5585c2bc731049f21ea900fb93d2fa
[lyx.git] / src / bufferlist.h
1 // -*- C++ -*-
2 /* This file is part of
3  * ====================================================== 
4  * 
5  *           LyX, The Document Processor         
6  *           Copyright 1995 Matthias Ettrich
7  *           Copyright 1995-1999 The LyX Team
8  *
9  *           This file is Copyright 1996
10  *           Lars Gullik Bjønnes
11  *
12  * ====================================================== */
13
14 #ifndef BUFFER_LIST_H
15 #define BUFFER_LIST_H
16
17 #ifdef __GNUG__
18 #pragma interface
19 #endif
20
21 #include "buffer.h"
22 #include "debug.h"
23
24 /** A class to hold all the buffers in a structure
25   The point of this class is to hide from bufferlist what kind
26   of structure the buffers are stored in. Should be no concern for
27   bufferlist if the buffers is in a array or in a linked list.
28
29   This class should ideally be enclosed inside class BufferList, but that
30   gave me an "internal gcc error".
31   */
32 class BufferStorage {
33 public:
34         ///
35         typedef vector<Buffer *> Container;
36         ///
37         typedef Container::iterator iterator;
38         ///
39         typedef Container::const_iterator const_iterator;
40         ///
41         bool empty() const { return container.empty(); }
42         ///
43         void release(Buffer * buf);
44         ///
45         Buffer * newBuffer(string const & s, LyXRC *, bool = false);
46         ///
47         Container::iterator begin() { return container.begin(); }
48         ///
49         Container::iterator end() { return container.end(); }
50         ///
51         Container::const_iterator begin() const { return container.begin(); }
52         ///
53         Container::const_iterator end() const { return container.end(); }
54         ///
55         Buffer * front() { return container.front(); }
56         ///
57         Buffer * operator[](int c) { return container[c]; }
58         ///
59         int size() const { return container.size(); }
60 private:
61         ///
62         Container container;
63 };
64
65
66 /** The class governing all the open buffers
67   This class governs all the currently open buffers. Currently all the buffer
68   are located in a static array, soon this will change and we will have a
69   linked list instead.
70  */
71 class BufferList {
72 public:
73         ///
74         BufferList();
75
76         /// state info
77         enum list_state {
78                 ///
79                 OK,
80                 ///
81                 CLOSING
82         };
83
84         /// returns the state of the bufferlist
85         list_state getState() { return state_; }
86         
87         /** loads a LyX file or...
88             If the optional argument tolastfiles is false (default is
89             true), the file name will not be added to the last opened
90             files list
91         */  
92         Buffer * loadLyXFile(string const & filename, 
93                              bool tolastfiles = true);
94         
95         ///
96         bool empty();
97
98         /// Saves buffer. Returns false if unsuccesful.
99         bool write(Buffer *, bool makeBackup);
100
101         ///
102         bool QwriteAll();
103
104         /// Close all open buffers.
105         void closeAll();
106
107         ///
108         void resize();
109
110         /// Read a file into a buffer readonly or not.
111         Buffer * readFile(string const &, bool ro);
112
113         /// Make a new file (buffer) using a template
114         Buffer * newFile(string const &, string);
115         /// returns a vector with all the buffers filenames
116         vector<string> getFileNames() const;
117         
118         ///
119         void updateInset(Inset *, bool = true);
120
121         ///
122         int unlockInset(UpdatableInset *);
123
124         ///
125         void updateIncludedTeXfiles(string const &);
126
127         ///
128         void emergencyWriteAll();
129
130         /** closes buffer
131           Returns false if operation was canceled
132           */
133         bool close(Buffer *);
134
135         ///
136         Buffer * first();
137         
138         /// returns true if the buffer exists already
139         bool exists(string const &);
140
141         /// returns a pointer to the buffer with the given name.
142         Buffer * getBuffer(string const &);
143         /// returns a pointer to the buffer with the given number.
144         Buffer * getBuffer(int);
145
146 private:
147         ///
148         BufferStorage bstore;
149         
150         ///
151         list_state state_;
152 };
153
154 #endif