refactor: add TransCache

This commit is contained in:
Christopher Mosher 2013-12-15 14:00:43 -05:00
parent 90145f3d37
commit d3068e35e6
7 changed files with 77 additions and 27 deletions

View File

@ -13,6 +13,7 @@
#include "Trace.h"
#include "Common.h"
#include "TransNetwork.h"
#include "TransCache.h"
#include "SegmentCache.h"
#include <istream>
@ -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;

View File

@ -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)

13
TransCache.cpp Normal file
View File

@ -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<Trans>(c1,gate,c2));
}

33
TransCache.h Normal file
View File

@ -0,0 +1,33 @@
/*
* File: TransCache.h
* Author: Christopher
*
* Created on December 15, 2013, 1:39 PM
*/
#ifndef TRANSCACHE_H
#define TRANSCACHE_H
#include <set>
#include <memory>
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<std::shared_ptr<Trans>> cache;
};
#endif /* TRANSCACHE_H */

View File

@ -6,6 +6,7 @@
*/
#include "TransNetwork.h"
#include "TransCache.h"
#include "SegmentCache.h"
#include "StateCalculator.h"
#include "trans.h"
@ -14,11 +15,11 @@
#include <string>
#include <memory>
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<Trans>(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;
}

View File

@ -12,6 +12,7 @@
#include <set>
#include <memory>
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<std::shared_ptr<Trans>> transes;
TransCache& transes;
friend Common;
};