2000-07-17 18:27:53 +00:00
|
|
|
|
// -*- C++ -*-
|
2003-08-23 00:17:00 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file counters.h
|
|
|
|
|
* 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
|
|
|
|
|
2002-05-29 16:21:03 +00:00
|
|
|
|
#include <map>
|
2003-10-06 15:43:21 +00:00
|
|
|
|
#include <string>
|
2002-09-05 12:58:10 +00:00
|
|
|
|
|
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
|
2003-10-06 15:43:21 +00:00
|
|
|
|
std::string master() const;
|
2002-08-07 14:15:06 +00:00
|
|
|
|
/// sets the master counter for this counter
|
2003-10-06 15:43:21 +00:00
|
|
|
|
void setMaster(std::string 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".
|
2003-10-06 15:43:21 +00:00
|
|
|
|
std::string 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.
|
2003-10-06 15:43:21 +00:00
|
|
|
|
void newCounter(std::string const & newc);
|
2002-08-07 14:15:06 +00:00
|
|
|
|
/// Add new counter having oldc as its master.
|
2003-10-06 15:43:21 +00:00
|
|
|
|
void newCounter(std::string const & newc, std::string const & oldc);
|
2000-07-17 18:27:53 +00:00
|
|
|
|
///
|
2003-10-06 15:43:21 +00:00
|
|
|
|
void set(std::string const & ctr, int val);
|
2000-07-17 18:27:53 +00:00
|
|
|
|
///
|
2003-10-06 15:43:21 +00:00
|
|
|
|
void addto(std::string const & ctr, int val);
|
2000-07-17 18:27:53 +00:00
|
|
|
|
///
|
2003-10-06 15:43:21 +00:00
|
|
|
|
int value(std::string 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.
|
2003-10-06 15:43:21 +00:00
|
|
|
|
void step(std::string const & ctr);
|
2002-08-11 20:34:20 +00:00
|
|
|
|
/// Reset all counters.
|
|
|
|
|
void reset();
|
|
|
|
|
/// Reset counters matched by match string.
|
2003-10-06 15:43:21 +00:00
|
|
|
|
void reset(std::string 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.
|
2003-10-06 15:43:21 +00:00
|
|
|
|
void copy(Counters & from, Counters & to, std::string const & match = std::string());
|
2003-09-12 17:13:22 +00:00
|
|
|
|
/// A complete expanded label, like 2.1.4 for a subsubsection
|
|
|
|
|
/// according to the given format
|
2003-10-06 15:43:21 +00:00
|
|
|
|
std::string counterLabel(std::string const & format);
|
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.
|
2003-10-06 15:43:21 +00:00
|
|
|
|
std::string labelItem(std::string const & ctr, std::string const & numbertype);
|
2002-08-07 14:15:06 +00:00
|
|
|
|
/// Maps counter (layout) names to actual counters.
|
2003-10-06 15:43:21 +00:00
|
|
|
|
typedef std::map<std::string, Counter> CounterList;
|
2002-08-07 14:15:06 +00:00
|
|
|
|
/// Instantiate.
|
2000-07-17 18:27:53 +00:00
|
|
|
|
CounterList counterList;
|
2002-08-06 22:40:59 +00:00
|
|
|
|
|
2000-07-17 18:27:53 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif
|