]> git.lyx.org Git - lyx.git/blob - src/counters.h
prevent crash when inserting minipage in table cell,
[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 #include "LString.h"
18 #include <map>
19
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         string master() const;
38         /// sets the master counter for this counter
39         void setMaster(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         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(string const & newc);
56         /// Add new counter having oldc as its master.
57         void newCounter(string const & newc, string const & oldc);
58         ///
59         void set(string const & ctr, int val);
60         ///
61         void addto(string const & ctr, int val);
62         ///
63         int value(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(string const & ctr);
69         /// Reset all counters.
70         void reset();
71         /// Reset counters matched by match string.
72         void reset(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, string const & match = string());
76         /// A numeric label's single item, like .1 for subsection number in
77         /// the 2.1.4 subsubsection number label. "first" indicates if this
78         /// is the first item to be displayed, usually chapter or section.
79         string labelItem(string const & ctr,
80                         string const & labeltype,
81                         string const & langtype = "latin",
82                         bool first = false);
83         /// A complete numeric label, like 2.1.4 for a subsubsection.
84         /// "head" indicates sequence number of first item to be
85         /// displayed, e.g. 0 for chapter, 1 for section.
86         string numberLabel(string const & ctr,
87                         string const & labeltype,
88                         string const & langtype = "latin",
89                         int head = 0);
90 private:
91         /// Maps counter (layout) names to actual counters.
92         typedef std::map<string, Counter> CounterList;
93         /// Instantiate.
94         CounterList counterList;
95
96 };
97
98 #endif