2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-1999 The LyX Team
9 * This file is Copyright 1996
12 * ======================================================*/
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".
38 typedef vector<Buffer *> Container;
40 typedef Container::iterator iterator;
42 bool empty() const { return container.empty(); }
44 void release(Buffer * buf);
46 Buffer * newBuffer(string const & s, LyXRC *, bool = false);
48 Container::iterator begin() { return container.begin(); }
50 Container::iterator end() { return container.end(); }
52 Buffer * front() { return container.front(); }
54 Buffer * operator[](int c) { return container[c]; }
56 int size() const { return container.size(); }
67 void release(Buffer * buf);
69 Buffer* newBuffer(string const & s, LyXRC *, bool =false);
72 /** The max number of buffers there are possible to have
73 loaded at the same time. (this only applies when we use an
76 NUMBER_OF_BUFFERS = 50
79 /** The Bufferlist is currently implemented as a static array.
80 The buffers are new'ed and deleted as reqested.
82 Buffer *buffer[NUMBER_OF_BUFFERS];
84 friend class BufferStorage_Iter;
90 /// An Iterator class for BufferStorage
91 class BufferStorage_Iter {
94 BufferStorage_Iter(BufferStorage const & bs)
95 { cs =& bs; index = 0;}
97 Buffer* operator() ();
99 Buffer* operator[] (int a);
102 const BufferStorage *cs;
109 /** The class governing all the open buffers
110 This class governs all the currently open buffers. Currently all the buffer
111 are located in a static array, soon this will change and we will have a
127 /// returns the state of the bufferlist
128 list_state getState() { return _state; }
130 /** loads a LyX file or...
131 If the optional argument tolastfiles is false (default is
132 true), the file name will not be added to the last opened
135 Buffer * loadLyXFile(string const & filename,
136 bool tolastfiles = true);
141 /// Saves buffer. Returns false if unsuccesful.
142 bool write(Buffer *, bool makeBackup = true);
147 /// Close all open buffers.
153 /// Read a file into a buffer readonly or not.
154 Buffer * readFile(string const &, bool ro);
156 /// Make a new file (buffer) using a template
157 Buffer * newFile(string const &, string);
159 /** This one must be moved to some other place.
164 void updateInset(Inset *, bool = true);
167 int unlockInset(UpdatableInset *);
170 void updateIncludedTeXfiles(string const &);
173 void emergencyWriteAll();
176 Returns false if operation was canceled
178 bool close(Buffer *);
183 /// returns true if the buffer exists already
184 bool exists(string const &);
186 /// returns a pointer to the buffer with the given name.
187 Buffer * getBuffer(string const &);
188 /// returns a pointer to the buffer with the given number.
189 Buffer * getBuffer(int);
193 BufferStorage bstore;