]> git.lyx.org Git - lyx.git/blob - src/Counters.h
* src/frontends/qt4/qlkey.h: add AltGr as modifier key (fix bug 4026)
[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
23 namespace lyx {
24
25 /// This represents a single counter.
26 class Counter {
27 public:
28         ///
29         Counter();
30         ///
31         void set(int v);
32         ///
33         void addto(int v);
34         ///
35         int value() const;
36         ///
37         void step();
38         ///
39         void reset();
40         /// Returns the master counter of this counter
41         lyx::docstring const & master() const;
42         /// sets the master counter for this counter
43         void setMaster(lyx::docstring const & m);
44 private:
45         ///
46         int value_;
47         /// contains master counter name; master counter is the counter
48         /// that, if stepped (incremented) zeroes this counter. E.g.
49         /// "subparagraph"'s master is "paragraph".
50         lyx::docstring master_;
51 };
52
53
54 /// This is a class of (La)TeX type counters.
55 /// Every instantiation is an array of counters of type Counter.
56 class Counters {
57 public:
58         /// Add a new counter to array.
59         void newCounter(lyx::docstring const & newc);
60         /// Add new counter having oldc as its master.
61         void newCounter(lyx::docstring const & newc,
62                         lyx::docstring const & oldc);
63         ///
64         void set(lyx::docstring const & ctr, int val);
65         ///
66         void addto(lyx::docstring const & ctr, int val);
67         ///
68         int value(lyx::docstring const & ctr) const;
69         /// Step (increment by one) counter named by arg, and
70         /// zeroes slave counter(s) for which it is the master.
71         /// NOTE sub-slaves not zeroed! That happens at slave's
72         /// first step 0->1. Seems to be sufficient.
73         void step(lyx::docstring const & ctr);
74         /// Reset all counters.
75         void reset();
76         /// Reset counters matched by match string.
77         void reset(lyx::docstring const & match);
78         /// Copy counters whose name matches match from the &from to
79         /// the &to array of counters. Empty string matches all.
80         void copy(Counters & from, Counters & to,
81                   lyx::docstring const & match = lyx::docstring());
82         /// A complete expanded label, like 2.1.4 for a subsubsection
83         /// according to the given format
84         lyx::docstring counterLabel(lyx::docstring const & format);
85         ///
86         bool appendix() const { return appendix_; };
87         ///
88         void appendix(bool a) { appendix_ = a; };
89 private:
90         /// A counter label's single item, 1 for subsection number in
91         /// the 2.1.4 subsubsection number label.
92         lyx::docstring labelItem(lyx::docstring const & ctr,
93                                  lyx::docstring const & numbertype);
94         /// Maps counter (layout) names to actual counters.
95         typedef std::map<lyx::docstring, Counter> CounterList;
96         /// Instantiate.
97         CounterList counterList;
98         ///
99         bool appendix_;
100
101 };
102
103
104 } // namespace lyx
105
106 #endif