4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Lars Gullik Bjønnes
8 * \author Jean-Marc Lasgouttes
10 * \author Martin Vermeer
12 * Full author contact details are available in file CREDITS.
18 #include "support/docstring.h"
28 /// This represents a single counter.
34 Counter(docstring const & mc, docstring const & ls,
35 docstring const & lsa);
36 /// \return true on success
37 bool read(Lexer & lex);
48 /// Returns the master counter of this counter.
49 docstring const & master() const;
50 /// Returns a LaTeX-like string to format the counter.
51 /** This is similar to what one gets in LaTeX when using
52 * "\the<counter>". The \c in_appendix bool tells whether we
53 * want the version shown in an appendix.
55 docstring const & labelString(bool in_appendix) const;
56 /// Returns a map of LaTeX-like strings to format the counter.
57 /** For each language, the string is similar to what one gets
58 * in LaTeX when using "\the<counter>". The \c in_appendix
59 * bool tells whether we want the version shown in an
60 * appendix. This version does not contain any \\the<counter>
63 typedef std::map<std::string, docstring> StringMap;
64 StringMap & flatLabelStrings(bool in_appendix) const;
68 /// contains master counter name.
69 /** The master counter is the counter that, if stepped
70 * (incremented) zeroes this counter. E.g. "subsection"'s
71 * master is "section".
74 /// Contains a LaTeX-like string to format the counter.
75 docstring labelstring_;
76 /// The same as labelstring_, but in appendices.
77 docstring labelstringappendix_;
78 /// Cache of the labelstring with \\the<counter> expressions expanded,
79 /// indexed by language
80 mutable StringMap flatlabelstring_;
81 /// Cache of the appendix labelstring with \\the<counter> expressions expanded,
82 /// indexed by language
83 mutable StringMap flatlabelstringappendix_;
87 /// This is a class of (La)TeX type counters.
88 /// Every instantiation is an array of counters of type Counter.
92 Counters() : appendix_(false), subfloat_(false) {}
93 /// Add new counter newc having masterc as its master,
94 /// ls as its label, and lsa as its appendix label.
95 void newCounter(docstring const & newc,
96 docstring const & masterc,
98 docstring const & lsa);
99 /// Checks whether the given counter exists.
100 bool hasCounter(docstring const & c) const;
101 /// reads the counter name
102 /// \return true on success
103 bool read(Lexer & lex, docstring const & name);
105 void set(docstring const & ctr, int val);
107 void addto(docstring const & ctr, int val);
109 int value(docstring const & ctr) const;
110 /// Increment by one counter named by arg, and zeroes slave
111 /// counter(s) for which it is the master.
112 /** Sub-slaves not zeroed! That happens at slave's first step
113 * 0->1. Seems to be sufficient.
115 void step(docstring const & ctr);
116 /// Reset all counters.
118 /// Reset counters matched by match string.
119 void reset(docstring const & match);
120 /// Copy counters whose name matches match from the &from to
121 /// the &to array of counters. Empty string matches all.
122 void copy(Counters & from, Counters & to,
123 docstring const & match = docstring());
124 /** returns the expanded string representation of counter \c
125 * c. The \c lang code is used to translate the string.
127 docstring theCounter(docstring const & c,
128 std::string const & lang) const;
129 /** Replace in \c format all the LaTeX-like macros that depend
130 * on counters. The \c lang code is used to translate the
133 docstring counterLabel(docstring const & format,
134 std::string const & lang) const;
135 /// Are we in appendix?
136 bool appendix() const { return appendix_; };
137 /// Set the state variable indicating whether we are in appendix.
138 void appendix(bool a) { appendix_ = a; };
139 /// Returns the current enclosing float.
140 std::string const & current_float() const { return current_float_; }
141 /// Sets the current enclosing float.
142 void current_float(std::string const & f) { current_float_ = f; }
143 /// Are we in a subfloat?
144 bool isSubfloat() const { return subfloat_; }
145 /// Set the state variable indicating whether we are in a subfloat.
146 void isSubfloat(bool s) { subfloat_ = s; };
148 /** expands recusrsively any \\the<counter> macro in the
149 * labelstring of \c counter. The \c lang code is used to
150 * translate the string.
152 docstring flattenLabelString(docstring const & counter, bool in_appendix,
153 std::string const &lang,
154 std::vector<docstring> & callers) const;
155 /// Returns the value of the counter according to the
156 /// numbering scheme numbertype.
157 /** Available numbering schemes are arabic (1, 2,...), roman
158 * (i, ii,...), Roman (I, II,...), alph (a, b,...), Alpha (A,
161 docstring labelItem(docstring const & ctr,
162 docstring const & numbertype) const;
163 /// Maps counter (layout) names to actual counters.
164 typedef std::map<docstring, Counter> CounterList;
166 CounterList counterList_;
167 /// Are we in an appendix?
169 /// The current enclosing float.
170 std::string current_float_;
171 /// Are we in a subfloat?