]> git.lyx.org Git - lyx.git/blob - src/counters.h
Move counters toward unicode.
[lyx.git] / src / counters.h
1 // -*- C++ -*-
2 /**
3  * \file counters.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Lars Gullik Bjønnes
8  * \author Jean-Marc Lasgouttes
9  * \author John Levon
10  * \author Martin Vermeer
11  *
12  * Full author contact details are available in file CREDITS.
13  */
14
15 #ifndef COUNTERS_H
16 #define COUNTERS_H
17
18 #include "support/docstring.h"
19
20 #include <map>
21
22 /// This represents a single counter.
23 class Counter {
24 public:
25         ///
26         Counter();
27         ///
28         void set(int v);
29         ///
30         void addto(int v);
31         ///
32         int value() const;
33         ///
34         void step();
35         ///
36         void reset();
37         /// Returns the master counter of this counter
38         lyx::docstring master() const;
39         /// sets the master counter for this counter
40         void setMaster(lyx::docstring const & m);
41 private:
42         ///
43         int value_;
44         /// contains master counter name; master counter is the counter
45         /// that, if stepped (incremented) zeroes this counter. E.g.
46         /// "subparagraph"'s master is "paragraph".
47         lyx::docstring master_;
48 };
49
50
51 /// This is a class of (La)TeX type counters.
52 /// Every instantiation is an array of counters of type Counter.
53 class Counters {
54 public:
55         /// Add a new counter to array.
56         void newCounter(lyx::docstring const & newc);
57         /// Add new counter having oldc as its master.
58         void newCounter(lyx::docstring const & newc,
59                         lyx::docstring const & oldc);
60         ///
61         void set(lyx::docstring const & ctr, int val);
62         ///
63         void addto(lyx::docstring const & ctr, int val);
64         ///
65         int value(lyx::docstring const & ctr) const;
66         /// Step (increment by one) counter named by arg, and
67         /// zeroes slave counter(s) for which it is the master.
68         /// NOTE sub-slaves not zeroed! That happens at slave's
69         /// first step 0->1. Seems to be sufficient.
70         void step(lyx::docstring const & ctr);
71         /// Reset all counters.
72         void reset();
73         /// Reset counters matched by match string.
74         void reset(lyx::docstring const & match);
75         /// Copy counters whose name matches match from the &from to
76         /// the &to array of counters. Empty string matches all.
77         void copy(Counters & from, Counters & to,
78                   lyx::docstring const & match = lyx::docstring());
79         /// A complete expanded label, like 2.1.4 for a subsubsection
80         /// according to the given format
81         lyx::docstring counterLabel(lyx::docstring const & format);
82 private:
83         /// A counter label's single item, 1 for subsection number in
84         /// the 2.1.4 subsubsection number label.
85         lyx::docstring labelItem(lyx::docstring const & ctr,
86                                  lyx::docstring const & numbertype);
87         /// Maps counter (layout) names to actual counters.
88         typedef std::map<lyx::docstring, Counter> CounterList;
89         /// Instantiate.
90         CounterList counterList;
91
92 };
93
94 #endif