add SegmentCache class
This commit is contained in:
parent
abe1e7d2e6
commit
acd93b877b
6
Makefile
6
Makefile
|
@ -1,8 +1,8 @@
|
||||||
CXXFLAGS=-g
|
CXXFLAGS=-g -std=c++11
|
||||||
|
|
||||||
all: v6502
|
all: v6502
|
||||||
|
|
||||||
v6502: v6502.o cpu.o nodes.o
|
v6502: v6502.o cpu.o nodes.o SegmentCache.o
|
||||||
g++ $^ -o $@
|
g++ $^ -o $@
|
||||||
|
|
||||||
v6502.o: v6502.cpp cpu.h addressbus.h
|
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
|
nodes.o: nodes.cpp nodes.h
|
||||||
|
|
||||||
|
SegmentCache.o : SegmentCache.cpp SegmentCache.h
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
-rm *.o
|
-rm *.o
|
||||||
-rm v6502
|
-rm v6502
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
/*
|
||||||
|
* File: SegmentCache.cpp
|
||||||
|
* Author: cmosher
|
||||||
|
*
|
||||||
|
* Created on December 10, 2013, 9:56 PM
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "SegmentCache.h"
|
||||||
|
#include <string>
|
||||||
|
#include <map>
|
||||||
|
#include <memory>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
Segment* SegmentCache::getOrAdd(std::string& id) {
|
||||||
|
if (this->cache.find(id) == this->cache.end()) {
|
||||||
|
this->cache[id] = std::make_shared<Segment>(id);
|
||||||
|
}
|
||||||
|
return this->cache[id].get();
|
||||||
|
}
|
|
@ -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 <memory>
|
||||||
|
#include <string>
|
||||||
|
#include <map>
|
||||||
|
|
||||||
|
class SegmentCache {
|
||||||
|
public:
|
||||||
|
SegmentCache() {}
|
||||||
|
virtual ~SegmentCache() {}
|
||||||
|
|
||||||
|
Segment* getOrAdd(std::string& id);
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::map<std::string,std::shared_ptr<Segment>> cache;
|
||||||
|
|
||||||
|
SegmentCache(const SegmentCache&);
|
||||||
|
SegmentCache& operator=(const SegmentCache&);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* SEGMENTCACHE_H */
|
Loading…
Reference in New Issue