]> git.lyx.org Git - lyx.git/blob - src/bufferlist.h
7cf20fae51b07c98d10b62a214166e368a9788c3
[lyx.git] / src / bufferlist.h
1 // -*- C++ -*-
2 /* This file is part of
3 * ======================================================
4
5 *           LyX, The Document Processor          
6 *           Copyright (C) 1995 Matthias Ettrich
7 *
8 *           This file is Copyleft (C) 1996
9 *           Lars Gullik Bjønnes
10 *
11 *======================================================*/
12
13 #ifndef _BUFFER_LIST_H_
14 #define _BUFFER_LIST_H_
15
16 #ifdef __GNUG__
17 #pragma interface
18 #endif
19
20 #include "buffer.h"
21 #include "error.h"
22
23 /** A class to hold all the buffers in a structure
24   The point of this class is to hide from bufferlist what kind
25   of structure the buffers are stored in. Should be no concern for
26   bufferlist if the buffers is in a array or in a linked list.
27
28   This class should ideally be enclosed inside class BufferList, but that
29   gave me an "internal gcc error".
30   */
31 class BufferStorage {
32 public:
33         ///
34         BufferStorage();
35         ///
36         bool isEmpty();
37         ///
38         void release(Buffer* buf);
39         ///
40         Buffer* newBuffer(string const &s, LyXRC *, bool =false);
41 private:
42         enum {
43                 /** The max number of buffers there are possible to have
44                     loaded at the same time. (this only applies when we use an
45                     array)
46                 */
47                 NUMBER_OF_BUFFERS = 50
48         };
49         
50         /** The Bufferlist is currently implemented as a static array.
51           The buffers are new'ed and deleted as reqested.
52           */
53         Buffer *buffer[NUMBER_OF_BUFFERS];
54         ///
55         friend class BufferStorage_Iter;
56 };
57
58 /// An Iterator class for BufferStorage
59 class BufferStorage_Iter {
60 public:
61         ///
62         BufferStorage_Iter(const BufferStorage & bs)
63         { cs=&bs; index=0;}
64         /// next
65         Buffer* operator() ();
66         ///
67         Buffer* operator[] (int a);
68 private:
69         ///
70         const BufferStorage *cs;
71         ///
72         unsigned char index;
73 };
74
75
76
77 /** The class governing all the open buffers
78   This class governs all the currently open buffers. Currently all the buffer
79   are located in a static array, soon this will change and we will have a
80   linked list instead.
81  */
82 class BufferList {
83 public:
84         ///
85         BufferList();
86
87         ///
88         ~BufferList();
89
90         /// state info
91         enum list_state {
92                 ///
93                 OK,
94                 ///
95                 CLOSING
96         };
97
98         /// returns the state of the bufferlist
99         list_state getState() { return _state; }
100         
101         /** loads a LyX file or...
102           If the optional argument tolastfiles is false (default is
103             true), the file name will not be added to the last opened
104             files list
105             */  
106         Buffer* loadLyXFile(string const & filename, 
107                             bool tolastfiles = true);
108         
109         ///
110         bool isEmpty();
111
112         /// Saves buffer. Returns false if unsuccesful.
113         bool write(Buffer *, bool makeBackup = true);
114
115         ///
116         bool QwriteAll();
117
118         /// Close all open buffers.
119         void closeAll();
120
121         ///
122         void resize();
123
124         /// Read a file into a buffer readonly or not.
125         Buffer* readFile(string const &, bool ro);
126
127         /// Make a new file (buffer) using a template
128         Buffer* newFile(string const &, string);
129
130         /** This one must be moved to some other place.
131          */
132         void makePup(int);
133
134         ///** Later with multiple frames this should not be here.
135         // */
136         //Buffer* switchBuffer(Buffer *from, int);
137
138         ///
139         void updateInset(Inset*, bool = true);
140
141         ///
142         int unlockInset(UpdatableInset*);
143
144         ///
145         void updateIncludedTeXfiles(string const &);
146
147         ///
148         void emergencyWriteAll();
149
150         /** closes buffer
151           Returns false if operation was canceled
152           */
153         bool close(Buffer *);
154
155         ///
156         Buffer* first();
157         
158         /// returns true if the buffer exists already
159         bool exists(string const &);
160
161         /// returns a pointer to the buffer with the given name.
162         Buffer* getBuffer(string const &);
163         /// returns a pointer to the buffer with the given number.
164         Buffer* getBuffer(int);
165
166 private:
167         ///
168         BufferStorage bstore;
169         
170         ///
171         list_state _state;
172 };
173
174 #endif