constify counters code and rename private variable counterList

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@29323 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Jean-Marc Lasgouttes 2009-04-19 10:06:17 +00:00
parent ef5f53017a
commit 22e92f0d6f
2 changed files with 40 additions and 41 deletions

View File

@ -161,13 +161,13 @@ void Counters::newCounter(docstring const & newc,
<< endl; << endl;
return; return;
} }
counterList[newc] = Counter(masterc, ls, lsa); counterList_[newc] = Counter(masterc, ls, lsa);
} }
bool Counters::hasCounter(docstring const & c) const bool Counters::hasCounter(docstring const & c) const
{ {
return counterList.find(c) != counterList.end(); return counterList_.find(c) != counterList_.end();
} }
@ -175,13 +175,13 @@ bool Counters::read(Lexer & lex, docstring const & name)
{ {
if (hasCounter(name)) { if (hasCounter(name)) {
LYXERR(Debug::TCLASS, "Reading existing counter " << to_utf8(name)); LYXERR(Debug::TCLASS, "Reading existing counter " << to_utf8(name));
return counterList[name].read(lex); return counterList_[name].read(lex);
} }
LYXERR(Debug::TCLASS, "Reading new counter " << to_utf8(name)); LYXERR(Debug::TCLASS, "Reading new counter " << to_utf8(name));
Counter cnt; Counter cnt;
bool success = cnt.read(lex); bool success = cnt.read(lex);
if (success) if (success)
counterList[name] = cnt; counterList_[name] = cnt;
else else
LYXERR0("Error reading counter `" << name << "'!"); LYXERR0("Error reading counter `" << name << "'!");
return success; return success;
@ -190,8 +190,8 @@ bool Counters::read(Lexer & lex, docstring const & name)
void Counters::set(docstring const & ctr, int const val) void Counters::set(docstring const & ctr, int const val)
{ {
CounterList::iterator const it = counterList.find(ctr); CounterList::iterator const it = counterList_.find(ctr);
if (it == counterList.end()) { if (it == counterList_.end()) {
lyxerr << "set: Counter does not exist: " lyxerr << "set: Counter does not exist: "
<< to_utf8(ctr) << endl; << to_utf8(ctr) << endl;
return; return;
@ -202,8 +202,8 @@ void Counters::set(docstring const & ctr, int const val)
void Counters::addto(docstring const & ctr, int const val) void Counters::addto(docstring const & ctr, int const val)
{ {
CounterList::iterator const it = counterList.find(ctr); CounterList::iterator const it = counterList_.find(ctr);
if (it == counterList.end()) { if (it == counterList_.end()) {
lyxerr << "addto: Counter does not exist: " lyxerr << "addto: Counter does not exist: "
<< to_utf8(ctr) << endl; << to_utf8(ctr) << endl;
return; return;
@ -214,8 +214,8 @@ void Counters::addto(docstring const & ctr, int const val)
int Counters::value(docstring const & ctr) const int Counters::value(docstring const & ctr) const
{ {
CounterList::const_iterator const cit = counterList.find(ctr); CounterList::const_iterator const cit = counterList_.find(ctr);
if (cit == counterList.end()) { if (cit == counterList_.end()) {
lyxerr << "value: Counter does not exist: " lyxerr << "value: Counter does not exist: "
<< to_utf8(ctr) << endl; << to_utf8(ctr) << endl;
return 0; return 0;
@ -226,16 +226,16 @@ int Counters::value(docstring const & ctr) const
void Counters::step(docstring const & ctr) void Counters::step(docstring const & ctr)
{ {
CounterList::iterator it = counterList.find(ctr); CounterList::iterator it = counterList_.find(ctr);
if (it == counterList.end()) { if (it == counterList_.end()) {
lyxerr << "step: Counter does not exist: " lyxerr << "step: Counter does not exist: "
<< to_utf8(ctr) << endl; << to_utf8(ctr) << endl;
return; return;
} }
it->second.step(); it->second.step();
it = counterList.begin(); it = counterList_.begin();
CounterList::iterator const end = counterList.end(); CounterList::iterator const end = counterList_.end();
for (; it != end; ++it) { for (; it != end; ++it) {
if (it->second.master() == ctr) { if (it->second.master() == ctr) {
it->second.reset(); it->second.reset();
@ -249,8 +249,8 @@ void Counters::reset()
appendix_ = false; appendix_ = false;
subfloat_ = false; subfloat_ = false;
current_float_.erase(); current_float_.erase();
CounterList::iterator it = counterList.begin(); CounterList::iterator it = counterList_.begin();
CounterList::iterator const end = counterList.end(); CounterList::iterator const end = counterList_.end();
for (; it != end; ++it) { for (; it != end; ++it) {
it->second.reset(); it->second.reset();
} }
@ -261,8 +261,8 @@ void Counters::reset(docstring const & match)
{ {
LASSERT(!match.empty(), /**/); LASSERT(!match.empty(), /**/);
CounterList::iterator it = counterList.begin(); CounterList::iterator it = counterList_.begin();
CounterList::iterator end = counterList.end(); CounterList::iterator end = counterList_.end();
for (; it != end; ++it) { for (; it != end; ++it) {
if (it->first.find(match) != string::npos) if (it->first.find(match) != string::npos)
it->second.reset(); it->second.reset();
@ -272,8 +272,8 @@ void Counters::reset(docstring const & match)
void Counters::copy(Counters & from, Counters & to, docstring const & match) void Counters::copy(Counters & from, Counters & to, docstring const & match)
{ {
CounterList::iterator it = counterList.begin(); CounterList::iterator it = counterList_.begin();
CounterList::iterator end = counterList.end(); CounterList::iterator end = counterList_.end();
for (; it != end; ++it) { for (; it != end; ++it) {
if (it->first.find(match) != string::npos || match == "") { if (it->first.find(match) != string::npos || match == "") {
to.set(it->first, from.value(it->first)); to.set(it->first, from.value(it->first));
@ -384,10 +384,10 @@ docstring const lowerromanCounter(int const n)
docstring Counters::labelItem(docstring const & ctr, docstring Counters::labelItem(docstring const & ctr,
docstring const & numbertype) docstring const & numbertype) const
{ {
CounterList::const_iterator const cit = counterList.find(ctr); CounterList::const_iterator const cit = counterList_.find(ctr);
if (cit == counterList.end()) { if (cit == counterList_.end()) {
lyxerr << "Counter " lyxerr << "Counter "
<< to_utf8(ctr) << to_utf8(ctr)
<< " does not exist." << endl; << " does not exist." << endl;
@ -415,25 +415,24 @@ docstring Counters::labelItem(docstring const & ctr,
} }
docstring Counters::theCounter(docstring const & counter) docstring Counters::theCounter(docstring const & counter) const
{ {
std::set<docstring> callers; std::set<docstring> callers;
return theCounter(counter, callers); return theCounter(counter, callers);
} }
docstring Counters::theCounter(docstring const & counter, docstring Counters::theCounter(docstring const & counter,
std::set<docstring> & callers) std::set<docstring> & callers) const
{ {
if (!hasCounter(counter))
return from_ascii("??");
docstring label; docstring label;
if (callers.find(counter) == callers.end()) { if (callers.find(counter) == callers.end()) {
pair<std::set<docstring>::iterator, bool> result = callers.insert(counter); CounterList::const_iterator it = counterList_.find(counter);
if (it == counterList_.end())
return from_ascii("??");
Counter const & c = it->second;
Counter const & c = counterList[counter];
docstring ls = appendix() ? c.labelStringAppendix() : c.labelString(); docstring ls = appendix() ? c.labelStringAppendix() : c.labelString();
if (ls.empty()) { if (ls.empty()) {
@ -442,8 +441,8 @@ docstring Counters::theCounter(docstring const & counter,
ls += from_ascii("\\arabic{") + counter + "}"; ls += from_ascii("\\arabic{") + counter + "}";
} }
pair<std::set<docstring>::iterator, bool> const result = callers.insert(counter);
label = counterLabel(ls, &callers); label = counterLabel(ls, &callers);
callers.erase(result.first); callers.erase(result.first);
} else { } else {
// recursion detected // recursion detected
@ -457,7 +456,7 @@ docstring Counters::theCounter(docstring const & counter,
docstring Counters::counterLabel(docstring const & format, docstring Counters::counterLabel(docstring const & format,
std::set<docstring> * callers) std::set<docstring> * callers) const
{ {
docstring label = format; docstring label = format;
@ -469,13 +468,13 @@ docstring Counters::counterLabel(docstring const & format,
size_t const i = label.find(from_ascii("\\the"), 0); size_t const i = label.find(from_ascii("\\the"), 0);
if (i == docstring::npos) if (i == docstring::npos)
break; break;
size_t j = i + 4; size_t const j = i + 4;
size_t k = j; size_t k = j;
while (k < label.size() && lowercase(label[k]) >= 'a' while (k < label.size() && lowercase(label[k]) >= 'a'
&& lowercase(label[k]) <= 'z') && lowercase(label[k]) <= 'z')
++k; ++k;
docstring counter = label.substr(j, k - j); docstring const counter = label.substr(j, k - j);
docstring repl = callers? theCounter(counter, *callers): docstring const repl = callers? theCounter(counter, *callers):
theCounter(counter); theCounter(counter);
label.replace(i, k - j + 4, repl); label.replace(i, k - j + 4, repl);
} }

View File

@ -111,11 +111,11 @@ public:
void copy(Counters & from, Counters & to, void copy(Counters & from, Counters & to,
docstring const & match = docstring()); docstring const & match = docstring());
/// returns the expanded string representation of the counter. /// returns the expanded string representation of the counter.
docstring theCounter(docstring const & c); docstring theCounter(docstring const & c) const;
/// Replace om format all the LaTeX-like macros that depend on /// Replace in \c format all the LaTeX-like macros that depend on
/// counters. /// counters.
docstring counterLabel(docstring const & format, docstring counterLabel(docstring const & format,
std::set<docstring> * callers = 0); std::set<docstring> * callers = 0) const;
/// Are we in apendix? /// Are we in apendix?
bool appendix() const { return appendix_; }; bool appendix() const { return appendix_; };
/// Set the state variable indicating whether we are in appendix. /// Set the state variable indicating whether we are in appendix.
@ -132,7 +132,7 @@ private:
/// returns the expanded string representation of the counter /// returns the expanded string representation of the counter
/// with recursion protection through callers. /// with recursion protection through callers.
docstring theCounter(docstring const & c, docstring theCounter(docstring const & c,
std::set<docstring> & callers); std::set<docstring> & callers) const;
/// Returns the value of the counter according to the /// Returns the value of the counter according to the
/// numbering scheme numbertype. /// numbering scheme numbertype.
/** Available numbering schemes are arabic (1, 2,...), roman /** Available numbering schemes are arabic (1, 2,...), roman
@ -140,11 +140,11 @@ private:
* B,...) and hebrew. * B,...) and hebrew.
*/ */
docstring labelItem(docstring const & ctr, docstring labelItem(docstring const & ctr,
docstring const & numbertype); docstring const & numbertype) const;
/// Maps counter (layout) names to actual counters. /// Maps counter (layout) names to actual counters.
typedef std::map<docstring, Counter> CounterList; typedef std::map<docstring, Counter> CounterList;
/// Instantiate. /// Instantiate.
CounterList counterList; CounterList counterList_;
/// Are we in an appendix? /// Are we in an appendix?
bool appendix_; bool appendix_;
/// The current enclosing float. /// The current enclosing float.