2003-08-23 00:17:00 +00:00
|
|
|
|
/**
|
2007-04-26 04:41:58 +00:00
|
|
|
|
* \file InsetList.cpp
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
|
*
|
|
|
|
|
* \author Lars Gullik Bj<EFBFBD>nnes
|
|
|
|
|
* \author Martin Vermeer
|
|
|
|
|
*
|
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
|
*/
|
|
|
|
|
|
2002-08-11 15:03:52 +00:00
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
|
|
#include "InsetList.h"
|
2003-09-09 11:24:33 +00:00
|
|
|
|
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "Buffer.h"
|
|
|
|
|
#include "BufferParams.h"
|
2003-12-14 16:33:56 +00:00
|
|
|
|
#include "BranchList.h"
|
2007-11-29 07:04:28 +00:00
|
|
|
|
#include "support/debug.h"
|
2002-08-11 15:03:52 +00:00
|
|
|
|
|
2007-04-25 01:24:38 +00:00
|
|
|
|
#include "insets/InsetBranch.h"
|
2002-08-11 15:03:52 +00:00
|
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
|
using namespace std;
|
2004-01-26 10:13:15 +00:00
|
|
|
|
|
2007-07-17 17:46:54 +00:00
|
|
|
|
namespace lyx {
|
|
|
|
|
|
|
|
|
|
|
2002-08-11 15:03:52 +00:00
|
|
|
|
namespace {
|
|
|
|
|
|
2004-01-26 10:13:15 +00:00
|
|
|
|
typedef InsetList::InsetTable Table;
|
|
|
|
|
|
2007-11-28 22:12:03 +00:00
|
|
|
|
struct InsetTablePosLess
|
|
|
|
|
{
|
2004-01-26 10:13:15 +00:00
|
|
|
|
bool operator()(Table const & t1, Table const & t2) const
|
2003-02-20 17:39:48 +00:00
|
|
|
|
{
|
2004-01-05 18:00:12 +00:00
|
|
|
|
return t1.pos < t2.pos;
|
2002-08-11 15:03:52 +00:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2003-05-29 01:13:18 +00:00
|
|
|
|
} // namespace anon
|
2002-08-11 15:03:52 +00:00
|
|
|
|
|
2004-01-26 10:13:15 +00:00
|
|
|
|
|
|
|
|
|
|
2002-12-01 22:59:25 +00:00
|
|
|
|
InsetList::~InsetList()
|
2002-08-11 15:03:52 +00:00
|
|
|
|
{
|
|
|
|
|
// If we begin storing a shared_ptr in the List
|
|
|
|
|
// this code can be removed. (Lgb)
|
2004-07-25 00:04:42 +00:00
|
|
|
|
List::iterator it = list_.begin();
|
|
|
|
|
List::iterator end = list_.end();
|
2002-08-11 15:03:52 +00:00
|
|
|
|
for (; it != end; ++it) {
|
|
|
|
|
delete it->inset;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-11-13 13:43:44 +00:00
|
|
|
|
InsetList::iterator InsetList::insetIterator(pos_type pos)
|
2002-08-11 15:03:52 +00:00
|
|
|
|
{
|
|
|
|
|
InsetTable search_elem(pos, 0);
|
2004-07-25 00:04:42 +00:00
|
|
|
|
return lower_bound(list_.begin(), list_.end(), search_elem,
|
2004-01-05 18:00:12 +00:00
|
|
|
|
InsetTablePosLess());
|
2002-08-11 15:03:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-11-13 13:43:44 +00:00
|
|
|
|
InsetList::const_iterator InsetList::insetIterator(pos_type pos) const
|
2002-08-11 15:03:52 +00:00
|
|
|
|
{
|
|
|
|
|
InsetTable search_elem(pos, 0);
|
2004-07-25 00:04:42 +00:00
|
|
|
|
return lower_bound(list_.begin(), list_.end(), search_elem,
|
2004-01-05 18:00:12 +00:00
|
|
|
|
InsetTablePosLess());
|
2003-11-13 13:43:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-29 13:39:47 +00:00
|
|
|
|
void InsetList::insert(Inset * inset, pos_type pos)
|
2003-11-13 13:43:44 +00:00
|
|
|
|
{
|
2004-07-25 00:04:42 +00:00
|
|
|
|
List::iterator end = list_.end();
|
2003-11-13 13:43:44 +00:00
|
|
|
|
List::iterator it = insetIterator(pos);
|
2003-05-29 01:13:18 +00:00
|
|
|
|
if (it != end && it->pos == pos) {
|
2007-11-28 22:12:03 +00:00
|
|
|
|
LYXERR0("ERROR (InsetList::insert): "
|
|
|
|
|
<< "There is an inset in position: " << pos);
|
2002-08-11 15:03:52 +00:00
|
|
|
|
} else {
|
2004-07-25 00:04:42 +00:00
|
|
|
|
list_.insert(it, InsetTable(pos, inset));
|
2002-08-11 15:03:52 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetList::erase(pos_type pos)
|
|
|
|
|
{
|
2004-07-25 00:04:42 +00:00
|
|
|
|
List::iterator end = list_.end();
|
2003-11-13 13:43:44 +00:00
|
|
|
|
List::iterator it = insetIterator(pos);
|
2003-05-29 01:13:18 +00:00
|
|
|
|
if (it != end && it->pos == pos) {
|
2002-08-11 15:03:52 +00:00
|
|
|
|
delete it->inset;
|
2004-07-25 00:04:42 +00:00
|
|
|
|
list_.erase(it);
|
2002-08-11 15:03:52 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-29 13:39:47 +00:00
|
|
|
|
Inset * InsetList::release(pos_type pos)
|
2002-08-11 15:03:52 +00:00
|
|
|
|
{
|
2004-07-25 00:04:42 +00:00
|
|
|
|
List::iterator end = list_.end();
|
2003-11-13 13:43:44 +00:00
|
|
|
|
List::iterator it = insetIterator(pos);
|
2003-05-29 01:13:18 +00:00
|
|
|
|
if (it != end && it->pos == pos) {
|
2007-04-29 13:39:47 +00:00
|
|
|
|
Inset * tmp = it->inset;
|
2002-08-11 15:03:52 +00:00
|
|
|
|
it->inset = 0;
|
|
|
|
|
return tmp;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2002-12-01 22:59:25 +00:00
|
|
|
|
|
2007-04-29 13:39:47 +00:00
|
|
|
|
Inset * InsetList::get(pos_type pos) const
|
2002-08-11 15:03:52 +00:00
|
|
|
|
{
|
2004-07-25 00:04:42 +00:00
|
|
|
|
List::const_iterator end = list_.end();
|
2003-11-13 13:43:44 +00:00
|
|
|
|
List::const_iterator it = insetIterator(pos);
|
2003-05-29 01:13:18 +00:00
|
|
|
|
if (it != end && it->pos == pos)
|
2002-08-11 15:03:52 +00:00
|
|
|
|
return it->inset;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetList::increasePosAfterPos(pos_type pos)
|
|
|
|
|
{
|
2004-07-25 00:04:42 +00:00
|
|
|
|
List::iterator end = list_.end();
|
2003-11-13 13:43:44 +00:00
|
|
|
|
List::iterator it = insetIterator(pos);
|
2002-08-11 15:03:52 +00:00
|
|
|
|
for (; it != end; ++it) {
|
|
|
|
|
++it->pos;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetList::decreasePosAfterPos(pos_type pos)
|
|
|
|
|
{
|
2004-07-25 00:04:42 +00:00
|
|
|
|
List::iterator end = list_.end();
|
2003-11-13 13:43:44 +00:00
|
|
|
|
List::iterator it = insetIterator(pos);
|
2002-08-11 15:03:52 +00:00
|
|
|
|
for (; it != end; ++it) {
|
|
|
|
|
--it->pos;
|
|
|
|
|
}
|
|
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
|
2007-10-19 08:57:22 +00:00
|
|
|
|
InsetList::InsetList(InsetList const & il)
|
2007-10-18 15:29:51 +00:00
|
|
|
|
{
|
2007-10-19 08:57:22 +00:00
|
|
|
|
list_ = il.list_;
|
2007-10-18 15:29:51 +00:00
|
|
|
|
List::iterator it = list_.begin();
|
|
|
|
|
List::iterator end = list_.end();
|
|
|
|
|
for (; it != end; ++it)
|
|
|
|
|
it->inset = it->inset->clone();
|
|
|
|
|
}
|
|
|
|
|
|
2007-10-24 15:32:43 +00:00
|
|
|
|
|
|
|
|
|
pos_type InsetList::find(InsetCode code, pos_type startpos) const
|
|
|
|
|
{
|
|
|
|
|
List::const_iterator it = insetIterator(startpos);
|
|
|
|
|
List::const_iterator end = list_.end();
|
|
|
|
|
for (; it != end ; ++it) {
|
|
|
|
|
if (it->inset->lyxCode() == code)
|
|
|
|
|
return it->pos;
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int InsetList::count(InsetCode code, pos_type startpos) const
|
|
|
|
|
{
|
|
|
|
|
int num = 0;
|
|
|
|
|
List::const_iterator it = insetIterator(startpos);
|
|
|
|
|
List::const_iterator end = list_.end();
|
|
|
|
|
for (; it != end ; ++it) {
|
|
|
|
|
if (it->inset->lyxCode() == code)
|
|
|
|
|
++num;
|
|
|
|
|
}
|
|
|
|
|
return num;
|
|
|
|
|
}
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
} // namespace lyx
|