2000-07-24 13:53:19 +00:00
|
|
|
/* This file is part of
|
|
|
|
* ======================================================
|
|
|
|
*
|
|
|
|
* LyX, The Document Processor
|
|
|
|
*
|
|
|
|
* Copyright 1995 Matthias Ettrich
|
2001-05-30 13:53:44 +00:00
|
|
|
* Copyright 1995-2001 The LyX Team.
|
2000-07-24 13:53:19 +00:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* ====================================================== */
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
2000-07-17 18:27:53 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "counters.h"
|
|
|
|
#include "debug.h"
|
|
|
|
|
|
|
|
using std::endl;
|
|
|
|
|
|
|
|
|
|
|
|
Counter::Counter()
|
|
|
|
{
|
|
|
|
reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Counter::set(int v)
|
|
|
|
{
|
|
|
|
value_ = v;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Counter::addto(int v)
|
|
|
|
{
|
|
|
|
value_ += v;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int Counter::value() const
|
|
|
|
{
|
|
|
|
return value_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Counter::step()
|
|
|
|
{
|
|
|
|
++value_;
|
|
|
|
onstep.emit();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Counter::reset()
|
|
|
|
{
|
|
|
|
value_ = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Counters::~Counters()
|
|
|
|
{
|
|
|
|
// We need this since we store the Counter's as pointers in
|
|
|
|
// the counterList.
|
|
|
|
for (CounterList::iterator it = counterList.begin();
|
|
|
|
it != counterList.end();
|
|
|
|
++it)
|
2001-07-12 11:11:10 +00:00
|
|
|
delete it->second;
|
2000-07-17 18:27:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Counters::newCounter(string const & newc)
|
|
|
|
{
|
|
|
|
// First check if newc already exist
|
2000-09-26 13:54:57 +00:00
|
|
|
CounterList::iterator cit = counterList.find(newc);
|
2000-07-17 18:27:53 +00:00
|
|
|
// if alrady exist give warning and return
|
|
|
|
if (cit != counterList.end()) {
|
|
|
|
lyxerr << "The new counter already exist." << endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
counterList[newc] = new Counter;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Counters::newCounter(string const & newc, string const & oldc)
|
|
|
|
{
|
|
|
|
// First check if newc already exist
|
2000-09-26 13:54:57 +00:00
|
|
|
CounterList::iterator cit = counterList.find(newc);
|
2000-07-17 18:27:53 +00:00
|
|
|
// if already existant give warning and return
|
|
|
|
if (cit != counterList.end()) {
|
|
|
|
lyxerr << "The new counter already exist." << endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// then check if oldc exist
|
|
|
|
CounterList::iterator it = counterList.find(oldc);
|
|
|
|
// if not give warning and return
|
|
|
|
if (it == counterList.end()) {
|
|
|
|
lyxerr << "The old counter does not exist." << endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Counter * tmp = new Counter;
|
2001-07-12 11:11:10 +00:00
|
|
|
it->second->onstep.connect(SigC::slot(tmp,
|
|
|
|
&Counter::reset));
|
2000-07-17 18:27:53 +00:00
|
|
|
counterList[newc] = tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Counters::set(string const & ctr, int val)
|
|
|
|
{
|
|
|
|
CounterList::iterator it = counterList.find(ctr);
|
|
|
|
if (it == counterList.end()) {
|
|
|
|
lyxerr << "Counter does not exist." << endl;
|
|
|
|
return;
|
|
|
|
}
|
2001-07-12 11:11:10 +00:00
|
|
|
it->second->set(val);
|
2000-07-17 18:27:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Counters::addto(string const & ctr, int val)
|
|
|
|
{
|
|
|
|
CounterList::iterator it = counterList.find(ctr);
|
|
|
|
if (it == counterList.end()) {
|
|
|
|
lyxerr << "Counter does not exist." << endl;
|
|
|
|
return;
|
|
|
|
}
|
2001-07-12 11:11:10 +00:00
|
|
|
it->second->addto(val);
|
2000-07-17 18:27:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int Counters::value(string const & ctr) const
|
|
|
|
{
|
|
|
|
CounterList::const_iterator cit = counterList.find(ctr);
|
|
|
|
if (cit == counterList.end()) {
|
|
|
|
lyxerr << "Counter does not exist." << endl;
|
|
|
|
return 0;
|
|
|
|
}
|
2001-07-12 11:11:10 +00:00
|
|
|
return cit->second->value();
|
2000-07-17 18:27:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Counters::step(string const & ctr)
|
|
|
|
{
|
|
|
|
CounterList::iterator it = counterList.find(ctr);
|
|
|
|
if (it == counterList.end()) {
|
|
|
|
lyxerr << "Counter does not exist." << endl;
|
|
|
|
return;
|
|
|
|
}
|
2001-07-12 11:11:10 +00:00
|
|
|
it->second->step();
|
2000-07-17 18:27:53 +00:00
|
|
|
}
|