Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members   Related Pages   Examples  

XSBPool.cpp

00001 #define TRACE_NAME "XSBPool"
00002 #include "XSBPool.h"
00003 // $Id: XSBPool_8cpp-source.html,v 1.2 2001/10/10 20:40:58 sandro Exp $
00004 #include "XSBQuery.h"
00005 
00007 //
00008 //  Standard Member Functions
00009 //
00011 
00012 
00013 XSBPool::XSBPool(XSBAgent& agent, VariableScope* scope)
00014     : agent(agent),
00015       cache(scope),
00016       maybeChanged(true)
00017 {
00018     file = agent.getFile(&fileName);
00019     predicate = agent.getNewPredicate();
00020     agent.pools.push_back(this);
00021     TRACE "XSBPool()  @" << this << " using file " << fileName << endl;
00022 }
00023 
00024 #if 0  /* omit definitions until they are implemented */
00025 
00026 XSBPool::XSBPool(const XSBPool& other)
00027 {
00028     NOT_IMPLEMENTED
00029 }
00030 
00031 const XSBPool& XSBPool::operator=(const XSBPool& other)
00032 {
00033     NOT_IMPLEMENTED
00034 }
00035 
00036 bool XSBPool::operator==(const XSBPool& other) const
00037 {
00038     NOT_IMPLEMENTED
00039 }
00040 
00041 bool XSBPool::operator<(const XSBPool& other) const
00042 {
00043     NOT_IMPLEMENTED
00044 }
00045 
00046 size_t XSBPool::hash() const
00047 {
00048     NOT_IMPLEMENTED
00049 }
00050 
00051 #endif /* omit definitions until they are implemented */
00052 
00053 std::ostream& XSBPool::print_to(std::ostream& stream) const
00054 {
00055     cache.print_to(stream);
00056     return stream;
00057 }
00058 
00059     
00060 XSBPool::~XSBPool()
00061 {
00062     agent.pools.remove(this);
00063     free(fileName);
00064 }
00065 
00067 //
00068 //  Additional Public Member Functions
00069 //
00071 
00072 
00073 static void printTriple(std::ostream& out, Triple t, int* maxVar) 
00074 {
00075     for (int i=0; i<3; i++) {
00076     Symbol s = t.get(i);
00077     if (s.isVar()) {
00078         int index = s.index();
00079         out << "var(" << index;
00080         if (maxVar && index > *maxVar) *maxVar = index;
00081         out << ")";
00082     } else {
00083         out << s.index();
00084     }
00085     if (i<2) out << ",";
00086     }
00087 }
00088 
00089 void XSBPool::sync()
00090 {
00091     if (maybeChanged) {
00092     maybeChanged = false;
00093     // file->seekp(0);
00094     
00095     *file << "% This is prolog file written by Blindfold::XSBPool.\n\n";
00096     
00097     LoopState l;
00098     size_t dcount=0;
00099     while (Triple t = cache.fetch(Triple::null, l)) {
00100         *file << predicate << "(";
00101         printTriple(*file, t, 0);
00102         *file << ").\n";
00103         dcount++;
00104     }
00105     if (dcount == 0) {
00106         // we still want XSB to know the predicate exists, just not to
00107         // match anything.
00108         *file << predicate << "(place_holder(0), place_holder(1), place_holder(2)).\n";
00109     }
00110     }
00111     file->flush();
00112     *(agent.out) << "['" << fileName << "'].\n";
00113 
00114 }
00115 
00116 
00118 //
00119 //  Additional Private Member Functions
00120 //
00122 
00123 #undef TRACE_NAME

Home to blindfold. This page generated via doxygen 1.2.11.1 Wed Oct 10 16:40:33 2001.