From d3068e35e6722e5d16c31c7c3c662bd2e9f6724a Mon Sep 17 00:00:00 2001 From: Christopher Mosher Date: Sun, 15 Dec 2013 14:00:43 -0500 Subject: [PATCH] refactor: add TransCache --- Emu6502.h | 4 +++- Makefile | 2 +- SegmentTypes.h | 42 +++++++++++++++++++++--------------------- TransCache.cpp | 13 +++++++++++++ TransCache.h | 33 +++++++++++++++++++++++++++++++++ TransNetwork.cpp | 5 +++-- TransNetwork.h | 5 +++-- 7 files changed, 77 insertions(+), 27 deletions(-) create mode 100644 TransCache.cpp create mode 100644 TransCache.h diff --git a/Emu6502.h b/Emu6502.h index 63f3333..2412cad 100644 --- a/Emu6502.h +++ b/Emu6502.h @@ -13,6 +13,7 @@ #include "Trace.h" #include "Common.h" #include "TransNetwork.h" +#include "TransCache.h" #include "SegmentCache.h" #include @@ -21,7 +22,7 @@ class AddressBus; class Emu6502 { public: - Emu6502(std::istream& transistors, AddressBus& mem) : tn(transistors, segs), c(tn), trace(segs, c), cpu(mem, trace, c), cpuhelper(cpu, c) { + Emu6502(std::istream& transistors, AddressBus& mem) : tn(transistors, segs, transes), c(tn), trace(segs, c), cpu(mem, trace, c), cpuhelper(cpu, c) { } virtual ~Emu6502() { @@ -45,6 +46,7 @@ private: Emu6502 operator=(const Emu6502&) = delete; SegmentCache segs; + TransCache transes; TransNetwork tn; Common c; Trace trace; diff --git a/Makefile b/Makefile index 69b842b..2a8c0ae 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ CXXFLAGS=-g -std=c++11 -Wall -O3 DOXYGEN=doxygen -SRCS = v6502.cpp Emu6502.cpp SegmentCache.cpp Common.cpp TransNetwork.cpp Trace.cpp Circuit.cpp StateCalculator.cpp Cpu6502.cpp Cpu6502Helper.cpp +SRCS = v6502.cpp Emu6502.cpp SegmentCache.cpp TransCache.cpp Common.cpp TransNetwork.cpp Trace.cpp Circuit.cpp StateCalculator.cpp Cpu6502.cpp Cpu6502Helper.cpp OBJS = $(SRCS:.cpp=.o) DEPS = $(SRCS:.cpp=.d) diff --git a/SegmentTypes.h b/SegmentTypes.h index 986dbff..c964bb7 100644 --- a/SegmentTypes.h +++ b/SegmentTypes.h @@ -1,21 +1,21 @@ -/* - * File: setpSeg.h - * Author: Christopher - * - * Created on December 15, 2013, 12:16 AM - */ - -#ifndef SETPSEG_H -#define SETPSEG_H - -#include "ptr_less.h" -#include -#include - -class Segment; - -typedef std::set> SegmentSet; -typedef std::set> PinSettings; - -#endif /* SETPSEG_H */ - +/* + * File: setpSeg.h + * Author: Christopher + * + * Created on December 15, 2013, 12:16 AM + */ + +#ifndef SETPSEG_H +#define SETPSEG_H + +#include "ptr_less.h" +#include +#include + +class Segment; + +typedef std::set> SegmentSet; +typedef std::set> PinSettings; + +#endif /* SETPSEG_H */ + diff --git a/TransCache.cpp b/TransCache.cpp new file mode 100644 index 0000000..69f8a86 --- /dev/null +++ b/TransCache.cpp @@ -0,0 +1,13 @@ +/* + * File: TransCache.cpp + * Author: Christopher + * + * Created on December 15, 2013, 1:39 PM + */ + +#include "TransCache.h" +#include "trans.h" + +void TransCache::add(Segment* c1, Segment* gate, Segment* c2) { + this->cache.insert(std::make_shared(c1,gate,c2)); +} diff --git a/TransCache.h b/TransCache.h new file mode 100644 index 0000000..ac59144 --- /dev/null +++ b/TransCache.h @@ -0,0 +1,33 @@ +/* + * File: TransCache.h + * Author: Christopher + * + * Created on December 15, 2013, 1:39 PM + */ + +#ifndef TRANSCACHE_H +#define TRANSCACHE_H + +#include +#include + +class Trans; +class Segment; + +class TransCache final { +public: + + TransCache() { + } + + void add(Segment* c1, Segment* gate, Segment* c2); + +private: + + TransCache(const TransCache&) = delete; + TransCache& operator=(const TransCache&) = delete; + + std::set> cache; +}; + +#endif /* TRANSCACHE_H */ diff --git a/TransNetwork.cpp b/TransNetwork.cpp index b49fccf..9d65dfc 100644 --- a/TransNetwork.cpp +++ b/TransNetwork.cpp @@ -6,6 +6,7 @@ */ #include "TransNetwork.h" +#include "TransCache.h" #include "SegmentCache.h" #include "StateCalculator.h" #include "trans.h" @@ -14,11 +15,11 @@ #include #include -TransNetwork::TransNetwork(std::istream& in, SegmentCache& segs) : segs(segs) { +TransNetwork::TransNetwork(std::istream& in, SegmentCache& segs, TransCache& transes) : segs(segs), transes(transes) { std::string c1, gate, c2; in >> c1 >> gate >> c2; while (in.good()) { - this->transes.insert(std::make_shared(this->segs.getOrAdd(c1), this->segs.getOrAdd(gate), this->segs.getOrAdd(c2))); + this->transes.add(this->segs.getOrAdd(c1), this->segs.getOrAdd(gate), this->segs.getOrAdd(c2)); in >> c1 >> gate >> c2; } diff --git a/TransNetwork.h b/TransNetwork.h index 1b13d7a..a9f5961 100644 --- a/TransNetwork.h +++ b/TransNetwork.h @@ -12,6 +12,7 @@ #include #include +class TransCache; class SegmentCache; class Common; class Trans; @@ -19,7 +20,7 @@ class Trans; class TransNetwork final { public: - TransNetwork(std::istream& readFromHere, SegmentCache& segs); + TransNetwork(std::istream& readFromHere, SegmentCache& segs, TransCache& transes); private: @@ -27,7 +28,7 @@ private: TransNetwork& operator=(const TransNetwork&) = delete; SegmentCache& segs; - std::set> transes; + TransCache& transes; friend Common; };