* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
- * \author Lars Gullik Bjønnes
+ * \author Lars Gullik Bjønnes
*
* Full author contact details are available in file CREDITS.
*/
{}
+BufferList::~BufferList()
+{
+ BufferStorage::iterator it = binternal.begin();
+ BufferStorage::iterator end = binternal.end();
+ for (; it != end; ++it)
+ delete (*it);
+}
+
+
bool BufferList::empty() const
{
return bstore.empty();
}
}
tmpbuf->params().useClassDefaults();
- LYXERR(Debug::INFO, "Assigning to buffer " << bstore.size());
- bstore.push_back(tmpbuf.get());
+ if (tmpbuf->fileName().extension() == "internal") {
+ binternal.push_back(tmpbuf.get());
+ } else {
+ LYXERR(Debug::INFO, "Assigning to buffer " << bstore.size());
+ bstore.push_back(tmpbuf.get());
+ }
return tmpbuf.release();
}
LASSERT(it != bstore.end(), /**/);
++it;
Buffer * nextbuf = (it == bstore.end()) ? bstore.front() : *it;
- if (nextbuf->fileName().extension() == "internal")
- return next(nextbuf);
return nextbuf;
}
LASSERT(it != bstore.end(), /**/);
Buffer * previousbuf = (it == bstore.begin()) ? bstore.back() : *(it - 1);
- if (previousbuf->fileName().extension() == "internal")
- return previous(previousbuf);
return previousbuf;
}
bool BufferList::isLoaded(Buffer const * b) const
{
- LASSERT(b, /**/);
BufferStorage::const_iterator cit =
find(bstore.begin(), bstore.end(), b);
return cit != bstore.end();
}
+namespace {
+struct equivalent_to : public binary_function<FileName, FileName, bool>
+{
+ bool operator()(FileName const & x, FileName const & y) const
+ { return equivalent(x, y); }
+};
+}
+
+
Buffer * BufferList::getBuffer(support::FileName const & fname) const
{
+ // 1) cheap test, using string comparison of file names
BufferStorage::const_iterator it = find_if(bstore.begin(), bstore.end(),
bind(equal_to<FileName>(), bind(&Buffer::fileName, _1), fname));
+ if (it != bstore.end())
+ return *it;
+ // 2) possibly expensive test, using equivalence test of file names
+ it = find_if(bstore.begin(), bstore.end(),
+ bind(equivalent_to(), bind(&Buffer::fileName, _1), fname));
return it != bstore.end() ? (*it) : 0;
}
{
BufferStorage::iterator it = bstore.begin();
BufferStorage::iterator end = bstore.end();
- for (; it < end; ++it)
- if (prefixIs(s, (*it)->temppath()))
- return *it;
+ for (; it < end; ++it) {
+ if (prefixIs(s, (*it)->temppath())) {
+ // check whether the filename matches the master
+ string const master_name = changeExtension(onlyFilename(
+ (*it)->absFileName()), ".tex");
+ if (suffixIs(s, master_name))
+ return *it;
+ // if not, try with the children
+ vector<Buffer *> clist = (*it)->getChildren();
+ vector<Buffer *>::const_iterator cit = clist.begin();
+ vector<Buffer *>::const_iterator cend = clist.end();
+ for (; cit < cend; ++cit) {
+ string const mangled_child_name = DocFileName(
+ changeExtension((*cit)->absFileName(),
+ ".tex")).mangledFilename();
+ if (suffixIs(s, mangled_child_name))
+ return *cit;
+ }
+ }
+ }
return 0;
}