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