]> git.lyx.org Git - features.git/blob - src/bufferlist.h
Reduced header file includes somewhat
[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-2001 The LyX Team
8  *
9  *           This file is Copyright 1996-2001
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 class Buffer;
22 class UpdatableInset;
23 #include <vector>
24 #include <boost/utility.hpp>
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 : boost::noncopyable {
35 public:
36         ///
37         typedef std::vector<Buffer *> Container;
38         ///
39         typedef Container::iterator iterator;
40         ///
41         typedef Container::const_iterator const_iterator;
42         ///
43         typedef Container::size_type size_type;
44         ///
45         bool empty() const { return container.empty(); }
46         ///
47         void release(Buffer * buf);
48         ///
49         Buffer * newBuffer(string const & s, bool = false);
50         ///
51         Container::iterator begin() { return container.begin(); }
52         ///
53         Container::iterator end() { return container.end(); }
54         ///
55         Container::const_iterator begin() const { return container.begin(); }
56         ///
57         Container::const_iterator end() const { return container.end(); }
58         ///
59         Buffer * front() { return container.front(); }
60         ///
61         Buffer * operator[](int c) { return container[c]; }
62         ///
63         size_type size() const { return container.size(); }
64 private:
65         ///
66         Container container;
67 };
68
69
70 /** The class govern all open buffers.
71  */
72 class BufferList : boost::noncopyable {
73 public:
74         ///
75         BufferList();
76
77         /// state info
78         enum list_state {
79                 ///
80                 OK,
81                 ///
82                 CLOSING
83         };
84
85         /// returns the state of the bufferlist
86         list_state getState() const { return state_; }
87         
88         /** loads a LyX file or...
89             If the optional argument tolastfiles is false (default is
90             true), the file name will not be added to the last opened
91             files list
92         */  
93         Buffer * loadLyXFile(string const & filename, 
94                              bool tolastfiles = true);
95         
96         ///
97         bool empty() const;
98
99         ///
100         bool qwriteAll();
101
102         /// Close all open buffers.
103         void closeAll();
104
105         /// Read a file into a buffer readonly or not.
106         Buffer * readFile(string const &, bool ro);
107
108         /// Make a new file (buffer) using a template
109         Buffer * newFile(string const &, string, bool isNamed = false);
110         /// returns a vector with all the buffers filenames
111         std::vector<string> const getFileNames() const;
112
113         ///
114         int unlockInset(UpdatableInset *);
115
116         ///
117         void updateIncludedTeXfiles(string const &);
118
119         ///
120         void emergencyWriteAll();
121         
122         /** Close buffer.
123             @param buf the buffer that should be closed
124             @return #false# if operation was canceled
125           */
126         bool close(Buffer * buf);
127
128         ///
129         Buffer * first();
130         
131         /// returns true if the buffer exists already
132         bool exists(string const &) const;
133
134         /// returns true if the buffer is loaded
135         bool isLoaded(Buffer const * b) 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(unsigned int);
141
142 private:
143         ///
144         BufferStorage bstore;
145         
146         ///
147         list_state state_;
148         ///
149         void emergencyWrite(Buffer * buf);
150 };
151
152 #endif