2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2001 The LyX Team
9 * This file is Copyright 1996-2001
12 * ====================================================== */
24 #include <boost/utility.hpp>
26 /** A class to hold all the buffers in a structure
27 The point of this class is to hide from bufferlist what kind
28 of structure the buffers are stored in. Should be no concern for
29 bufferlist if the buffers is in a array or in a linked list.
31 This class should ideally be enclosed inside class BufferList, but that
32 gave me an "internal gcc error".
34 class BufferStorage : boost::noncopyable {
37 typedef std::vector<Buffer *> Container;
39 typedef Container::iterator iterator;
41 typedef Container::const_iterator const_iterator;
43 typedef Container::size_type size_type;
45 bool empty() const { return container.empty(); }
47 void release(Buffer * buf);
49 Buffer * newBuffer(string const & s, bool = false);
51 Container::iterator begin() { return container.begin(); }
53 Container::iterator end() { return container.end(); }
55 Container::const_iterator begin() const { return container.begin(); }
57 Container::const_iterator end() const { return container.end(); }
59 Buffer * front() { return container.front(); }
61 Buffer * operator[](int c) { return container[c]; }
63 size_type size() const { return container.size(); }
70 /** The class govern all open buffers.
72 class BufferList : boost::noncopyable {
85 /// returns the state of the bufferlist
86 list_state getState() const { return state_; }
88 /** loads a LyX file or...
89 If the optional argument tolastfiles is false (default is
90 true), the file name will not be added to the last opened
93 Buffer * loadLyXFile(string const & filename,
94 bool tolastfiles = true);
102 /// Close all open buffers.
105 /// Read a file into a buffer readonly or not.
106 Buffer * readFile(string const &, bool ro);
108 /// Make a new file (buffer) using a template
109 Buffer * newFile(string const &, string, bool isNamed = false);
110 /// returns a vector with all the buffers filenames
111 std::vector<string> const getFileNames() const;
114 int unlockInset(UpdatableInset *);
117 void updateIncludedTeXfiles(string const &);
120 void emergencyWriteAll();
123 @param buf the buffer that should be closed
124 @return #false# if operation was canceled
126 bool close(Buffer * buf);
131 /// returns true if the buffer exists already
132 bool exists(string const &) const;
134 /// returns true if the buffer is loaded
135 bool isLoaded(Buffer const * b) const;
137 /// returns a pointer to the buffer with the given name.
138 Buffer * getBuffer(string const &);
139 /// returns a pointer to the buffer with the given number.
140 Buffer * getBuffer(unsigned int);
144 BufferStorage bstore;
149 void emergencyWrite(Buffer * buf);