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