From c2a0bd59370db718bceec72c46d6e1670eec1c52 Mon Sep 17 00:00:00 2001 From: Christopher Mosher Date: Sat, 14 Dec 2013 00:26:34 -0500 Subject: [PATCH] refactor; also notices intermittent failures --- Circuit.cpp | 8 +++----- SegmentCache.h | 2 +- Trace.cpp | 24 ++++++++++++++---------- Trace.h | 8 ++++---- 4 files changed, 22 insertions(+), 20 deletions(-) diff --git a/Circuit.cpp b/Circuit.cpp index 9c34d6c..56081f8 100644 --- a/Circuit.cpp +++ b/Circuit.cpp @@ -17,7 +17,7 @@ Circuit::Circuit(Segment* extendFrom, Segment* VSS, Segment* VCC) : VSS(VSS), VC * This happens recursively, but we don't recurse past ground or voltage supply. */ void Circuit::extend(Segment* extendFrom) { - const std::pair < std::set::iterator, bool> ret = this->segs.insert(extendFrom); + auto ret = this->segs.insert(extendFrom); if (!ret.second) { return; } @@ -34,8 +34,7 @@ void Circuit::extend(Segment* extendFrom) { * to OFF, so at the time of the very first recalcAll call, *no* other * segments will be added here. */ - for (std::set::const_iterator iTrn = extendFrom->c1c2s.begin(); iTrn != extendFrom->c1c2s.end(); ++iTrn) { - const Trans * t(*iTrn); + for (auto t : extendFrom->c1c2s) { if (t->on) { if (t->c1 == extendFrom) { extend(t->c2); @@ -62,8 +61,7 @@ bool Circuit::getValue() { - for (std::set::const_iterator iSeg = this->segs.begin(); iSeg != this->segs.end(); ++iSeg) { - Segment * s(*iSeg); + for (auto s : this->segs) { if (s->pullup) { return true; } diff --git a/SegmentCache.h b/SegmentCache.h index 43d027f..83c1f0d 100644 --- a/SegmentCache.h +++ b/SegmentCache.h @@ -28,7 +28,7 @@ public: std::set all() { std::set s; - for (auto i : cache) { + for (auto i : this->cache) { s.insert(i.second.get()); } return s; diff --git a/Trace.cpp b/Trace.cpp index 45e73eb..5da30ff 100644 --- a/Trace.cpp +++ b/Trace.cpp @@ -10,15 +10,19 @@ #include #include -static void pHex(const unsigned char x) { - std::cout << std::setw(2) << std::setfill('0') << std::hex << (unsigned long) x << std::dec; +static void pHex(const unsigned long x, const int width) { + std::cout << std::setw(width) << std::setfill('0') << std::hex << x << std::dec; +} + +static void pHexb(const unsigned char x) { + pHex(x,2); } static void pHexw(const unsigned short x) { - std::cout << std::setw(4) << std::setfill('0') << std::hex << (unsigned long) x << std::dec; + pHex(x,4); } -void Trace::dumpSegments() { +void Trace::dumpSegments() const { // for (int i = 0; i < segs.size(); ++i) { // seg& s = segs[i]; // if (s.pullup) { @@ -37,13 +41,13 @@ void Trace::dumpSegments() { // std::cout << std::endl; } -void Trace::dumpRegisters() { +void Trace::dumpRegisters() const { std::cout << "A"; - pHex(s.rA()); + pHexb(s.rA()); std::cout << " X"; - pHex(s.rX()); + pHexb(s.rX()); std::cout << " Y"; - pHex(s.rY()); + pHexb(s.rY()); std::cout << " "; std::cout << (s.c->P7->on ? "N" : "n"); std::cout << (s.c->P6->on ? "V" : "v"); @@ -54,7 +58,7 @@ void Trace::dumpRegisters() { std::cout << (s.c->P1->on ? "Z" : "z"); std::cout << (s.c->P0->on ? "C" : "c"); std::cout << " S"; - pHex(s.rS()); + pHexb(s.rS()); std::cout << " PC"; pHexw(s.rPC()); if (s.c->CLK1OUT->on) { @@ -72,7 +76,7 @@ void Trace::dumpRegisters() { std::cout << " PH- "; } std::cout << " DB"; - pHex(s.rData()); + pHexb(s.rData()); std::cout << " AB"; pHexw(s.rAddr()); std::cout << std::endl; diff --git a/Trace.h b/Trace.h index 2f3735e..f6e21cb 100644 --- a/Trace.h +++ b/Trace.h @@ -15,12 +15,12 @@ public: Trace(const SegmentCache& s) : s(s) {} virtual ~Trace() {} - void dumpSegments(); - void dumpRegisters(); + void dumpSegments() const; + void dumpRegisters() const; private: - Trace(const Trace&); - Trace& operator=(const Trace&); + Trace(const Trace&) = delete; + Trace& operator=(const Trace&) = delete; const SegmentCache& s; };