]> git.lyx.org Git - lyx.git/blob - src/counters.C
Dekel's lyxrc.example; Angus's FormDocument; John's build-listerrors; POTFILES.in...
[lyx.git] / src / counters.C
1 /* This file is part of
2  * ====================================================== 
3  * 
4  *           LyX, The Document Processor
5  *
6  *           Copyright 1995 Matthias Ettrich
7  *           Copyright 1995-2000 The LyX Team.
8  *
9  *
10  * ====================================================== */
11
12 #ifdef __GNUG__
13 #pragma implementation
14 #endif
15
16 #include <config.h>
17
18 #include "counters.h"
19 #include "debug.h"
20
21 #ifdef SIGC_CXX_NAMESPACES
22 using SigC::Connection;
23 using SigC::slot;
24 #endif
25
26 using std::endl;
27
28
29 Counter::Counter()
30 {
31         reset();
32 }
33
34
35 void Counter::set(int v)
36 {
37         value_ = v;
38 }
39
40
41 void Counter::addto(int v)
42 {
43         value_ += v;
44 }
45
46
47 int Counter::value() const
48 {
49         return value_;
50 }
51
52
53 void Counter::step()
54 {
55         ++value_;
56         onstep.emit();
57 }
58
59
60 void Counter::reset()
61 {
62         value_ = 0;
63 }
64
65
66 Counters::~Counters() 
67 {
68         // We need this since we store the Counter's as pointers in
69         // the counterList.
70         for (CounterList::iterator it = counterList.begin();
71              it != counterList.end();
72              ++it)
73                 delete (*it).second;
74 }
75
76
77 void Counters::newCounter(string const & newc)
78 {
79         // First check if newc already exist
80         CounterList::iterator cit = counterList.find(newc);
81         // if alrady exist give warning and return
82         if (cit != counterList.end()) {
83                 lyxerr << "The new counter already exist." << endl;
84                 return;
85         }
86         counterList[newc] = new Counter;
87 }
88
89
90 void Counters::newCounter(string const & newc, string const & oldc)
91 {
92         // First check if newc already exist
93         CounterList::iterator cit = counterList.find(newc);
94         // if already existant give warning and return
95         if (cit != counterList.end()) {
96                 lyxerr << "The new counter already exist." << endl;
97                 return;
98         }
99         // then check if oldc exist
100         CounterList::iterator it = counterList.find(oldc);
101         // if not give warning and return
102         if (it == counterList.end()) {
103                 lyxerr << "The old counter does not exist." << endl;
104                 return;
105         }
106
107         Counter * tmp = new Counter;
108         (*it).second->onstep.connect(slot(tmp,
109                                          &Counter::reset));
110         counterList[newc] = tmp;
111 }
112
113
114 void Counters::set(string const & ctr, int val) 
115 {
116         CounterList::iterator it = counterList.find(ctr);
117         if (it == counterList.end()) {
118                 lyxerr << "Counter does not exist." << endl;
119                 return;
120         }
121         (*it).second->set(val);
122 }
123
124
125 void Counters::addto(string const & ctr, int val)
126 {
127         CounterList::iterator it = counterList.find(ctr);
128         if (it == counterList.end()) {
129                 lyxerr << "Counter does not exist." << endl;
130                 return;
131         }
132         (*it).second->addto(val);
133 }
134
135
136 int Counters::value(string const & ctr) const 
137 {
138         CounterList::const_iterator cit = counterList.find(ctr);
139         if (cit == counterList.end()) {
140                 lyxerr << "Counter does not exist." << endl;
141                 return 0;
142         }
143         return (*cit).second->value();
144 }
145
146
147 void Counters::step(string const & ctr)
148 {
149         CounterList::iterator it = counterList.find(ctr);
150         if (it == counterList.end()) {
151                 lyxerr << "Counter does not exist." << endl;
152                 return;
153         }
154         (*it).second->step();
155 }