]> git.lyx.org Git - lyx.git/blob - src/counters.h
Point fix, earlier forgotten
[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 "LString.h"
19 #include <map>
20
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         string master() const;
39         /// sets the master counter for this counter
40         void setMaster(string 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         string 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(string const & newc);
57         /// Add new counter having oldc as its master.
58         void newCounter(string const & newc, string const & oldc);
59         ///
60         void set(string const & ctr, int val);
61         ///
62         void addto(string const & ctr, int val);
63         ///
64         int value(string const & ctr) const;
65         /// Step (increment by one) counter named by arg, and
66         /// zeroes slave counter(s) for which it is the master.
67         /// NOTE sub-slaves not zeroed! That happens at slave's
68         /// first step 0->1. Seems to be sufficient.
69         void step(string const & ctr);
70         /// Reset all counters.
71         void reset();
72         /// Reset counters matched by match string.
73         void reset(string const & match);
74         /// Copy counters whose name matches match from the &from to
75         /// the &to array of counters. Empty string matches all.
76         void copy(Counters & from, Counters & to, string const & match = string());
77         /// A numeric label's single item, like .1 for subsection number in
78         /// the 2.1.4 subsubsection number label. "first" indicates if this
79         /// is the first item to be displayed, usually chapter or section.
80         string labelItem(string const & ctr,
81                         string const & labeltype,
82                         string const & langtype = "latin",
83                         bool first = false);
84         /// A complete numeric label, like 2.1.4 for a subsubsection.
85         /// "head" indicates sequence number of first item to be
86         /// displayed, e.g. 0 for chapter, 1 for section.
87         string numberLabel(string const & ctr,
88                         string const & labeltype,
89                         string const & langtype = "latin",
90                         int head = 0);
91 private:
92         /// Maps counter (layout) names to actual counters.
93         typedef std::map<string, Counter> CounterList;
94         /// Instantiate.
95         CounterList counterList;
96
97 };
98
99 #endif