]> git.lyx.org Git - lyx.git/blob - src/bufferlist.h
fec67696c0bd3a5eb6d0f79f9131dbf4a5894480
[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-2000 The LyX Team
8  *
9  *           This file is Copyright 1996-2000
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 using std::vector;
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 public:
36         ///
37         typedef vector<Buffer *> Container;
38         ///
39         typedef Container::iterator iterator;
40         ///
41         typedef Container::const_iterator const_iterator;
42         ///
43         bool empty() const { return container.empty(); }
44         ///
45         void release(Buffer * buf);
46         ///
47         Buffer * newBuffer(string const & s, bool = false);
48         ///
49         Container::iterator begin() { return container.begin(); }
50         ///
51         Container::iterator end() { return container.end(); }
52         ///
53         Container::const_iterator begin() const { return container.begin(); }
54         ///
55         Container::const_iterator end() const { return container.end(); }
56         ///
57         Buffer * front() { return container.front(); }
58         ///
59         Buffer * operator[](int c) { return container[c]; }
60         ///
61         int size() const { return container.size(); }
62 private:
63         ///
64         Container container;
65 };
66
67
68 /** The class governing all the open buffers
69   This class governs all the currently open buffers. Currently all the buffer
70   are located in a static array, soon this will change and we will have a
71   linked list instead.
72  */
73 class BufferList {
74 public:
75         ///
76         BufferList();
77
78         /// state info
79         enum list_state {
80                 ///
81                 OK,
82                 ///
83                 CLOSING
84         };
85
86         /// returns the state of the bufferlist
87         list_state getState() const { return state_; }
88         
89         /** loads a LyX file or...
90             If the optional argument tolastfiles is false (default is
91             true), the file name will not be added to the last opened
92             files list
93         */  
94         Buffer * loadLyXFile(string const & filename, 
95                              bool tolastfiles = true);
96         
97         ///
98         bool empty() const;
99
100         ///
101         bool QwriteAll();
102
103         /// Close all open buffers.
104         void closeAll();
105
106         ///
107         void resize();
108
109         /// Read a file into a buffer readonly or not.
110         Buffer * readFile(string const &, bool ro);
111
112         /// Make a new file (buffer) using a template
113         Buffer * newFile(string const &, string);
114         /// returns a vector with all the buffers filenames
115         vector<string> getFileNames() const;
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 &) const;
136
137         /// returns true if the buffer is loaded
138         bool isLoaded(Buffer const * b) const;
139         
140         /// returns a pointer to the buffer with the given name.
141         Buffer * getBuffer(string const &);
142         /// returns a pointer to the buffer with the given number.
143         Buffer * getBuffer(int);
144
145 private:
146         ///
147         BufferStorage bstore;
148         
149         ///
150         list_state state_;
151 };
152
153 #endif