2000-07-17 18:27:53 +00:00
|
|
|
|
// -*- C++ -*-
|
2003-08-23 00:17:00 +00:00
|
|
|
|
/**
|
2007-04-26 04:41:58 +00:00
|
|
|
|
* \file Counters.h
|
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.
|
2002-03-21 17:27:08 +00:00
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* \author Lars Gullik Bj<EFBFBD>nnes
|
|
|
|
|
* \author Jean-Marc Lasgouttes
|
|
|
|
|
* \author John Levon
|
|
|
|
|
* \author Martin Vermeer
|
2000-07-24 13:53:19 +00:00
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
|
*/
|
2000-07-17 18:27:53 +00:00
|
|
|
|
|
|
|
|
|
#ifndef COUNTERS_H
|
2001-02-12 14:09:09 +00:00
|
|
|
|
#define COUNTERS_H
|
2000-07-17 18:27:53 +00:00
|
|
|
|
|
2006-10-20 20:30:00 +00:00
|
|
|
|
#include "support/docstring.h"
|
|
|
|
|
|
2002-05-29 16:21:03 +00:00
|
|
|
|
#include <map>
|
2002-09-05 12:58:10 +00:00
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
|
2002-08-07 14:15:06 +00:00
|
|
|
|
/// This represents a single counter.
|
2002-08-06 22:40:59 +00:00
|
|
|
|
class Counter {
|
2000-07-17 18:27:53 +00:00
|
|
|
|
public:
|
|
|
|
|
///
|
|
|
|
|
Counter();
|
|
|
|
|
///
|
|
|
|
|
void set(int v);
|
|
|
|
|
///
|
|
|
|
|
void addto(int v);
|
|
|
|
|
///
|
|
|
|
|
int value() const;
|
|
|
|
|
///
|
|
|
|
|
void step();
|
|
|
|
|
///
|
|
|
|
|
void reset();
|
2002-08-07 14:15:06 +00:00
|
|
|
|
/// Returns the master counter of this counter
|
2007-01-11 22:38:37 +00:00
|
|
|
|
lyx::docstring const & master() const;
|
2002-08-07 14:15:06 +00:00
|
|
|
|
/// sets the master counter for this counter
|
2006-10-20 20:30:00 +00:00
|
|
|
|
void setMaster(lyx::docstring const & m);
|
2002-08-06 22:40:59 +00:00
|
|
|
|
private:
|
2002-09-05 12:58:10 +00:00
|
|
|
|
///
|
2000-07-17 18:27:53 +00:00
|
|
|
|
int value_;
|
2002-08-11 20:34:20 +00:00
|
|
|
|
/// contains master counter name; master counter is the counter
|
|
|
|
|
/// that, if stepped (incremented) zeroes this counter. E.g.
|
2002-08-07 14:15:06 +00:00
|
|
|
|
/// "subparagraph"'s master is "paragraph".
|
2006-10-20 20:30:00 +00:00
|
|
|
|
lyx::docstring master_;
|
2000-07-17 18:27:53 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2002-08-11 20:34:20 +00:00
|
|
|
|
/// This is a class of (La)TeX type counters.
|
2002-08-07 14:15:06 +00:00
|
|
|
|
/// Every instantiation is an array of counters of type Counter.
|
2000-07-17 18:27:53 +00:00
|
|
|
|
class Counters {
|
|
|
|
|
public:
|
2002-08-07 14:15:06 +00:00
|
|
|
|
/// Add a new counter to array.
|
2006-10-20 20:30:00 +00:00
|
|
|
|
void newCounter(lyx::docstring const & newc);
|
2002-08-07 14:15:06 +00:00
|
|
|
|
/// Add new counter having oldc as its master.
|
2006-10-20 20:30:00 +00:00
|
|
|
|
void newCounter(lyx::docstring const & newc,
|
|
|
|
|
lyx::docstring const & oldc);
|
2000-07-17 18:27:53 +00:00
|
|
|
|
///
|
2006-10-20 20:30:00 +00:00
|
|
|
|
void set(lyx::docstring const & ctr, int val);
|
2000-07-17 18:27:53 +00:00
|
|
|
|
///
|
2006-10-20 20:30:00 +00:00
|
|
|
|
void addto(lyx::docstring const & ctr, int val);
|
2000-07-17 18:27:53 +00:00
|
|
|
|
///
|
2006-10-20 20:30:00 +00:00
|
|
|
|
int value(lyx::docstring const & ctr) const;
|
2002-08-07 14:15:06 +00:00
|
|
|
|
/// Step (increment by one) counter named by arg, and
|
|
|
|
|
/// zeroes slave counter(s) for which it is the master.
|
|
|
|
|
/// NOTE sub-slaves not zeroed! That happens at slave's
|
|
|
|
|
/// first step 0->1. Seems to be sufficient.
|
2006-10-20 20:30:00 +00:00
|
|
|
|
void step(lyx::docstring const & ctr);
|
2002-08-11 20:34:20 +00:00
|
|
|
|
/// Reset all counters.
|
|
|
|
|
void reset();
|
|
|
|
|
/// Reset counters matched by match string.
|
2006-10-20 20:30:00 +00:00
|
|
|
|
void reset(lyx::docstring const & match);
|
2002-08-11 20:34:20 +00:00
|
|
|
|
/// Copy counters whose name matches match from the &from to
|
2002-08-07 14:15:06 +00:00
|
|
|
|
/// the &to array of counters. Empty string matches all.
|
2006-10-20 20:30:00 +00:00
|
|
|
|
void copy(Counters & from, Counters & to,
|
|
|
|
|
lyx::docstring const & match = lyx::docstring());
|
2003-09-12 17:13:22 +00:00
|
|
|
|
/// A complete expanded label, like 2.1.4 for a subsubsection
|
|
|
|
|
/// according to the given format
|
2006-10-20 20:30:00 +00:00
|
|
|
|
lyx::docstring counterLabel(lyx::docstring const & format);
|
2007-07-11 12:52:50 +00:00
|
|
|
|
///
|
|
|
|
|
bool appendix() const { return appendix_; };
|
|
|
|
|
///
|
|
|
|
|
void appendix(bool a) { appendix_ = a; };
|
2000-07-17 18:27:53 +00:00
|
|
|
|
private:
|
2003-09-12 17:13:22 +00:00
|
|
|
|
/// A counter label's single item, 1 for subsection number in
|
|
|
|
|
/// the 2.1.4 subsubsection number label.
|
2006-10-20 20:30:00 +00:00
|
|
|
|
lyx::docstring labelItem(lyx::docstring const & ctr,
|
|
|
|
|
lyx::docstring const & numbertype);
|
2002-08-07 14:15:06 +00:00
|
|
|
|
/// Maps counter (layout) names to actual counters.
|
2006-10-20 20:30:00 +00:00
|
|
|
|
typedef std::map<lyx::docstring, Counter> CounterList;
|
2002-08-07 14:15:06 +00:00
|
|
|
|
/// Instantiate.
|
2000-07-17 18:27:53 +00:00
|
|
|
|
CounterList counterList;
|
2007-07-11 12:52:50 +00:00
|
|
|
|
///
|
|
|
|
|
bool appendix_;
|
2002-08-06 22:40:59 +00:00
|
|
|
|
|
2000-07-17 18:27:53 +00:00
|
|
|
|
};
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
} // namespace lyx
|
|
|
|
|
|
2000-07-17 18:27:53 +00:00
|
|
|
|
#endif
|