]> git.lyx.org Git - features.git/blob - src/Counters.h
* Counter.cpp (hasCounter): new method.
[features.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         docstring const & master() const;
42         /// sets the master counter for this counter
43         void setMaster(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         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(docstring const & newc);
60         /// Add new counter having oldc as its master.
61         void newCounter(docstring const & newc,
62                         docstring const & oldc);
63         ///
64         bool hasCounter(docstring const & c) const;
65         ///
66         void set(docstring const & ctr, int val);
67         ///
68         void addto(docstring const & ctr, int val);
69         ///
70         int value(docstring const & ctr) const;
71         /// Step (increment by one) counter named by arg, and
72         /// zeroes slave counter(s) for which it is the master.
73         /// NOTE sub-slaves not zeroed! That happens at slave's
74         /// first step 0->1. Seems to be sufficient.
75         void step(docstring const & ctr);
76         /// Reset all counters.
77         void reset();
78         /// Reset counters matched by match string.
79         void reset(docstring const & match);
80         /// Copy counters whose name matches match from the &from to
81         /// the &to array of counters. Empty string matches all.
82         void copy(Counters & from, Counters & to,
83                   docstring const & match = docstring());
84         /// A complete expanded label, like 2.1.4 for a subsubsection
85         /// according to the given format
86         docstring counterLabel(docstring const & format);
87         ///
88         bool appendix() const { return appendix_; };
89         ///
90         void appendix(bool a) { appendix_ = a; };
91         ///
92         std::string const & current_float() const { return current_float_; }
93         ///
94         void current_float(std::string const & f) { current_float_ = f; }
95 private:
96         /// A counter label's single item, 1 for subsection number in
97         /// the 2.1.4 subsubsection number label.
98         docstring labelItem(docstring const & ctr,
99                                  docstring const & numbertype);
100         /// Maps counter (layout) names to actual counters.
101         typedef std::map<docstring, Counter> CounterList;
102         /// Instantiate.
103         CounterList counterList;
104         ///
105         bool appendix_;
106         ///
107         std::string current_float_;
108 };
109
110
111 } // namespace lyx
112
113 #endif