On Mon, Jul 15, 2002 at 05:57:01PM +0100, Angus Leeming wrote: ... > Do you really need to make char Counters::hebrewCounter(int n) a class > method? It doesn't use any class variables. > > I'd suggest, in the .C file only: > > namespace { > > char Counters::hebrewCounter(int n) > { > ... > } > > } // namespace anon > > Ditto for other, similar helper functions. Keep the header file minimal. > > Angus
Did this. Diff attached. Martin -- Martin Vermeer [EMAIL PROTECTED] Helsinki University of Technology Department of Surveying P.O. Box 1200, FIN-02015 HUT, Finland :wq
Index: counters.C =================================================================== RCS file: /cvs/lyx/lyx-devel/src/counters.C,v retrieving revision 1.7 diff -u -p -r1.7 counters.C --- counters.C 2002/03/21 17:25:09 1.7 +++ counters.C 2002/07/16 11:36:37 @@ -17,10 +17,10 @@ #include "counters.h" #include "debug.h" +#include "support/lstrings.h" using std::endl; - Counter::Counter() { reset(); @@ -48,7 +48,7 @@ int Counter::value() const void Counter::step() { ++value_; - onstep.emit(); + //onstep.emit(); } @@ -57,6 +57,41 @@ void Counter::reset() value_ = 0; } +string Counter::master() const +{ + return master_; +} + +void Counter::setMaster(string const & m) +{ + master_ = m; +} + + +Counters::Counters() +{ + // Ehh, should this take a textclass arg? + + // Sectioning counters: + newCounter("part"); + newCounter("chapter"); + newCounter("section", "chapter"); + newCounter("subsection", "section"); + newCounter("subsubsection", "subsection"); + newCounter("paragraph", "subsubsection"); + newCounter("subparagraph", "paragraph"); + + // Enumeration counters: + newCounter("emumi"); + newCounter("emumii", "enumi"); + newCounter("enumiii", "enumii"); + newCounter("enumiv", "enumiii"); + + // Float counters: + newCounter("figure"); + newCounter("table"); +} + Counters::~Counters() { @@ -73,36 +108,35 @@ void Counters::newCounter(string const & { // First check if newc already exist CounterList::iterator cit = counterList.find(newc); - // if alrady exist give warning and return + // if already exist give warning and return if (cit != counterList.end()) { - lyxerr << "The new counter already exist." << endl; + lyxerr << "The new counter already exists." << endl; return; } counterList[newc] = new Counter; + cit->second->setMaster(""); } -void Counters::newCounter(string const & newc, string const & oldc) +void Counters::newCounter(string const & newc, string const & masterc) { - // First check if newc already exist + // First check if newc already exists CounterList::iterator cit = counterList.find(newc); // if already existant give warning and return if (cit != counterList.end()) { - lyxerr << "The new counter already exist." << endl; + lyxerr << "The new counter already exists." << endl; return; } - // then check if oldc exist - CounterList::iterator it = counterList.find(oldc); + // then check if masterc exists + CounterList::iterator it = counterList.find(masterc); // if not give warning and return if (it == counterList.end()) { - lyxerr << "The old counter does not exist." << endl; + lyxerr << "The master counter does not exist." << endl; return; } - Counter * tmp = new Counter; - it->second->onstep.connect(SigC::slot(tmp, - &Counter::reset)); - counterList[newc] = tmp; + counterList[newc] = new Counter; + cit->second->setMaster(masterc); } @@ -147,4 +181,118 @@ void Counters::step(string const & ctr) return; } it->second->step(); + if (it->second->master() != "") { + set(it->second->master(), 0); + } +} + +namespace { + +inline +char loweralphaCounter(int n) +{ + if (n < 1 || n > 26) + return '?'; + else + return 'a' + n - 1; +} + +inline +char alphaCounter(int n) +{ + if (n < 1 || n > 26) + return '?'; + else + return 'A' + n - 1; +} + +inline +char hebrewCounter(int n) +{ + static const char hebrew[22] = { + 'à', 'á', 'â', 'ã', 'ä', 'å', 'æ', 'ç', 'è', + 'é', 'ë', 'ì', 'î', 'ð', 'ñ', 'ò', 'ô', 'ö', + '÷', 'ø', 'ù', 'ú' + }; + if (n < 1 || n > 22) + return '?'; + else + return hebrew[n-1]; +} + +inline +string const romanCounter(int n) +{ + static char const * roman[20] = { + "i", "ii", "iii", "iv", "v", + "vi", "vii", "viii", "ix", "x", + "xi", "xii", "xiii", "xiv", "xv", + "xvi", "xvii", "xviii", "xix", "xx" + }; + if (n < 1 || n > 20) + return "??"; + else + return roman[n-1]; +} + +} // namespace anon + +string Counters::numberlabel(string const & ctr, + string const & numbertype, + string const & langtype) +{ + ostringstream s, o; + if (numbertype == "sectioning" || numbertype == "appendix") { + if (numbertype == "appendix") { + if (langtype == "hebrew") { + o << hebrewCounter(value("chapter")); + } else { + o << alphaCounter(value("chapter")); + } + } else o << value("chapter"); + + if (ctr == "chapter") { + s << o.str(); + } else if (ctr == "section") { + s << numberlabel("chapter", numbertype, langtype) + << '.' << value("section"); + } else if (ctr == "subsection") { + s << numberlabel("section", numbertype, langtype) + << '.' << value("subsection"); + } else if (ctr == "subsubsection") { + s << numberlabel("subsection", numbertype, langtype) + << '.' << value("subsubsection"); + } else if (ctr == "paragraph") { + s << numberlabel("subsubsection", numbertype, langtype) + << '.' << value("paragraph"); + } else if (ctr == "subparagraph") { + s << numberlabel("paragraph", numbertype, langtype) + << '.' << value("subparagraph"); + } + + } else if (numbertype == "enumeration") { + string eii, eiii, eiv; + char ei; + if (langtype == "hebrew") { + ei = hebrewCounter(value("enumi")); + eii = '.' + romanCounter(value("enumii")); + eiii = '.' + alphaCounter(value("enumiii")); + eiv = '.' + value("enumiv"); + } else { + ei = loweralphaCounter(value("enumi")); + eii = romanCounter(value("enumii")) + '.'; + eiii = alphaCounter(value("enumiii")) + '.'; + eiv = value("enumiv") + '.'; + } + if (ctr == "enumi") { + s << '(' << ei << ')'; + } else if (ctr == "enumii") { + s << eii; + } else if (ctr == "enumiii") { + s << eiii; + } else if (ctr == "enumiv") { + s << eiv; + } + } + return s.str(); } Index: counters.h =================================================================== RCS file: /cvs/lyx/lyx-devel/src/counters.h,v retrieving revision 1.7 diff -u -p -r1.7 counters.h --- counters.h 2002/05/29 16:20:57 1.7 +++ counters.h 2002/07/16 11:36:37 @@ -19,14 +19,10 @@ #endif #include "LString.h" - -#include <boost/signals/signal0.hpp> -#include <boost/signals/trackable.hpp> - #include <map> /// -class Counter : public boost::trackable { +class Counter { public: /// Counter(); @@ -41,10 +37,15 @@ public: /// void reset(); /// - boost::signal0<void> onstep; -private: + string master() const; /// + void setMaster(string const & m); + /// + +private: int value_; + /// + string master_; }; @@ -54,6 +55,8 @@ private: class Counters { public: /// + Counters(); + /// ~Counters(); /// void newCounter(string const & newc); @@ -68,11 +71,17 @@ public: /// void step(string const & ctr); // string refstep(string const & cou); + /// + string numberlabel(string const & ctr, + string const & labeltype, + string const & langtype = "latin"); + private: /// typedef std::map<string, Counter*> CounterList; /// CounterList counterList; + }; #endif
msg41070/pgp00000.pgp
Description: PGP signature