some refactoring; use C++11 foreach

This commit is contained in:
Christopher Mosher 2013-12-13 23:06:13 -05:00
parent 4f6338422f
commit 70d040a3aa
3 changed files with 20 additions and 18 deletions

View File

@ -28,8 +28,8 @@ public:
std::set<Segment*> all() {
std::set<Segment*> s;
for (std::map<const std::string, std::shared_ptr<Segment > >::const_iterator i = cache.begin(); i != cache.end(); ++i) {
s.insert(i->second.get());
for (auto i : cache) {
s.insert(i.second.get());
}
return s;
}

View File

@ -25,7 +25,7 @@ StateCalculator::StateCalculator(Segment* VSS, Segment* VCC) : VSS(VSS), VCC(VCC
void StateCalculator::recalc(Segment* seg, Segment* VSS, Segment* VCC) {
std::set<Segment*> rSeg;
rSeg.insert(seg);
recalc(rSeg,VSS,VCC);
recalc(rSeg, VSS, VCC);
}
/*
@ -36,20 +36,20 @@ void StateCalculator::recalc(Segment* seg, Segment* VSS, Segment* VCC) {
*/
#define SANE (100)
void StateCalculator::recalc(const std::set<Segment*>& rSeg, Segment* VSS, Segment* VCC) {
void StateCalculator::recalc(const std::set<Segment*>& segs, Segment* VSS, Segment* VCC) {
int sanity(0);
std::set<Segment*> riSegRecalc(rSeg);
while (!riSegRecalc.empty()) {
std::set<Segment*> changed(segs);
while (!changed.empty()) {
if (++sanity >= SANE) {
throw "ERROR: reached maximum iteration limit while recalculating CPU state";
}
StateCalculator c(VSS, VCC);
for (std::set<Segment*>::const_iterator is = riSegRecalc.begin(); is != riSegRecalc.end(); ++is) {
c.recalcNode(*is);
for (auto s : changed) {
c.recalcNode(s);
}
riSegRecalc = c.getChanged();
changed = c.getChanged();
}
}
@ -64,16 +64,17 @@ void StateCalculator::recalc(const std::set<Segment*>& rSeg, Segment* VSS, Segme
void StateCalculator::recalcNode(Segment* seg) {
if (!(seg == this->VSS || seg == this->VCC)) {
Circuit c(seg, this->VSS, this->VCC);
for (auto s : c) {
setSeg(s, c.getValue());
}
}
}
for (std::set<Segment*>::iterator is = c.begin(); is != c.end(); ++is) {
Segment * s(*is);
if (s->on != c.getValue()) {
s->on = c.getValue();
for (std::set<Trans*>::iterator it = s->gates.begin(); it != s->gates.end(); ++it) {
Trans * t(*it);
setTrans(t, c.getValue());
}
}
void StateCalculator::setSeg(Segment* s, const bool on) {
if (s->on != on) {
s->on = on;
for (auto t : s->gates) {
setTrans(t, on);
}
}
}

View File

@ -32,6 +32,7 @@ private:
StateCalculator& operator=(const StateCalculator&);
void recalcNode(Segment* seg);
void setSeg(Segment* s, const bool on);
void setTrans(Trans* t, const bool on);
void addRecalc(Segment* seg);