]> git.lyx.org Git - features.git/blob - src/bufferlist.h
dont use pragma impementation and interface anymore
[features.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 #include "LString.h"
13
14 #include <boost/utility.hpp>
15
16 #include <vector>
17
18 class Buffer;
19 class UpdatableInset;
20
21 /** A class to hold all the buffers in a structure
22   The point of this class is to hide from bufferlist what kind
23   of structure the buffers are stored in. Should be no concern for
24   bufferlist if the buffers is in a array or in a linked list.
25
26   This class should ideally be enclosed inside class BufferList, but that
27   gave me an "internal gcc error".
28   */
29 class BufferStorage : boost::noncopyable {
30 public:
31         ///
32         typedef std::vector<Buffer *> Container;
33         ///
34         typedef Container::iterator iterator;
35         ///
36         typedef Container::const_iterator const_iterator;
37         ///
38         typedef Container::size_type size_type;
39         /**
40            Is the container empty or not.
41            \return True if the container is empty, False otherwise.
42          */
43         bool empty() const { return container.empty(); }
44         /**
45            Releases the passed buffer from the storage and deletes
46            all resources.
47            \param buf The buffer to release.
48          */
49         void release(Buffer * buf);
50         /**
51            \param s The name of the file to base the buffer on.
52            \param ronly If the buffer should be created read only of not.
53            \return The newly created buffer.
54          */
55         Buffer * newBuffer(string const & s, bool ronly = false);
56         ///
57         Container::iterator begin() { return container.begin(); }
58         ///
59         Container::iterator end() { return container.end(); }
60         ///
61         Container::const_iterator begin() const { return container.begin(); }
62         ///
63         Container::const_iterator end() const { return container.end(); }
64         ///
65         Buffer * front() { return container.front(); }
66         ///
67         Buffer * operator[](int c) { return container[c]; }
68         /**
69            What is the size of the container.
70            \return The size of the container.
71          */
72         size_type size() const { return container.size(); }
73 private:
74         ///
75         Container container;
76 };
77
78
79 /**
80    The class holds all all open buffers, and handles construction
81    and deletions of new ones.
82  */
83 class BufferList : boost::noncopyable {
84 public:
85         ///
86         BufferList();
87
88         /// state info
89         enum list_state {
90                 ///
91                 OK,
92                 ///
93                 CLOSING
94         };
95
96         /// returns the state of the bufferlist
97         list_state getState() const { return state_; }
98
99         /**
100            Loads a LyX file or...
101
102            \param filename The filename to read from.
103            \param tolastfiles Wether the file should be put in the
104            last opened files list or not.
105            \return The newly loaded LyX file.
106         */
107         Buffer * loadLyXFile(string const & filename,
108                              bool tolastfiles = true);
109
110         ///
111         bool empty() const;
112
113         ///
114         bool qwriteAll();
115
116         /// Close all open buffers.
117         void closeAll();
118
119         /**
120            Read a file into a buffer readonly or not.
121            \return
122         */
123         Buffer * readFile(string const &, bool ro);
124
125         /// Make a new file (buffer) using a template
126         Buffer * newFile(string const &, string, bool isNamed = false);
127         /// returns a vector with all the buffers filenames
128         std::vector<string> const getFileNames() const;
129
130         ///
131         int unlockInset(UpdatableInset *);
132
133         ///
134         void updateIncludedTeXfiles(string const &);
135
136         ///
137         void emergencyWriteAll();
138
139         /**
140            Close buffer.
141            \param buf the buffer that should be closed
142            \return #false# if operation was canceled
143           */
144         bool close(Buffer * buf);
145
146         ///
147         Buffer * first();
148
149         /// returns true if the buffer exists already
150         bool exists(string const &) const;
151
152         /// returns true if the buffer is loaded
153         bool isLoaded(Buffer const * b) const;
154
155         /// returns a pointer to the buffer with the given name.
156         Buffer * getBuffer(string const &);
157         /// returns a pointer to the buffer with the given number.
158         Buffer * getBuffer(unsigned int);
159
160         /// reset current author for all buffers
161         void setCurrentAuthor(string const & name, string const & email);
162
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