LyX 1.6.0 release candidate 4 (rc4)
[lyx.git] / src / BufferList.h
blob8c79d4c30afcc76be64a266383a444785761c2a7
1 // -*- C++ -*-
2 /**
3 * \file BufferList.h
4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Lars Gullik Bjønnes
9 * Full author contact details are available in file CREDITS.
12 #ifndef BUFFER_LIST_H
13 #define BUFFER_LIST_H
15 #include "support/docstring.h"
17 #include <vector>
20 namespace lyx {
22 class Buffer;
23 class OutputParams;
25 namespace support {
26 class FileName;
27 class FileNameList;
30 /**
31 * The class holds all all open buffers, and handles construction
32 * and deletions of new ones.
34 class BufferList {
35 public:
36 typedef std::vector<Buffer *>::iterator iterator;
37 typedef std::vector<Buffer *>::const_iterator const_iterator;
39 public:
40 BufferList();
41 ~BufferList();
43 iterator begin();
44 const_iterator begin() const;
46 iterator end();
47 const_iterator end() const;
49 /// create a new buffer
50 /// \return 0 if the Buffer creation is not possible for whatever reason.
51 Buffer * newBuffer(std::string const & s, bool ronly = false);
53 /// delete a buffer
54 void release(Buffer * b);
56 /// Release \p child if it really is a child and is not used elsewhere.
57 /// \return true is the file was closed.
58 bool releaseChild(Buffer * parent, Buffer * child);
60 /// Close all open buffers.
61 void closeAll();
63 /// returns a vector with all the buffers filenames
64 support::FileNameList const & fileNames() const;
66 /// FIXME
67 void updateIncludedTeXfiles(std::string const &, OutputParams const &);
69 /// emergency save for all buffers
70 void emergencyWriteAll();
72 /// save emergency file for the given buffer
73 /**
74 * \return a status message towards the user.
76 docstring emergencyWrite(Buffer * buf);
78 /// return true if no buffers loaded
79 bool empty() const;
81 /// return head of buffer list if any
82 Buffer * first();
84 /// return back of buffer list if any
85 Buffer * last();
87 /// returns true if the buffer exists already
88 bool exists(support::FileName const &) const;
90 /// returns true if the buffer is loaded
91 bool isLoaded(Buffer const * b) const;
93 /// return index of named buffer in buffer list
94 int bufferNum(support::FileName const & name) const;
95 /// returns a pointer to the buffer with the given name.
96 Buffer * getBuffer(support::FileName const &) const;
97 /// returns a pointer to the buffer with the given number.
98 Buffer * getBuffer(unsigned int);
99 /// returns a pointer to the buffer whose temppath matches the string
100 Buffer * getBufferFromTmp(std::string const &);
102 /** returns a pointer to the buffer that follows argument in
103 * buffer list. The buffer following the last in list is the
104 * first one.
106 Buffer * next(Buffer const *) const;
108 /** returns a pointer to the buffer that precedes argument in
109 * buffer list. The buffer preceding the first in list is the
110 * last one.
112 Buffer * previous(Buffer const *) const;
114 /// reset current author for all buffers
115 void setCurrentAuthor(docstring const & name, docstring const & email);
117 private:
118 /// noncopiable
119 BufferList(BufferList const &);
120 void operator=(BufferList const &);
122 typedef std::vector<Buffer *> BufferStorage;
124 /// storage of all buffers
125 BufferStorage bstore;
126 /// storage of all internal buffers used for cut&paste, etc.
127 BufferStorage binternal;
130 /// Implementation is in LyX.cpp
131 extern BufferList & theBufferList();
134 } // namespace lyx
136 #endif // BUFFERLIST_H