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"
26 /// This represents a single counter.
32 Counter(docstring const & mc, docstring const & ls,
33 docstring const & lsa);
44 /// Returns the master counter of this counter.
45 docstring const & master() const;
46 /// Returns a LaTeX-like string to format the counter.
47 /* This is similar to what one gets in LaTeX when using
50 docstring const & labelString() const;
51 /// Returns a LaTeX-like string to format the counter in appendix.
52 /* This is similar to what one gets in LaTeX when using
53 * "\the<counter>" in an appendix.
55 docstring const & labelStringAppendix() const;
59 /// contains master counter name.
60 /* The master counter is the counter that, if stepped
61 * (incremented) zeroes this counter. E.g. "subsection"'s
62 * master is "section".
65 // Contains a LaTeX-like string to format the counter.
66 docstring labelstring_;
67 // The same as labelstring_, but in appendices.
68 docstring labelstringappendix_;
72 /// This is a class of (La)TeX type counters.
73 /// Every instantiation is an array of counters of type Counter.
77 Counters() : appendix_(false), subfloat_(false) {}
78 /// Add a new counter to array.
79 void newCounter(docstring const & newc);
80 /// Add new counter having oldc as its master and ls as its label.
81 void newCounter(docstring const & newc,
82 docstring const & masterc,
84 docstring const & lsa);
85 /// Checks whether the given counter exists.
86 bool hasCounter(docstring const & c) const;
88 void set(docstring const & ctr, int val);
90 void addto(docstring const & ctr, int val);
92 int value(docstring const & ctr) const;
93 /// Increment by one counter named by arg, and zeroes slave
94 /// counter(s) for which it is the master.
95 /* Sub-slaves not zeroed! That happens at slave's first step
96 * 0->1. Seems to be sufficient.
98 void step(docstring const & ctr);
99 /// Reset all counters.
101 /// Reset counters matched by match string.
102 void reset(docstring const & match);
103 /// Copy counters whose name matches match from the &from to
104 /// the &to array of counters. Empty string matches all.
105 void copy(Counters & from, Counters & to,
106 docstring const & match = docstring());
107 /// returns the expanded string representation of the counter.
108 docstring theCounter(docstring const & c);
109 /// Replace om format all the LaTeX-like macros that depend on
111 docstring counterLabel(docstring const & format,
112 std::set<docstring> * callers = 0);
113 /// Are we in apendix?
114 bool appendix() const { return appendix_; };
115 /// Set the state variable indicating whether we are in appendix.
116 void appendix(bool a) { appendix_ = a; };
117 /// Returns the current enclosing float.
118 std::string const & current_float() const { return current_float_; }
119 /// Sets the current enclosing float.
120 void current_float(std::string const & f) { current_float_ = f; }
121 /// Are we in a subfloat?
122 bool isSubfloat() const { return subfloat_; }
123 /// Set the state variable indicating whether we are in a subfloat.
124 void isSubfloat(bool s) { subfloat_ = s; };
126 /// returns the expanded string representation of the counter
127 /// with recursion protection through callers.
128 docstring theCounter(docstring const & c,
129 std::set<docstring> & callers);
130 /// Returns the value of the counter according to the
131 /// numbering scheme numbertype.
132 /* Available numbering schemes are arabic (1, 2,...), roman
133 * (i, ii,...), Roman (I, II,...), alph (a, b,...), Alpha (A,
136 docstring labelItem(docstring const & ctr,
137 docstring const & numbertype);
138 /// Maps counter (layout) names to actual counters.
139 typedef std::map<docstring, Counter> CounterList;
141 CounterList counterList;
142 /// Are we in an appendix?
144 /// The current enclosing float.
145 std::string current_float_;
146 /// Are we in a subfloat?