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
53 * we want the version shown in an appendix.
55 docstring const & labelString(bool in_appendix) const;
56 /// Returns a LaTeX-like string to format the counter.
57 /** This is similar to what one gets in LaTeX when using
58 * "\the<counter>". The \c in_appendix bool tells whether
59 * we want the version shown in an appendix. This version does
60 * not contain any \\the<counter> expression.
62 docstring const & flatLabelString(bool in_appendix) const;
63 /// set the \c flatLabelString values.
64 void setFlatLabelStrings(docstring const & fls, docstring const & flsa);
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 /// A version of the labelstring with \\the<counter> expressions expanded
79 docstring flatlabelstring_;
80 /// A version of the appendix labelstring with \\the<counter> expressions expanded
81 docstring flatlabelstringappendix_;
85 /// This is a class of (La)TeX type counters.
86 /// Every instantiation is an array of counters of type Counter.
90 Counters() : appendix_(false), subfloat_(false) {}
91 /// Add new counter newc having masterc as its master,
92 /// ls as its label, and lsa as its appendix label.
93 void newCounter(docstring const & newc,
94 docstring const & masterc,
96 docstring const & lsa);
97 /// Checks whether the given counter exists.
98 bool hasCounter(docstring const & c) const;
99 /// reads the counter name
100 /// \return true on success
101 bool read(Lexer & lex, docstring const & name);
103 void set(docstring const & ctr, int val);
105 void addto(docstring const & ctr, int val);
107 int value(docstring const & ctr) const;
108 /// Increment by one counter named by arg, and zeroes slave
109 /// counter(s) for which it is the master.
110 /** Sub-slaves not zeroed! That happens at slave's first step
111 * 0->1. Seems to be sufficient.
113 void step(docstring const & ctr);
114 /// Reset all counters.
116 /// Reset counters matched by match string.
117 void reset(docstring const & match);
118 /// Copy counters whose name matches match from the &from to
119 /// the &to array of counters. Empty string matches all.
120 void copy(Counters & from, Counters & to,
121 docstring const & match = docstring());
122 /// returns the expanded string representation of the counter.
123 docstring theCounter(docstring const & c) const;
124 /// Replace in \c format all the LaTeX-like macros that depend on
126 docstring counterLabel(docstring const & format) const;
127 /// Are we in appendix?
128 bool appendix() const { return appendix_; };
129 /// Set the state variable indicating whether we are in appendix.
130 void appendix(bool a) { appendix_ = a; };
131 /// Returns the current enclosing float.
132 std::string const & current_float() const { return current_float_; }
133 /// Sets the current enclosing float.
134 void current_float(std::string const & f) { current_float_ = f; }
135 /// Are we in a subfloat?
136 bool isSubfloat() const { return subfloat_; }
137 /// Set the state variable indicating whether we are in a subfloat.
138 void isSubfloat(bool s) { subfloat_ = s; };
140 /// expands recusrsively any \\the<counter> macro in the
141 /// labelstring of \c counter.
142 docstring flattenLabelString(docstring const & counter, bool in_appendix,
143 std::vector<docstring> & callers) const;
144 /// Returns the value of the counter according to the
145 /// numbering scheme numbertype.
146 /** Available numbering schemes are arabic (1, 2,...), roman
147 * (i, ii,...), Roman (I, II,...), alph (a, b,...), Alpha (A,
150 docstring labelItem(docstring const & ctr,
151 docstring const & numbertype) const;
152 /// Maps counter (layout) names to actual counters.
153 typedef std::map<docstring, Counter> CounterList;
155 CounterList counterList_;
156 /// Are we in an appendix?
158 /// The current enclosing float.
159 std::string current_float_;
160 /// Are we in a subfloat?