#include "support/lstrings.h"
#include "support/Package.h"
-#include <boost/assert.hpp>
+#include "support/lassert.h"
#include <boost/bind.hpp>
#include <algorithm>
void BufferList::release(Buffer * buf)
{
- BOOST_ASSERT(buf);
+ LASSERT(buf, /**/);
BufferStorage::iterator const it =
find(bstore.begin(), bstore.end(), buf);
if (it != bstore.end()) {
Buffer * tmp = (*it);
- BOOST_ASSERT(tmp);
+ LASSERT(tmp, /**/);
bstore.erase(it);
delete tmp;
}
Buffer * BufferList::next(Buffer const * buf) const
{
- BOOST_ASSERT(buf);
+ LASSERT(buf, /**/);
if (bstore.empty())
return 0;
BufferStorage::const_iterator it = find(bstore.begin(),
bstore.end(), buf);
- BOOST_ASSERT(it != bstore.end());
+ LASSERT(it != bstore.end(), /**/);
++it;
if (it == bstore.end())
return bstore.front();
Buffer * BufferList::previous(Buffer const * buf) const
{
- BOOST_ASSERT(buf);
+ LASSERT(buf, /**/);
if (bstore.empty())
return 0;
BufferStorage::const_iterator it = find(bstore.begin(),
bstore.end(), buf);
- BOOST_ASSERT(it != bstore.end());
+ LASSERT(it != bstore.end(), /**/);
if (it == bstore.begin())
return bstore.back();
else
bool BufferList::isLoaded(Buffer const * b) const
{
- BOOST_ASSERT(b);
+ LASSERT(b, /**/);
BufferStorage::const_iterator cit =
find(bstore.begin(), bstore.end(), b);
return cit != bstore.end();
}
+bool BufferList::releaseChild(Buffer * parent, Buffer * child)
+{
+ LASSERT(parent, return false);
+ LASSERT(child, return false);
+ LASSERT(parent->isChild(child), return false);
+
+ // Child document has a different parent, don't close it.
+ if (child->parent() != parent)
+ return false;
+
+ BufferStorage::iterator it = bstore.begin();
+ BufferStorage::iterator end = bstore.end();
+ for (; it != end; ++it) {
+ Buffer * buf = *it;
+ if (buf != parent && buf->isChild(child)) {
+ child->setParent(0);
+ return false;
+ }
+ }
+ release(child);
+ return true;
+}
+
+
} // namespace lyx