]> git.lyx.org Git - lyx.git/blob - src/counters.h
Fix and simplify Hebrew (generally: locale non-standard) counters
[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 #include "buffer.h"
22
23 /// This represents a single counter.
24 class Counter {
25 public:
26         ///
27         Counter();
28         ///
29         void set(int v);
30         ///
31         void addto(int v);
32         ///
33         int value() const;
34         ///
35         void step();
36         ///
37         void reset();
38         /// Returns the master counter of this counter
39         std::string master() const;
40         /// sets the master counter for this counter
41         void setMaster(std::string const & m);
42 private:
43         ///
44         int value_;
45         /// contains master counter name; master counter is the counter
46         /// that, if stepped (incremented) zeroes this counter. E.g.
47         /// "subparagraph"'s master is "paragraph".
48         std::string master_;
49 };
50
51
52 /// This is a class of (La)TeX type counters.
53 /// Every instantiation is an array of counters of type Counter.
54 class Counters {
55 public:
56         /// Add a new counter to array.
57         void newCounter(std::string const & newc);
58         /// Add new counter having oldc as its master.
59         void newCounter(std::string const & newc, std::string const & oldc);
60         ///
61         void set(std::string const & ctr, int val);
62         ///
63         void addto(std::string const & ctr, int val);
64         ///
65         int value(std::string 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(std::string const & ctr);
71         /// Reset all counters.
72         void reset();
73         /// Reset counters matched by match string.
74         void reset(std::string 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, std::string const & match = std::string());
78         /// A complete expanded label, like 2.1.4 for a subsubsection
79         /// according to the given format
80         std::string counterLabel(std::string const & format);
81         /// A complete label, like 1.a for enumerations
82         std::string enumLabel(std::string const & ctr, Buffer const & buf);
83 private:
84         /// A counter label's single item, 1 for subsection number in
85         /// the 2.1.4 subsubsection number label.
86         std::string labelItem(std::string const & ctr, std::string const & numbertype);
87         /// Maps counter (layout) names to actual counters.
88         typedef std::map<std::string, Counter> CounterList;
89         /// Instantiate.
90         CounterList counterList;
91
92 };
93
94 #endif