2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2000 The LyX Team
9 * This file is Copyright 1996-2000
12 * ====================================================== */
23 #include "support/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 : public noncopyable {
36 typedef std::vector<Buffer *> Container;
38 typedef Container::iterator iterator;
40 typedef Container::const_iterator const_iterator;
42 bool empty() const { return container.empty(); }
44 void release(Buffer * buf);
46 Buffer * newBuffer(string const & s, bool = false);
48 Container::iterator begin() { return container.begin(); }
50 Container::iterator end() { return container.end(); }
52 Container::const_iterator begin() const { return container.begin(); }
54 Container::const_iterator end() const { return container.end(); }
56 Buffer * front() { return container.front(); }
58 Buffer * operator[](int c) { return container[c]; }
60 int size() const { return container.size(); }
67 /** The class govern all open buffers.
69 class BufferList : public noncopyable {
82 /// returns the state of the bufferlist
83 list_state getState() const { return state_; }
85 /** loads a LyX file or...
86 If the optional argument tolastfiles is false (default is
87 true), the file name will not be added to the last opened
90 Buffer * loadLyXFile(string const & filename,
91 bool tolastfiles = true);
99 /// 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);
110 /// returns a vector with all the buffers filenames
111 std::vector<string> 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(int);
144 BufferStorage bstore;