Space* RBS::next(void) { if (restart) { restart = false; sslr++; NoGoods& ng = e->nogoods(); // Reset number of no-goods found ng.ng(0); CRI cri(stop->m_stat.restart,sslr,e->statistics().fail,last,ng); bool r = master->master(cri); stop->m_stat.nogood += ng.ng(); if (master->status(stop->m_stat) == SS_FAILED) { stop->update(e->statistics()); delete master; master = NULL; e->reset(NULL); return NULL; } else if (r) { stop->update(e->statistics()); Space* slave = master; master = master->clone(shared); complete = slave->slave(cri); e->reset(slave); sslr = 0; stop->m_stat.restart++; } } while (true) { Space* n = e->next(); if (n != NULL) { // The engine found a solution restart = true; delete last; last = n->clone(); return n; } else if ( (!complete && !e->stopped()) || (e->stopped() && stop->enginestopped()) ) { // The engine must perform a true restart // The number of the restart has been incremented in the stop object sslr = 0; NoGoods& ng = e->nogoods(); ng.ng(0); CRI cri(stop->m_stat.restart,sslr,e->statistics().fail,last,ng); (void) master->master(cri); stop->m_stat.nogood += ng.ng(); long unsigned int nl = ++(*co); stop->limit(e->statistics(),nl); if (master->status(stop->m_stat) == SS_FAILED) return NULL; Space* slave = master; master = master->clone(shared); complete = slave->slave(cri); e->reset(slave); } else { return NULL; } } GECODE_NEVER; return NULL; }
bool TSessionSqlObjectStore::remove(const QDateTime &garbageExpiration) { TSqlORMapper<TSessionObject> mapper; TCriteria cri(TSessionObject::UpdatedAt, TSql::LessThan, garbageExpiration); int cnt = mapper.removeAll(cri); return (cnt >= 0); }
forceinline RBS<E,T>::RBS(T* s, const Search::Options& m_opt) { if (m_opt.cutoff == NULL) throw Search::UninitializedCutoff("RBS::RBS"); Search::Options e_opt(m_opt.expand()); e_opt.clone = false; Search::Meta::RestartStop* rs = new Search::Meta::RestartStop(m_opt.stop); e_opt.stop = rs; Space* master; Space* slave; if (s->status(rs->m_stat) == SS_FAILED) { rs->m_stat.fail++; master = NULL; slave = NULL; } else { if (m_opt.clone) master = s->clone(); else master = s; slave = master->clone(); CRI cri(0,0,0,NULL,NoGoods::eng); slave->slave(cri); } E<T> engine(dynamic_cast<T*>(slave),e_opt); Search::EngineBase<T>* eb = &engine; Search::Engine* ee = eb->e; eb->e = NULL; e = new Search::Meta::RBS(master,rs,ee,m_opt); }
int TSessionSqlObjectStore::gc(const QDateTime &expire) { TSqlORMapper<TSessionObject> mapper; TCriteria cri(TSessionObject::UpdatedAt, TSql::LessThan, expire); int cnt = mapper.removeAll(cri); return cnt; }
bool TSessionSqlObjectStore::store(TSession &session) { TSqlORMapper<TSessionObject> mapper; TCriteria cri(TSessionObject::Id, TSql::Equal, session.id()); TSessionObject so = mapper.findFirst(cri); #ifndef TF_NO_DEBUG { QByteArray badummy; QDataStream dsdmy(&badummy, QIODevice::ReadWrite); dsdmy << *static_cast<const QVariantMap *>(&session); TSession dummy; dsdmy.device()->seek(0); dsdmy >> *static_cast<QVariantMap *>(&dummy); if (dsdmy.status() != QDataStream::Ok) { tSystemError("Failed to store a session into the cookie store. Must set objects that can be serialized."); } } #endif QDataStream ds(&so.data, QIODevice::WriteOnly); ds << *static_cast<const QVariantMap *>(&session); if (ds.status() != QDataStream::Ok) { tSystemError("Failed to store session. Must set objects that can be serialized."); return false; } if (so.isNull()) { so.id = session.id(); return so.create(); } return so.update(); }
bool TSessionSqlObjectStore::store(TSession &session) { TSqlORMapper<TSessionObject> mapper; TCriteria cri(TSessionObject::Id, TSql::Equal, session.id()); TSessionObject so = mapper.findFirst(cri); QDataStream ds(&so.data, QIODevice::WriteOnly); ds << *static_cast<const QVariantHash *>(&session); if (so.isEmpty()) { so.id = session.id(); return so.create(); } return so.update(); }
int main( int argc, const char** argv) { try { g_errorBuffer = strus::createErrorBuffer_standard( 0, 1); if (!g_errorBuffer) { std::cerr << "construction of error buffer failed" << std::endl; return -1; } else if (argc > 3) { printUsage( argc, argv); std::cerr << "too many arguments" << std::endl; return 1; } else if (argc < 3) { printUsage( argc, argv); std::cerr << "too few arguments" << std::endl; return 1; } // Create objects: std::auto_ptr<strus::TokenPatternMatchInterface> pti( strus::createTokenPatternMatch_standard( g_errorBuffer)); if (!pti.get()) throw std::runtime_error("failed to create pattern matcher"); std::auto_ptr<strus::CharRegexMatchInterface> cri( strus::createCharRegexMatch_standard( g_errorBuffer)); if (!cri.get()) throw std::runtime_error("failed to create char regex matcher"); std::auto_ptr<strus::PatternMatchProgramInterface> ppi( strus::createPatternMatchProgram_standard( pti.get(), cri.get(), g_errorBuffer)); if (!ppi.get()) throw std::runtime_error("failed to create pattern program loader"); std::auto_ptr<strus::PatternMatchProgramInstanceInterface> pii( ppi->createInstance()); if (!pii.get()) throw std::runtime_error("failed to create pattern program loader instance"); // Load program: std::string programfile( argv[ 1]); std::string programsrc; unsigned int ec; ec = strus::readFile( programfile, programsrc); if (ec) { char errmsg[ 256]; ::snprintf( errmsg, sizeof(errmsg), "error (%u) reading program source '%s': %s", ec, programfile.c_str(), ::strerror(ec)); throw std::runtime_error( errmsg); } if (!pii->load( programsrc)) { throw std::runtime_error( "error loading pattern match program source"); } if (!pii->compile()) { throw std::runtime_error( "error compiling pattern match program"); } // Load input: std::string inputfile( argv[ 2]); std::string inputsrc; ec = strus::readFile( inputfile, inputsrc); if (ec) { char errmsg[ 256]; ::snprintf( errmsg, sizeof(errmsg), "error (%u) reading input file '%s': %s", ec, inputfile.c_str(), ::strerror(ec)); throw std::runtime_error( errmsg); } // Load expected output: char const* argv2ext = std::strchr( argv[ 2], '.'); if (argv2ext) { char const* aa = std::strchr( argv2ext+1, '.'); while (aa) { argv2ext = aa; aa = std::strchr( argv2ext+1, '.'); } } else { argv2ext = std::strchr( argv[ 2], '\0'); } std::string expectedfile( argv[ 2], argv2ext - argv[ 2]); expectedfile.append( ".res"); std::string expectedsrc; ec = strus::readFile( expectedfile, expectedsrc); if (ec) { char errmsg[ 256]; ::snprintf( errmsg, sizeof(errmsg), "error (%u) reading expected file '%s': %s", ec, expectedfile.c_str(), ::strerror(ec)); throw std::runtime_error( errmsg); } // Scan source with char regex automaton for tokens: const strus::CharRegexMatchInstanceInterface* crinst = pii->getCharRegexMatchInstance(); std::auto_ptr<strus::CharRegexMatchContextInterface> crctx( crinst->createContext()); std::vector<strus::stream::PatternMatchToken> crmatches = crctx->match( inputsrc.c_str(), inputsrc.size()); if (crmatches.size() == 0 && g_errorBuffer->hasError()) { throw std::runtime_error( "failed to scan for tokens with char regex match automaton"); } std::ostringstream resultstrbuf; // Scan tokens with token pattern match automaton and print results: const strus::TokenPatternMatchInstanceInterface* ptinst = pii->getTokenPatternMatchInstance(); std::auto_ptr<strus::TokenPatternMatchContextInterface> ptctx( ptinst->createContext()); std::vector<strus::stream::PatternMatchToken>::const_iterator ci = crmatches.begin(), ce = crmatches.end(); for (; ci != ce; ++ci) { std::string tokstr( std::string( inputsrc.c_str() + ci->origpos(), ci->origsize())); resultstrbuf << "token " << pii->tokenName(ci->id()) << "(" << ci->id() << ") at " << ci->ordpos() << "[" << ci->origpos() << ":" << ci->origsize() << "] '" << tokstr << "'" << std::endl; ptctx->putInput( *ci); } std::vector<strus::stream::TokenPatternMatchResult> results = ptctx->fetchResults(); if (results.size() == 0 && g_errorBuffer->hasError()) { throw std::runtime_error( "failed to scan for patterns with token pattern match automaton"); } // Print results to buffer: strus::utils::printResults( resultstrbuf, results, inputsrc.c_str()); strus::stream::TokenPatternMatchStatistics stats = ptctx->getStatistics(); strus::utils::printStatistics( resultstrbuf, stats); // Print result to stdout and verify result by comparing it with the expected output: std::string resultstr = resultstrbuf.str(); std::cout << resultstr << std::endl; if (!diffContent( expectedsrc, resultstr)) { throw std::runtime_error( "output and expected result differ"); } if (g_errorBuffer->hasError()) { throw std::runtime_error( "uncaught error"); } std::cerr << "OK" << std::endl; delete g_errorBuffer; return 0; } catch (const std::runtime_error& err) { if (g_errorBuffer->hasError()) { std::cerr << "error processing pattern matching: " << g_errorBuffer->fetchError() << " (" << err.what() << ")" << std::endl; } else { std::cerr << "error processing pattern matching: " << err.what() << std::endl; } } catch (const std::bad_alloc&) { std::cerr << "out of memory processing pattern matching" << std::endl; } delete g_errorBuffer; return -1; }