]> git.lyx.org Git - lyx.git/blob - src/bufferlist.h
aadda105f1726308e0d4824b2bd0b2e86976d962
[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         BufferStorage();
36         ///
37         bool isEmpty();
38         ///
39         void release(Buffer* buf);
40         ///
41         Buffer* newBuffer(string const &s, LyXRC *, bool =false);
42 private:
43         enum {
44                 /** The max number of buffers there are possible to have
45                     loaded at the same time. (this only applies when we use an
46                     array)
47                 */
48                 NUMBER_OF_BUFFERS = 50
49         };
50         
51         /** The Bufferlist is currently implemented as a static array.
52           The buffers are new'ed and deleted as reqested.
53           */
54         Buffer *buffer[NUMBER_OF_BUFFERS];
55         ///
56         friend class BufferStorage_Iter;
57 };
58
59 /// An Iterator class for BufferStorage
60 class BufferStorage_Iter {
61 public:
62         ///
63         BufferStorage_Iter(const BufferStorage & bs)
64         { cs=&bs; index=0;}
65         /// next
66         Buffer* operator() ();
67         ///
68         Buffer* operator[] (int a);
69 private:
70         ///
71         const BufferStorage *cs;
72         ///
73         unsigned char index;
74 };
75
76
77
78 /** The class governing all the open buffers
79   This class governs all the currently open buffers. Currently all the buffer
80   are located in a static array, soon this will change and we will have a
81   linked list instead.
82  */
83 class BufferList {
84 public:
85         ///
86         BufferList();
87
88         ///
89         ~BufferList();
90
91         /// state info
92         enum list_state {
93                 ///
94                 OK,
95                 ///
96                 CLOSING
97         };
98
99         /// returns the state of the bufferlist
100         list_state getState() { return _state; }
101         
102         /** loads a LyX file or...
103           If the optional argument tolastfiles is false (default is
104             true), the file name will not be added to the last opened
105             files list
106             */  
107         Buffer* loadLyXFile(string const & filename, 
108                             bool tolastfiles = true);
109         
110         ///
111         bool isEmpty();
112
113         /// Saves buffer. Returns false if unsuccesful.
114         bool write(Buffer *, bool makeBackup = true);
115
116         ///
117         bool QwriteAll();
118
119         /// Close all open buffers.
120         void closeAll();
121
122         ///
123         void resize();
124
125         /// Read a file into a buffer readonly or not.
126         Buffer* readFile(string const &, bool ro);
127
128         /// Make a new file (buffer) using a template
129         Buffer* newFile(string const &, string);
130
131         /** This one must be moved to some other place.
132          */
133         void makePup(int);
134
135         ///** Later with multiple frames this should not be here.
136         // */
137         //Buffer* switchBuffer(Buffer *from, int);
138
139         ///
140         void updateInset(Inset*, bool = true);
141
142         ///
143         int unlockInset(UpdatableInset*);
144
145         ///
146         void updateIncludedTeXfiles(string const &);
147
148         ///
149         void emergencyWriteAll();
150
151         /** closes buffer
152           Returns false if operation was canceled
153           */
154         bool close(Buffer *);
155
156         ///
157         Buffer* first();
158         
159         /// returns true if the buffer exists already
160         bool exists(string const &);
161
162         /// returns a pointer to the buffer with the given name.
163         Buffer* getBuffer(string const &);
164         /// returns a pointer to the buffer with the given number.
165         Buffer* getBuffer(int);
166
167 private:
168         ///
169         BufferStorage bstore;
170         
171         ///
172         list_state _state;
173 };
174
175 #endif