]> git.lyx.org Git - lyx.git/blob - src/bufferlist.h
fix typo that put too many include paths for most people
[lyx.git] / src / bufferlist.h
1 // -*- C++ -*-
2 /** \file
3  *  Copyright 2002 the LyX Team
4  *  Read the file COPYING
5  *
6  *  \author Lars Gullik Bjønnes
7 */
8
9 #ifndef BUFFER_LIST_H
10 #define BUFFER_LIST_H
11
12 #ifdef __GNUG__
13 #pragma interface
14 #endif
15
16 #include "LString.h"
17
18 #include <boost/utility.hpp>
19
20 #include <vector>
21
22 class Buffer;
23 class UpdatableInset;
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            Is the container empty or not.
45            \return True if the container is empty, False otherwise.
46          */
47         bool empty() const { return container.empty(); }
48         /**
49            Releases the passed buffer from the storage and deletes
50            all resources.
51            \param buf The buffer to release.
52          */
53         void release(Buffer * buf);
54         /**
55            \param s The name of the file to base the buffer on.
56            \param ronly If the buffer should be created read only of not.
57            \return The newly created buffer.
58          */
59         Buffer * newBuffer(string const & s, bool ronly = false);
60         ///
61         Container::iterator begin() { return container.begin(); }
62         ///
63         Container::iterator end() { return container.end(); }
64         ///
65         Container::const_iterator begin() const { return container.begin(); }
66         ///
67         Container::const_iterator end() const { return container.end(); }
68         ///
69         Buffer * front() { return container.front(); }
70         ///
71         Buffer * operator[](int c) { return container[c]; }
72         /**
73            What is the size of the container.
74            \return The size of the container.
75          */
76         size_type size() const { return container.size(); }
77 private:
78         ///
79         Container container;
80 };
81
82
83 /**
84    The class holds all all open buffers, and handles construction
85    and deletions of new ones.
86  */
87 class BufferList : boost::noncopyable {
88 public:
89         ///
90         BufferList();
91
92         /// state info
93         enum list_state {
94                 ///
95                 OK,
96                 ///
97                 CLOSING
98         };
99
100         /// returns the state of the bufferlist
101         list_state getState() const { return state_; }
102
103         /**
104            Loads a LyX file or...
105
106            \param filename The filename to read from.
107            \param tolastfiles Wether the file should be put in the
108            last opened files list or not.
109            \return The newly loaded LyX file.
110         */
111         Buffer * loadLyXFile(string const & filename,
112                              bool tolastfiles = true);
113
114         ///
115         bool empty() const;
116
117         ///
118         bool qwriteAll();
119
120         /// Close all open buffers.
121         void closeAll();
122
123         /**
124            Read a file into a buffer readonly or not.
125            \return
126         */
127         Buffer * readFile(string const &, bool ro);
128
129         /// Make a new file (buffer) using a template
130         Buffer * newFile(string const &, string, bool isNamed = false);
131         /// returns a vector with all the buffers filenames
132         std::vector<string> const getFileNames() const;
133
134         ///
135         int unlockInset(UpdatableInset *);
136
137         ///
138         void updateIncludedTeXfiles(string const &);
139
140         ///
141         void emergencyWriteAll();
142
143         /**
144            Close buffer.
145            \param buf the buffer that should be closed
146            \return #false# if operation was canceled
147           */
148         bool close(Buffer * buf);
149
150         ///
151         Buffer * first();
152
153         /// returns true if the buffer exists already
154         bool exists(string const &) const;
155
156         /// returns true if the buffer is loaded
157         bool isLoaded(Buffer const * b) const;
158
159         /// returns a pointer to the buffer with the given name.
160         Buffer * getBuffer(string const &);
161         /// returns a pointer to the buffer with the given number.
162         Buffer * getBuffer(unsigned int);
163 private:
164         /// ask to save a buffer on quit
165         bool qwriteOne(Buffer * buf, string const & fname,
166                        string & unsaved_list);
167
168         ///
169         BufferStorage bstore;
170
171         ///
172         list_state state_;
173         ///
174         void emergencyWrite(Buffer * buf);
175 };
176
177 #endif