]> git.lyx.org Git - lyx.git/blob - src/bufferlist.h
Fix fuer #209
[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-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 #include "LString.h"
27
28 /** A class to hold all the buffers in a structure
29   The point of this class is to hide from bufferlist what kind
30   of structure the buffers are stored in. Should be no concern for
31   bufferlist if the buffers is in a array or in a linked list.
32
33   This class should ideally be enclosed inside class BufferList, but that
34   gave me an "internal gcc error".
35   */
36 class BufferStorage : boost::noncopyable {
37 public:
38         ///
39         typedef std::vector<Buffer *> Container;
40         ///
41         typedef Container::iterator iterator;
42         ///
43         typedef Container::const_iterator const_iterator;
44         ///
45         typedef Container::size_type size_type;
46         ///
47         bool empty() const { return container.empty(); }
48         ///
49         void release(Buffer * buf);
50         ///
51         Buffer * newBuffer(string const & s, bool = false);
52         ///
53         Container::iterator begin() { return container.begin(); }
54         ///
55         Container::iterator end() { return container.end(); }
56         ///
57         Container::const_iterator begin() const { return container.begin(); }
58         ///
59         Container::const_iterator end() const { return container.end(); }
60         ///
61         Buffer * front() { return container.front(); }
62         ///
63         Buffer * operator[](int c) { return container[c]; }
64         ///
65         size_type size() const { return container.size(); }
66 private:
67         ///
68         Container container;
69 };
70
71
72 /** The class govern all open buffers.
73  */
74 class BufferList : boost::noncopyable {
75 public:
76         ///
77         BufferList();
78
79         /// state info
80         enum list_state {
81                 ///
82                 OK,
83                 ///
84                 CLOSING
85         };
86
87         /// returns the state of the bufferlist
88         list_state getState() const { return state_; }
89         
90         /** loads a LyX file or...
91             If the optional argument tolastfiles is false (default is
92             true), the file name will not be added to the last opened
93             files list
94         */  
95         Buffer * loadLyXFile(string const & filename, 
96                              bool tolastfiles = true);
97         
98         ///
99         bool empty() const;
100
101         ///
102         bool qwriteAll();
103
104         /// Close all open buffers.
105         void closeAll();
106
107         /// Read a file into a buffer readonly or not.
108         Buffer * readFile(string const &, bool ro);
109
110         /// Make a new file (buffer) using a template
111         Buffer * newFile(string const &, string, bool isNamed = false);
112         /// returns a vector with all the buffers filenames
113         std::vector<string> const getFileNames() const;
114
115         ///
116         int unlockInset(UpdatableInset *);
117
118         ///
119         void updateIncludedTeXfiles(string const &);
120
121         ///
122         void emergencyWriteAll();
123         
124         /** Close buffer.
125             @param buf the buffer that should be closed
126             @return #false# if operation was canceled
127           */
128         bool close(Buffer * buf);
129
130         ///
131         Buffer * first();
132         
133         /// returns true if the buffer exists already
134         bool exists(string const &) const;
135
136         /// returns true if the buffer is loaded
137         bool isLoaded(Buffer const * b) const;
138         
139         /// returns a pointer to the buffer with the given name.
140         Buffer * getBuffer(string const &);
141         /// returns a pointer to the buffer with the given number.
142         Buffer * getBuffer(unsigned int);
143
144 private:
145         /// ask to save a buffer on quit
146         bool qwriteOne(Buffer * buf, string const & fname, string & unsaved_list); 
147
148         ///
149         BufferStorage bstore;
150         
151         ///
152         list_state state_;
153         ///
154         void emergencyWrite(Buffer * buf);
155 };
156
157 #endif