3 * Copyright 2002 the LyX Team
4 * Read the file COPYING
6 * \author Lars Gullik Bjønnes
14 #include <boost/utility.hpp>
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.
26 This class should ideally be enclosed inside class BufferList, but that
27 gave me an "internal gcc error".
29 class BufferStorage : boost::noncopyable {
32 typedef std::vector<Buffer *> Container;
34 typedef Container::iterator iterator;
36 typedef Container::const_iterator const_iterator;
38 typedef Container::size_type size_type;
40 Is the container empty or not.
41 \return True if the container is empty, False otherwise.
43 bool empty() const { return container.empty(); }
45 Releases the passed buffer from the storage and deletes
47 \param buf The buffer to release.
49 void release(Buffer * buf);
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.
55 Buffer * newBuffer(string const & s, bool ronly = false);
57 Container::iterator begin() { return container.begin(); }
59 Container::iterator end() { return container.end(); }
61 Container::const_iterator begin() const { return container.begin(); }
63 Container::const_iterator end() const { return container.end(); }
65 Buffer * front() { return container.front(); }
67 Buffer * operator[](int c) { return container[c]; }
69 What is the size of the container.
70 \return The size of the container.
72 size_type size() const { return container.size(); }
80 The class holds all all open buffers, and handles construction
81 and deletions of new ones.
83 class BufferList : boost::noncopyable {
96 /// returns the state of the bufferlist
97 list_state getState() const { return state_; }
100 Loads a LyX file or...
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.
107 Buffer * loadLyXFile(string const & filename,
108 bool tolastfiles = true);
116 /// Close all open buffers.
120 Read a file into a buffer readonly or not.
123 Buffer * readFile(string const &, bool ro);
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;
131 int unlockInset(UpdatableInset *);
134 void updateIncludedTeXfiles(string const &);
137 void emergencyWriteAll();
141 \param buf the buffer that should be closed
142 \return #false# if operation was canceled
144 bool close(Buffer * buf);
149 /// returns true if the buffer exists already
150 bool exists(string const &) const;
152 /// returns true if the buffer is loaded
153 bool isLoaded(Buffer const * b) const;
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);
160 /// reset current author for all buffers
161 void setCurrentAuthor(string const & name, string const & email);
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);