]> git.lyx.org Git - lyx.git/blob - src/bufferlist.h
c3cd5d2783fbff2d651a95356380670ff0ce368c
[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 #define NEW_STORE 1
25
26 /** A class to hold all the buffers in a structure
27   The point of this class is to hide from bufferlist what kind
28   of structure the buffers are stored in. Should be no concern for
29   bufferlist if the buffers is in a array or in a linked list.
30
31   This class should ideally be enclosed inside class BufferList, but that
32   gave me an "internal gcc error".
33   */
34 class BufferStorage {
35 #ifdef NEW_STORE
36 public:
37         ///
38         typedef vector<Buffer *> Container;
39         ///
40         typedef Container::iterator iterator;
41         ///
42         bool empty() const { return container.empty(); }
43         ///
44         void release(Buffer * buf);
45         ///
46         Buffer * newBuffer(string const & s, LyXRC *, bool = false);
47         ///
48         Container::iterator begin() { return container.begin(); }
49         ///
50         Container::iterator end() { return container.end(); }
51         ///
52         Buffer * front() { return container.front(); }
53         ///
54         Buffer * operator[](int c) { return container[c]; }
55         ///
56         int size() const { return container.size(); }
57 private:
58         ///
59         Container container;
60 #else
61 public:
62         ///
63         BufferStorage();
64         ///
65         bool empty();
66         ///
67         void release(Buffer * buf);
68         ///
69         Buffer* newBuffer(string const & s, LyXRC *, bool =false);
70 private:
71         enum {
72                 /** The max number of buffers there are possible to have
73                     loaded at the same time. (this only applies when we use an
74                     array)
75                 */
76                 NUMBER_OF_BUFFERS = 50
77         };
78         
79         /** The Bufferlist is currently implemented as a static array.
80           The buffers are new'ed and deleted as reqested.
81           */
82         Buffer *buffer[NUMBER_OF_BUFFERS];
83         ///
84         friend class BufferStorage_Iter;
85 #endif
86 };
87
88
89 #ifndef NEW_STORE
90 /// An Iterator class for BufferStorage
91 class BufferStorage_Iter {
92 public:
93         ///
94         BufferStorage_Iter(BufferStorage const & bs)
95         { cs =& bs; index = 0;}
96         /// next
97         Buffer* operator() ();
98         ///
99         Buffer* operator[] (int a);
100 private:
101         ///
102         const BufferStorage *cs;
103         ///
104         unsigned char index;
105 };
106 #endif
107
108
109 /** The class governing all the open buffers
110   This class governs all the currently open buffers. Currently all the buffer
111   are located in a static array, soon this will change and we will have a
112   linked list instead.
113  */
114 class BufferList {
115 public:
116         ///
117         BufferList();
118
119         /// state info
120         enum list_state {
121                 ///
122                 OK,
123                 ///
124                 CLOSING
125         };
126
127         /// returns the state of the bufferlist
128         list_state getState() { return _state; }
129         
130         /** loads a LyX file or...
131           If the optional argument tolastfiles is false (default is
132             true), the file name will not be added to the last opened
133             files list
134             */  
135         Buffer * loadLyXFile(string const & filename, 
136                              bool tolastfiles = true);
137         
138         ///
139         bool empty();
140
141         /// Saves buffer. Returns false if unsuccesful.
142         bool write(Buffer *, bool makeBackup = true);
143
144         ///
145         bool QwriteAll();
146
147         /// Close all open buffers.
148         void closeAll();
149
150         ///
151         void resize();
152
153         /// Read a file into a buffer readonly or not.
154         Buffer * readFile(string const &, bool ro);
155
156         /// Make a new file (buffer) using a template
157         Buffer * newFile(string const &, string);
158
159         /** This one must be moved to some other place.
160          */
161         void makePup(int);
162
163         ///
164         void updateInset(Inset *, bool = true);
165
166         ///
167         int unlockInset(UpdatableInset *);
168
169         ///
170         void updateIncludedTeXfiles(string const &);
171
172         ///
173         void emergencyWriteAll();
174
175         /** closes buffer
176           Returns false if operation was canceled
177           */
178         bool close(Buffer *);
179
180         ///
181         Buffer * first();
182         
183         /// returns true if the buffer exists already
184         bool exists(string const &);
185
186         /// returns a pointer to the buffer with the given name.
187         Buffer * getBuffer(string const &);
188         /// returns a pointer to the buffer with the given number.
189         Buffer * getBuffer(int);
190
191 private:
192         ///
193         BufferStorage bstore;
194         
195         ///
196         list_state _state;
197 };
198
199 #endif