From acd93b877b931bec2ac37845ccf044507554a157 Mon Sep 17 00:00:00 2001 From: Christopher Date: Tue, 10 Dec 2013 23:58:09 -0500 Subject: [PATCH] add SegmentCache class --- Makefile | 6 ++++-- SegmentCache.cpp | 19 +++++++++++++++++++ SegmentCache.h | 30 ++++++++++++++++++++++++++++++ trans.h | 3 +++ 4 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 SegmentCache.cpp create mode 100644 SegmentCache.h diff --git a/Makefile b/Makefile index 5071964..c774034 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,8 @@ -CXXFLAGS=-g +CXXFLAGS=-g -std=c++11 all: v6502 -v6502: v6502.o cpu.o nodes.o +v6502: v6502.o cpu.o nodes.o SegmentCache.o g++ $^ -o $@ v6502.o: v6502.cpp cpu.h addressbus.h @@ -11,6 +11,8 @@ cpu.o: cpu.cpp cpu.h addressbus.h nodes.h nodes.o: nodes.cpp nodes.h +SegmentCache.o : SegmentCache.cpp SegmentCache.h + clean: -rm *.o -rm v6502 diff --git a/SegmentCache.cpp b/SegmentCache.cpp new file mode 100644 index 0000000..4cff130 --- /dev/null +++ b/SegmentCache.cpp @@ -0,0 +1,19 @@ +/* + * File: SegmentCache.cpp + * Author: cmosher + * + * Created on December 10, 2013, 9:56 PM + */ + +#include "SegmentCache.h" +#include +#include +#include +#include + +Segment* SegmentCache::getOrAdd(std::string& id) { + if (this->cache.find(id) == this->cache.end()) { + this->cache[id] = std::make_shared(id); + } + return this->cache[id].get(); +} diff --git a/SegmentCache.h b/SegmentCache.h new file mode 100644 index 0000000..8f49772 --- /dev/null +++ b/SegmentCache.h @@ -0,0 +1,30 @@ +/* + * File: SegmentCache.h + * Author: Christopher + * + * Created on December 10, 2013, 9:56 PM + */ + +#ifndef SEGMENTCACHE_H +#define SEGMENTCACHE_H + +#include "trans.h" +#include +#include +#include + +class SegmentCache { +public: + SegmentCache() {} + virtual ~SegmentCache() {} + + Segment* getOrAdd(std::string& id); + +private: + std::map> cache; + + SegmentCache(const SegmentCache&); + SegmentCache& operator=(const SegmentCache&); +}; + +#endif /* SEGMENTCACHE_H */ diff --git a/trans.h b/trans.h index 0329541..9e3f8c0 100644 --- a/trans.h +++ b/trans.h @@ -22,6 +22,9 @@ public: bool pullup; bool pulldown; bool on; + + Segment(std::string& id) : id(id) { + } }; class Trans {