]> git.lyx.org Git - lyx.git/blobdiff - src/counters.C
move counters to the layout files
[lyx.git] / src / counters.C
index a49cd412952c952d9846fadec1bbcd4cf06e15d0..8203a98ceaec6583467fdeae9b4404d1c6af576a 100644 (file)
@@ -17,7 +17,9 @@
 
 #include "counters.h"
 #include "debug.h"
+
 #include "support/lstrings.h"
+#include "support/LAssert.h"
 
 using std::endl;
 using std::vector;
@@ -58,56 +60,19 @@ 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");
-
-       sects.push_back("chapter");
-       sects.push_back("section");
-       sects.push_back("subsection");
-       sects.push_back("subsubsection");
-       sects.push_back("paragraph");
-       sects.push_back("subparagraph");
-
-       // Enumeration counters:
-       newCounter("enumi");
-       newCounter("enumii", "enumi");
-       newCounter("enumiii", "enumii");
-       newCounter("enumiv", "enumiii");
-
-       enums.push_back("enumi");
-       enums.push_back("enumii");
-       enums.push_back("enumiii");
-       enums.push_back("enumiv");
-
-       // Biblio:
-       newCounter("bibitem");
-
-       // Float counters:
-       newCounter("Figure");
-       newCounter("Table");
-}
-
 
 void Counters::newCounter(string const & newc)
 {
@@ -119,8 +84,6 @@ void Counters::newCounter(string const & newc)
                return;
        }
        counterList[newc];
-       cit = counterList.find(newc);
-       cit->second.setMaster("");
 }
 
 
@@ -141,9 +104,7 @@ void Counters::newCounter(string const & newc, string const & masterc)
                return;
        }
 
-       counterList[newc];
-       cit = counterList.find(newc);
-    cit->second.setMaster(masterc);
+       counterList[newc].setMaster(masterc);
 }
 
 
@@ -198,16 +159,30 @@ void Counters::step(string const & ctr)
        }
 }
 
+
+void Counters::reset()
+{
+       CounterList::iterator it = counterList.begin();
+       CounterList::iterator end = counterList.end();
+       for (; it != end; ++it) {
+               it->second.reset();
+       }
+}
+
+
 void Counters::reset(string const & match)
 {
+       lyx::Assert(!match.empty());
+
        CounterList::iterator it = counterList.begin();
        CounterList::iterator end = counterList.end();
        for (; it != end; ++it) {
-               if (it->first.find(match) != string::npos || match == "")
+               if (it->first.find(match) != string::npos)
                        it->second.reset();
        }
 }
 
+
 void Counters::copy(Counters & from, Counters & to, string const & match)
 {
        CounterList::iterator it = counterList.begin();
@@ -231,6 +206,7 @@ char loweralphaCounter(int n)
                return 'a' + n - 1;
 }
 
+
 inline
 char alphaCounter(int n)
 {
@@ -240,6 +216,7 @@ char alphaCounter(int n)
                return 'A' + n - 1;
 }
 
+
 inline
 char hebrewCounter(int n)
 {
@@ -254,6 +231,7 @@ char hebrewCounter(int n)
                return hebrew[n-1];
 }
 
+
 inline
 string const romanCounter(int n)
 {
@@ -271,18 +249,21 @@ string const romanCounter(int n)
 
 } // namespace anon
 
+
 string Counters::labelItem(string const & ctr,
-               string const & numbertype,
-               string const & langtype,
-               bool first)
+                          string const & numbertype,
+                          string const & langtype,
+                          bool first)
 {
-       ostringstream s, o;
+       ostringstream s;
+       ostringstream o;
+
        CounterList::iterator it = counterList.find(ctr);
        if (it == counterList.end()) {
                lyxerr << "Counter does not exist." << endl;
                return "";
        }
-       string mstr = it->second.master();
+
        if (!first) {
                s << "." << value(ctr);
        } else {
@@ -300,10 +281,11 @@ string Counters::labelItem(string const & ctr,
        return s.str();
 }
 
+
 string Counters::numberLabel(string const & ctr,
-               string const & numbertype,
-               string const & langtype,
-               int head)
+                            string const & numbertype,
+                            string const & langtype,
+                            int head)
 {
        ostringstream s, o;
        if (numbertype == "sectioning" || numbertype == "appendix") {
@@ -324,7 +306,7 @@ string Counters::numberLabel(string const & ctr,
                } else if (ctr == "subparagraph" && head <= 5) {
                        s << numberLabel("paragraph", numbertype, langtype, head)
                          << labelItem("subparagraph", numbertype, langtype, head == 5);
-               } else if (ctr == "Figure" || ctr == "Table") {
+               } else if (ctr == "figure" || ctr == "table") {
                        // figure, table, ...
                        lyxerr << "Counter:" << ctr << endl;
                        s << numberLabel("chapter", numbertype, langtype, head)
@@ -332,9 +314,11 @@ string Counters::numberLabel(string const & ctr,
                }
 
        } else if (numbertype == "enumeration") {
-               ostringstream ei, eii, eiii, eiv;
-               //string ei, eiii, eiv;
-               //char eii;
+               ostringstream ei;
+               ostringstream eii;
+               ostringstream eiii;
+               ostringstream eiv;
+
                if (langtype == "hebrew") {
                        ei << '.' << value("enumi");
                        eii << '(' << hebrewCounter(value("enumii")) << ')';