]> git.lyx.org Git - features.git/blob - src/bufferlist.h
update libtool, try to make it work for std::streams (be VERY careful I have experien...
[features.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         bool empty() const { return container.empty(); }
40         ///
41         void release(Buffer * buf);
42         ///
43         Buffer * newBuffer(string const & s, LyXRC *, bool = false);
44         ///
45         Container::iterator begin() { return container.begin(); }
46         ///
47         Container::iterator end() { return container.end(); }
48         ///
49         Buffer * front() { return container.front(); }
50         ///
51         Buffer * operator[](int c) { return container[c]; }
52         ///
53         int size() const { return container.size(); }
54 private:
55         ///
56         Container container;
57 };
58
59
60 /** The class governing all the open buffers
61   This class governs all the currently open buffers. Currently all the buffer
62   are located in a static array, soon this will change and we will have a
63   linked list instead.
64  */
65 class BufferList {
66 public:
67         ///
68         BufferList();
69
70         /// state info
71         enum list_state {
72                 ///
73                 OK,
74                 ///
75                 CLOSING
76         };
77
78         /// returns the state of the bufferlist
79         list_state getState() { return _state; }
80         
81         /** loads a LyX file or...
82             If the optional argument tolastfiles is false (default is
83             true), the file name will not be added to the last opened
84             files list
85         */  
86         Buffer * loadLyXFile(string const & filename, 
87                              bool tolastfiles = true);
88         
89         ///
90         bool empty();
91
92         /// Saves buffer. Returns false if unsuccesful.
93         bool write(Buffer *, bool makeBackup = true);
94
95         ///
96         bool QwriteAll();
97
98         /// Close all open buffers.
99         void closeAll();
100
101         ///
102         void resize();
103
104         /// Read a file into a buffer readonly or not.
105         Buffer * readFile(string const &, bool ro);
106
107         /// Make a new file (buffer) using a template
108         Buffer * newFile(string const &, string);
109
110         /** This one must be moved to some other place.
111          */
112         void makePup(int);
113
114         ///
115         void updateInset(Inset *, bool = true);
116
117         ///
118         int unlockInset(UpdatableInset *);
119
120         ///
121         void updateIncludedTeXfiles(string const &);
122
123         ///
124         void emergencyWriteAll();
125
126         /** closes buffer
127           Returns false if operation was canceled
128           */
129         bool close(Buffer *);
130
131         ///
132         Buffer * first();
133         
134         /// returns true if the buffer exists already
135         bool exists(string const &);
136
137         /// returns a pointer to the buffer with the given name.
138         Buffer * getBuffer(string const &);
139         /// returns a pointer to the buffer with the given number.
140         Buffer * getBuffer(int);
141
142 private:
143         ///
144         BufferStorage bstore;
145         
146         ///
147         list_state _state;
148 };
149
150 #endif