3 * Copyright 2002 the LyX Team
4 * Read the file COPYING
6 * \author Lars Gullik Bjønnes
18 #include <boost/utility.hpp>
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.
30 This class should ideally be enclosed inside class BufferList, but that
31 gave me an "internal gcc error".
33 class BufferStorage : boost::noncopyable {
36 typedef std::vector<Buffer *> Container;
38 typedef Container::iterator iterator;
40 typedef Container::const_iterator const_iterator;
42 typedef Container::size_type size_type;
44 Is the container empty or not.
45 \return True if the container is empty, False otherwise.
47 bool empty() const { return container.empty(); }
49 Releases the passed buffer from the storage and deletes
51 \param buf The buffer to release.
53 void release(Buffer * buf);
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.
59 Buffer * newBuffer(string const & s, bool ronly = false);
61 Container::iterator begin() { return container.begin(); }
63 Container::iterator end() { return container.end(); }
65 Container::const_iterator begin() const { return container.begin(); }
67 Container::const_iterator end() const { return container.end(); }
69 Buffer * front() { return container.front(); }
71 Buffer * operator[](int c) { return container[c]; }
73 What is the size of the container.
74 \return The size of the container.
76 size_type size() const { return container.size(); }
84 The class holds all all open buffers, and handles construction
85 and deletions of new ones.
87 class BufferList : boost::noncopyable {
100 /// returns the state of the bufferlist
101 list_state getState() const { return state_; }
104 Loads a LyX file or...
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.
111 Buffer * loadLyXFile(string const & filename,
112 bool tolastfiles = true);
120 /// Close all open buffers.
124 Read a file into a buffer readonly or not.
127 Buffer * readFile(string const &, bool ro);
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;
135 int unlockInset(UpdatableInset *);
138 void updateIncludedTeXfiles(string const &);
141 void emergencyWriteAll();
145 \param buf the buffer that should be closed
146 \return #false# if operation was canceled
148 bool close(Buffer * buf);
153 /// returns true if the buffer exists already
154 bool exists(string const &) const;
156 /// returns true if the buffer is loaded
157 bool isLoaded(Buffer const * b) const;
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);
164 /// ask to save a buffer on quit
165 bool qwriteOne(Buffer * buf, string const & fname,
166 string & unsaved_list);
169 BufferStorage bstore;
174 void emergencyWrite(Buffer * buf);