2000-07-17 18:27:53 +00:00
|
|
|
// -*- C++ -*-
|
2000-07-24 13:53:19 +00:00
|
|
|
/* This file is part of
|
2002-03-21 17:27:08 +00:00
|
|
|
* ======================================================
|
|
|
|
*
|
2000-07-24 13:53:19 +00:00
|
|
|
* 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
|
|
|
*
|
|
|
|
*
|
|
|
|
* ====================================================== */
|
|
|
|
|
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
|
|
|
|
2000-07-24 13:53:19 +00:00
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma interface
|
|
|
|
#endif
|
|
|
|
|
2000-07-17 18:27:53 +00:00
|
|
|
#include "LString.h"
|
2002-05-29 16:21:03 +00:00
|
|
|
#include <map>
|
2002-09-05 12:58:10 +00:00
|
|
|
|
2002-05-29 16:21:03 +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
|
2002-08-06 22:40:59 +00:00
|
|
|
string master() const;
|
2002-08-07 14:15:06 +00:00
|
|
|
/// sets the master counter for this counter
|
2002-08-06 22:40:59 +00:00
|
|
|
void setMaster(string const & m);
|
|
|
|
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".
|
2002-08-06 22:40:59 +00:00
|
|
|
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.
|
2000-07-17 18:27:53 +00:00
|
|
|
void newCounter(string const & newc);
|
2002-08-07 14:15:06 +00:00
|
|
|
/// Add new counter having oldc as its master.
|
2000-07-17 18:27:53 +00:00
|
|
|
void newCounter(string const & newc, string const & oldc);
|
|
|
|
///
|
|
|
|
void set(string const & ctr, int val);
|
|
|
|
///
|
|
|
|
void addto(string const & ctr, int val);
|
|
|
|
///
|
|
|
|
int value(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.
|
2000-07-17 18:27:53 +00:00
|
|
|
void step(string const & ctr);
|
2002-08-11 20:34:20 +00:00
|
|
|
/// Reset all counters.
|
|
|
|
void reset();
|
|
|
|
/// Reset counters matched by match string.
|
|
|
|
void reset(string const & match);
|
|
|
|
/// 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.
|
|
|
|
void copy(Counters & from, Counters & to, string const & match = string());
|
|
|
|
/// A numeric label's single item, like .1 for subsection number in
|
|
|
|
/// the 2.1.4 subsubsection number label. "first" indicates if this
|
|
|
|
/// is the first item to be displayed, usually chapter or section.
|
2002-08-06 22:40:59 +00:00
|
|
|
string labelItem(string const & ctr,
|
2002-08-11 20:34:20 +00:00
|
|
|
string const & labeltype,
|
2002-08-06 22:40:59 +00:00
|
|
|
string const & langtype = "latin",
|
|
|
|
bool first = false);
|
2002-08-07 14:15:06 +00:00
|
|
|
/// A complete numeric label, like 2.1.4 for a subsubsection.
|
|
|
|
/// "head" indicates sequence number of first item to be
|
|
|
|
/// displayed, e.g. 0 for chapter, 1 for section.
|
2002-08-06 22:40:59 +00:00
|
|
|
string numberLabel(string const & ctr,
|
2002-08-11 20:34:20 +00:00
|
|
|
string const & labeltype,
|
2002-08-06 22:40:59 +00:00
|
|
|
string const & langtype = "latin",
|
|
|
|
int head = 0);
|
2000-07-17 18:27:53 +00:00
|
|
|
private:
|
2002-08-07 14:15:06 +00:00
|
|
|
/// Maps counter (layout) names to actual counters.
|
2002-08-06 22:40:59 +00:00
|
|
|
typedef std::map<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
|