00001 #define TRACE_NAME "InMemoryPool"
00002
00003 #include "InMemoryPool.h"
00004
00006
00007
00008
00010
00011 InMemoryPool::InMemoryPool(VariableScope* scope)
00012 {
00013 if (scope) {
00014 this->scope = scope;
00015 scopeOwner = false;
00016 } else {
00017 this->scope = new SimpleVariableScope();
00018 scopeOwner = true;
00019 }
00020 }
00021
00022 #if 0
00023
00024
00025 InMemoryPool::InMemoryPool(const InMemoryPool& other)
00026 : triples(other.triples),
00027 scope(other.scope),
00028 scopeOwner(false)
00029 { }
00030 #endif
00031
00032
00033 #if 0
00034
00035 const InMemoryPool& InMemoryPool::operator=(const InMemoryPool& other)
00036 {
00037 NOT_IMPLEMENTED
00038 }
00039
00040 bool InMemoryPool::operator==(const InMemoryPool& other) const
00041 {
00042 NOT_IMPLEMENTED
00043 }
00044
00045 bool InMemoryPool::operator<(const InMemoryPool& other) const
00046 {
00047 NOT_IMPLEMENTED
00048 }
00049
00050 size_t InMemoryPool::hash() const
00051 {
00052 NOT_IMPLEMENTED
00053 }
00054
00055 std::ostream& InMemoryPool::print_to(std::ostream& stream) const
00056 {
00057 return TripleSource::print_to(stream);
00058 }
00059
00060 #endif
00061
00062 InMemoryPool::~InMemoryPool()
00063 {
00064 if (scopeOwner) delete scope;
00065 }
00066
00068
00069
00070
00072
00073
00074 void InMemoryPool::add(Triple t)
00075 {
00076 TRACE "Triple Added: " << t << " ( size=" << triples.size() << " ) " << std::endl;
00077 TRACE "Hash is: " << t.hash() << std::endl;
00078 assert(getScope()->contains(t));
00079 triples.insert(t);
00080 }
00081
00082
00083 #define PTR static_cast<std::hash_set<Triple>::iterator *>(ls.data.as_ptr)
00084
00085 static void reset_handler(LoopState& ls)
00086 {
00087 delete PTR;
00088 PTR = 0;
00089 ls.reset_handler = 0;
00090 }
00091
00092 Triple InMemoryPool::fetch(Triple simplePattern,
00093 LoopState& ls,
00094 unsigned long max_results=0) const
00095 {
00096 if (PTR == 0) {
00097 PTR = new std::hash_set<Triple>::iterator;
00098 *PTR = triples.begin();
00099 ls.reset_handler = reset_handler;
00100 } else {
00101 ++ *PTR;
00102 }
00103 if (*PTR == triples.end()) {
00104 delete PTR;
00105 PTR = 0;
00106 ls.reset_handler = 0;
00107 return Triple::null;
00108 }
00109 return * * PTR;
00110 }
00111
00112 void InMemoryPool::remove(Triple t)
00113 {
00114 triples.erase(t);
00115 }
00116
00117 void InMemoryPool::replace(Symbol old, Symbol replacement)
00118 {
00119 NOT_IMPLEMENTED;
00120 }
00121
00122 void InMemoryPool::addAll(const TripleSource& source)
00123 {
00124 LoopState ls;
00125 while(Triple t=source.fetch(Triple::null, ls)) {
00126 add(t);
00127 }
00128 }
00129
00130 InMemoryPool::InMemoryPool(const TripleSource& other)
00131 {
00132 this->scope = new SimpleVariableScope();
00133 scopeOwner = true;
00134 mUnion(other);
00135 }
00136
00138
00139
00140
00142
00143 #if 0
00144 #include "UnitTest.h"
00145 static bool test1(std::ostream& out) {
00146 return true;
00147 }
00148 static UnitTest t1(test1, __FILE__, 1, "");
00149 #endif
00150
00151
00152 #undef TRACE_NAME