]> git.lyx.org Git - lyx.git/blob - src/counters.h
69c4983be810e318b611d813671966d9e2bae068
[lyx.git] / src / counters.h
1 // -*- C++ -*-
2 /* This file is part of
3  * ======================================================
4  *
5  *           LyX, The Document Processor
6  *
7  *           Copyright 1995 Matthias Ettrich
8  *           Copyright 1995-2001 The LyX Team.
9  *
10  *
11  * ====================================================== */
12
13
14 #ifndef COUNTERS_H
15 #define COUNTERS_H
16
17 #ifdef __GNUG__
18 #pragma interface
19 #endif
20
21 #include "LString.h"
22 #include <map>
23 #include <vector>
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         string master() const;
42         /// sets the master counter for this counter
43         void setMaster(string const & m);
44         ///
45
46 private:
47         int value_;
48         /// contains master counter name; master counter is the counter
49         /// that, if stepped (incremented) zeroes this counter. E.g.
50         /// "subparagraph"'s master is "paragraph".
51         string master_;
52 };
53
54
55 /// This is a class of (La)TeX type counters.
56 /// Every instantiation is an array of counters of type Counter.
57 class Counters {
58 public:
59         ///
60         Counters();
61         ///
62         //~Counters();
63         /// Add a new counter to array.
64         void newCounter(string const & newc);
65         /// Add new counter having oldc as its master.
66         void newCounter(string const & newc, string const & oldc);
67         ///
68         void set(string const & ctr, int val);
69         ///
70         void addto(string const & ctr, int val);
71         ///
72         int value(string const & ctr) const;
73         /// Step (increment by one) counter named by arg, and
74         /// zeroes slave counter(s) for which it is the master.
75         /// NOTE sub-slaves not zeroed! That happens at slave's
76         /// first step 0->1. Seems to be sufficient.
77         void step(string const & ctr);
78         /// Reset all counters.
79         void reset();
80         /// Reset counters matched by match string.
81         void reset(string const & match);
82         /// Copy counters whose name matches match from the &from to
83         /// the &to array of counters. Empty string matches all.
84         void copy(Counters & from, Counters & to, string const & match = string());
85         /// A numeric label's single item, like .1 for subsection number in
86         /// the 2.1.4 subsubsection number label. "first" indicates if this
87         /// is the first item to be displayed, usually chapter or section.
88         string labelItem(string const & ctr,
89                         string const & labeltype,
90                         string const & langtype = "latin",
91                         bool first = false);
92         /// A complete numeric label, like 2.1.4 for a subsubsection.
93         /// "head" indicates sequence number of first item to be
94         /// displayed, e.g. 0 for chapter, 1 for section.
95         string numberLabel(string const & ctr,
96                         string const & labeltype,
97                         string const & langtype = "latin",
98                         int head = 0);
99         /// Maps numbers to enumeration of sectioning counter name strings.
100         std::vector<string> enums;
101         std::vector<string> sects;
102
103 private:
104         /// Maps counter (layout) names to actual counters.
105         typedef std::map<string, Counter> CounterList;
106         /// Instantiate.
107         CounterList counterList;
108
109 };
110
111 #endif