示例#1
0
QueryResult TextQuery::query( const std::string& ac_sWord ) const {
  auto xCount = mc_Results.find( ac_sWord );
  if ( xCount != mc_Results.end() )
    return QueryResult(ac_sWord, mc_xLines, xCount->second);
  else
    return QueryResult(ac_sWord, mc_xLines, std::make_shared< std::set< mt_uLineNum > >() );
}
示例#2
0
文件: query.cpp 项目: multiphase/DSC
    QueryResult Query::raycast_faces(Ray ray, QueryType queryType) {
        if (!boundary_faces){
            rebuild_boundary_cache();
        }
        FaceKey firstIntersection((unsigned int) -1);
        double dist = std::numeric_limits<double>::max();

        for (auto faceIter : *boundary_faces){
            Face & face = mesh->get(faceIter);
            auto nodePos = mesh->get_pos(face.node_keys());
            double newDist;
            if (ray.intersect_triangle(nodePos[0], nodePos[1], nodePos[2], newDist)){
                bool isFirstFoundTriangle = dist == std::numeric_limits<double>::max();
                if (isFirstFoundTriangle){
                    firstIntersection = faceIter;
                    dist = newDist;
                } else {
                    if (newDist < dist){
                        firstIntersection = faceIter;
                        dist = newDist;
                    }
                    break;
                }
            }
        }
        if ((unsigned int)firstIntersection == (unsigned int)-1){
            return QueryResult();
        }

        return QueryResult(firstIntersection, dist, ray, queryType, mesh);
    }
QueryResult TextQuery::query(const std::string &sought) const {
	static std::shared_ptr<std::set<line_no>> nodata(new std::set<line_no>);
	auto loc = wm.find(sought);
	if (loc == wm.end())
		return QueryResult(sought, nodata, file);
	else
		return QueryResult(sought, loc->second, file);
}
示例#4
0
QueryResult TextQuery::query(const string& str) const 
{
    // use static just allocate once.
    static shared_ptr<std::set<StrBlob::size_type>> nodate(new std::set<StrBlob::size_type>);
    auto found = result.find(str);
    if (found == result.end()) return QueryResult(str, nodate, input);
    else return QueryResult(str, found->second, input);
}
示例#5
0
QueryResult TextQuery::query(const string &s) const
{
	static shared_ptr<set<string::size_type>> nodata(new set<string::size_type>);
	auto pos = wm.find(s);
	if(pos == wm.end())
		return QueryResult(s,nodata,file);
	else
		return QueryResult(s,pos->second,file);
}
示例#6
0
QueryResult TextQuery::query(std::string s)
{
    auto iter = wm.find(s);
    static std::shared_ptr<std::set<line_no>> nodata(new std::set<line_no>);
    if(iter != wm.end())
        return QueryResult(s, file, iter->second);
    else
        return QueryResult(s, file, nodata);
}
示例#7
0
const QueryResult
TextQuery::query(const string &word) const
{
	static shared_ptr<set<int>> nodata(new set<int>);
	auto loc = wm.find(word);
	if (loc != wm.end())
		return QueryResult(word, loc->second, file);
	else
		return QueryResult(word, nodata, file);
}
示例#8
0
QueryResult TextQuery::query(const std::string& word) const {
    static std::shared_ptr<std::set<line_no>> nodata(new std::set<line_no>);
    auto loc = lines_record.find(word);
    if (loc == lines_record.end()) {
        return QueryResult(word, nodata, text);
    } 
    else {
        return QueryResult(word, loc->second, text);
    }
}
QueryResult TextQuery::query(const std::string& sought) const
{
	// we'll return a pointer to this std::set if we don't find sought
	static std::shared_ptr<std::set<line_no>> nodata(new std::set<line_no>);
	//use find and not a subscript to avoid adding words to wm!
	auto loc = wm.find(sought);
	if(loc == wm.end())
		return QueryResult(sought, nodata, file); // not found
	else
		return QueryResult(sought, loc->second, file);
}
示例#10
0
QueryResult SQLQueryHolder::GetResult(size_t index) {
	// Don't call to this function if the index is of an ad-hoc statement
	if (index < m_queries.size()) {
		ResultSet* result = m_queries[index].second.qresult;
		if (!result || !result->GetRowCount())
			return QueryResult(NULL);

		result->NextRow();
		return QueryResult(result);
	} else
		return QueryResult(NULL);
}
示例#11
0
QueryResult TextQuery::query(const std::string &s) const
{
	std::shared_ptr<std::set<line_no>> nodata(new std::set<line_no>);
	auto it = word_map.find(s);
	if(it == word_map.end())
	{
		return QueryResult(s, nodata, file);
	}
	else
	{
		return QueryResult(s, it->second, file);
	}
}
示例#12
0
/**
 * @brief do a query opertion and return QueryResult object.
 */
QueryResult
TextQuery::query(const std::string &sought) const
{
    //! dynamicaly allocated set used for the word does not appear.
    static std::shared_ptr<std::set<index_Tp>> noData(new std::set<index_Tp>);

    //! fetch the iterator to the matching element in the map<word, lines>.
    //std::map<std::string, std::shared_ptr<std::set<index_Tp>>>::const_iterator
    auto iter = wm.find(sought);
    if(iter == wm.end())
        return QueryResult(sought, noData, file);
    else
        return QueryResult(sought, iter->second, file);
}
示例#13
0
        QueryResult query(const std::string &word) const
        {
            // *TN* How to handle the case when not found? Use empty set rather
            // then nullptr since print() do not have to handle a special case.
            static auto notfound = std::make_shared<std::set<lineno>>();

            // *TN* should not use [] since it can add a new one
            auto pos = word_map_.find(word);

            if (pos != word_map_.end())
                return QueryResult(word, input_file_, pos->second);
            else
                return QueryResult(word, input_file_, notfound);
        }
/**
 *
 * Connects to the database
 *
 * Note that this expects that the database driver has setup all the things in
 * the connection.
 *
 * @return A QueryResult. error.isError will be false on success.
 */
QueryResult DatabaseConnection::connect()
{
    QueryResult result;

    if (driver == nullptr) {

        // Get driver instance
        driver = get_driver_instance();

        // Init SQL thread
        driver->threadInit();
    }

    if (connection == nullptr) {

        try {

            connection = driver->connect(hostname, username,
                                                        password);
        } catch (SQLException &e) {

            result.error.isError = true;
            result.error.code = e.getErrorCode();
            result.error.string = e.getSQLState() + ": " + e.what();

            return result;
        }

        // Reset result
        result = QueryResult();

        // Get connection id
        result = this->execute(VariantVector() << "SELECT CONNECTION_ID()");
        if (result.rows.size() == 0 || result.error.isError) {

            // No row returned
            return result;
        }
        connection_id = result.rows.front().front().toUInt();

        // Reset result
        result = QueryResult();

        return result;
    }

    // Successful connection?
    return result;
}
示例#15
0
QueryResult DatabaseWorkerPool<T>::Query(const char* sql, T* connection /*= nullptr*/)
{
	if (!connection)
		connection = GetFreeConnection();

	ResultSet* result = connection->Query(sql);
	connection->Unlock();
	if (!result || !result->GetRowCount() || !result->NextRow())
	{
		delete result;
		return QueryResult(NULL);
	}

	return QueryResult(result);
}
int
Dictionary::dict_find (ustring dictionaryname, ustring query)
{
    int dindex = get_document_index (dictionaryname);
    if (dindex < 0)
        return dindex;
    ASSERT (dindex >= 0 && dindex < (int)m_documents.size());

    Query q (dindex, 0, query);
    QueryMap::iterator qfound = m_cache.find (q);
    if (qfound != m_cache.end()) {
        return qfound->second.valueoffset;
    }

    pugi::xml_document *doc = m_documents[dindex];

    // Query was not found.  Do the expensive lookup and cache it
    pugi::xpath_node_set matches;

    try {
        matches = doc->select_nodes (query.c_str());
    }
    catch (const pugi::xpath_exception& e) {
        m_context->error ("Invalid dict_find query '%s': %s",
                          query.c_str(), e.what());
        return 0;
    }

    if (matches.empty()) {
        m_cache[q] = QueryResult (false);  // mark invalid
        return 0;   // Not found
    }
    int firstmatch = (int) m_nodes.size();
    int last = -1;
    for (int i = 0, e = (int)matches.size(); i < e;  ++i) {
        m_nodes.push_back (Node (dindex, matches[i].node()));
        int nodeid = (int) m_nodes.size()-1;
        if (last < 0) {
            // If this is the first match, add a cache entry for it
            m_cache[q] = QueryResult (true /* it's a node */, nodeid);
        } else {
            // If this is a subsequent match, set the last match's 'next'
            m_nodes[last].next = nodeid;
        }
        last = nodeid;
    }
    return firstmatch;
}
示例#17
0
QueryResult AndQuery::eval(const TextQuery& text) const
{
	auto left=lhs.eval(text), right=rhs.eval(text);
	auto ret_lines=std::make_shared<std::set<line_no>>();
	set_intersection(left.begin(),left.end(),right.begin(),right.end(),inserter(*ret_lines,ret_lines->begin()));
	return QueryResult(rep(),ret_lines,left.get_file());
}
示例#18
0
// returns the lines not in its operand's result set
QueryResult
NotQuery::eval(const TextQuery& text) const
{
    // virtual call to eval through the Query operand
    auto result = query.eval(text);

    // start out with an empty result set
    auto ret_lines = std::make_shared<std::set<line_no>>();

    // we have to iterate through the lines on which our operand appears
    auto beg = result.begin(), end = result.end();

    // for each line in the input file, if that line is not in result,
    // add that line number to ret_lines
    auto sz = result.get_file()->size();

    for (size_t n = 0; n != sz; ++n) {
    // if we haven't processed all the lines in result
    // check whether this line is present
        if (beg == end || *beg != n)
            ret_lines->insert(n); // if not in result, add this line
        else if (beg != end)
            ++beg; // otherwise get next line number in result if there is one
    }

    return QueryResult(rep(), ret_lines, result.get_file());
}
示例#19
0
bool BasicStatementTask::Execute()
{
    if(m_has_result)
    {
        ResultSet* result = m_conn->Query(m_sql);
        if(!result || !result->GetRowCount())
        {
            m_result.set(QueryResult(NULL));
            return false;
        }
        result->NextRow();
        m_result.set(QueryResult(result));
        return true;
    }

    return m_conn->Execute(m_sql);
}
示例#20
0
bool BasicStatementTask::Execute()
{
    if (m_has_result)
    {
        ResultSet* result = m_conn->Query(m_sql);
        if (!result || !result->GetRowCount() || !result->NextRow())
        {
            delete result;
            m_result->set_value(QueryResult(nullptr));
            return false;
        }

        m_result->set_value(QueryResult(result));
        return true;
    }

    return m_conn->Execute(m_sql);
}
// ----------------------------------------------------------------------------
// CNATFWUNSAFQuerySrv::HandleQueryResultL
// ----------------------------------------------------------------------------
//
void CNATFWUNSAFQuerySrv::HandleQueryResultL(
    MNATFWUNSAFHostResolver& aResolver )
    {
    if ( QueryResult().Target().CompareF( KDot8 ) != KErrNone )
        {
        AddL( QueryResult() );
        }

    while ( aResolver.Resolver().QueryGetNext( QueryResultBuf() )
                                                == KErrNone )
        {
        if ( QueryResult().Target().CompareF( KDot8 ) != KErrNone )
            {
            //Records are sorted in right order in inserting phase
            AddL( QueryResult() );
            }
        }
    }
示例#22
0
// Deer Action.
QueryResult DeerAction::query() {
	cout << " >> [~ Deer Action ~]: Enter the name of the player you wish to exchange your secret animal with." << endl;
	cout << " >> Name: ";
	string playerName = "";
	getline(cin, playerName);
	QueryResult qr = QueryResult();
	qr.append(playerName);
	return qr;
}
int
Dictionary::dict_find (int nodeID, ustring query)
{
    if (nodeID <= 0 || nodeID >= (int)m_nodes.size())
        return 0;     // invalid node ID

    const Dictionary::Node &node (m_nodes[nodeID]);
    Query q (node.document, nodeID, query);
    QueryMap::iterator qfound = m_cache.find (q);
    if (qfound != m_cache.end()) {
        return qfound->second.valueoffset;
    }

    // Query was not found.  Do the expensive lookup and cache it
    pugi::xpath_node_set matches;
    try {
        matches = node.node.select_nodes (query.c_str());
    }
    catch (const pugi::xpath_exception& e) {
        m_context->error ("Invalid dict_find query '%s': %s",
                          query.c_str(), e.what());
        return 0;
    }

    if (matches.empty()) {
        m_cache[q] = QueryResult (false);  // mark invalid
        return 0;   // Not found
    }
    int firstmatch = (int) m_nodes.size();
    int last = -1;
    for (int i = 0, e = (int)matches.size(); i < e;  ++i) {
        m_nodes.push_back (Node (node.document, matches[i].node()));
        int nodeid = (int) m_nodes.size()-1;
        if (last < 0) {
            // If this is the first match, add a cache entry for it
            m_cache[q] = QueryResult (true /* it's a node */, nodeid);
        } else {
            // If this is a subsequent match, set the last match's 'next'
            m_nodes[last].next = nodeid;
        }
        last = nodeid;
    }
    return firstmatch;
}
示例#24
0
QueryResult OrQuery::eval(const TextQuery & tq) const
{
	QueryResult left_result = lhs.eval(tq);
	QueryResult right_result = rhs.eval(tq);
	shared_ptr<set<size_t>> ret_lines = make_shared<set<size_t>>(left_result.begin(),left_result.end());
	ret_lines->insert(right_result.begin(), right_result.end());

	return QueryResult(BinaryQuery::rep(), ret_lines, left_result.get_file());

}
示例#25
0
QueryResult OrQuery::eval(const TextQuery &t) const {
    
    auto left = lhs.eval(t);
    auto right = rhs.eval(t);

    auto ret_lines = std::make_shared<set<line_no>>(left.begin(), left.end());

    ret_lines->insert(right.begin(), right.end());

    return QueryResult(rep(), ret_lines, left.get_file());
}
示例#26
0
// returns the intersection of its operands' result sets
QueryResult AndQuery::eval(const TextQuery &text) const
{
	// virtual calls through the Query operands to get result sets for the operands
	auto left = lhs.eval(text), right = rhs.eval(text);
	// set to hold the intersection of left and right
	auto ret_lines = std::make_shared<std::set<line_no>>();
	// writes the intersection of two ranges to a destination iterator
	// destination iterator in this call adds elements to ret_lines
	std::set_intersection(left.begin(), left.end(), right.begin(), right.end(),
	                      std::inserter(*ret_lines, ret_lines->begin()));
	return QueryResult(rep(), ret_lines, left.get_file());
}
// returns the union of its operands' result sets
QueryResult OrQuery::eval(const TextQuery &text) const
{
	// virtual calls through Query members, lhs and rhs
	// the calls to eval return the QueryResult for each operand
	auto left = lhs.eval(text), right = rhs.eval(text);
	// copy the line numbers from the left-hand operand into the result set
	auto ret_lines = std::make_shared<std::set<line_no>>(left.begin(), left.end());
	// insert lines from the right-hand operand
	ret_lines->insert(right.begin(), right.end());
	// returns the new QueryResult representing the union of lhs and rhs
	return QueryResult(rep(), ret_lines, left.get_file());
}
示例#28
0
QueryResult OrQuery::eval(const TextQuery &text) const
{
    QueryResult right = rhs.eval(text), left= lhs.eval(text);

    //! copy the left-hand operand into the result set
    std::shared_ptr<std::set<line_no>> ret_lines =
            std::make_shared<std::set<line_no>>(left.begin(), left.end());

    //! inert lines from the right-hand operand
    ret_lines->insert(right.begin(), right.end());

    return QueryResult(rep(),ret_lines,left.get_file());
}
示例#29
0
// Hare Action.
QueryResult HareAction::query() {
	QueryResult qr = QueryResult();
	cout << " >> [~ Hare Action ~]: Enter the coordinates 'x0,y0,x1,y1' of which card you want to move and where." << endl;
	cout << " >> Enter 'x0': ";
	string coordinate;
	getline(cin, coordinate);
	qr.append(coordinate);
	cout << " >> Enter 'y0': ";
	getline(cin, coordinate);
	qr.append(coordinate);
	cout << " >> Enter 'x1': ";
	getline(cin, coordinate);
	qr.append(coordinate);
	cout << " >> Enter 'y1': ";
	getline(cin, coordinate);
	qr.append(coordinate);
	return qr;
}
示例#30
0
QueryResult NotQuery::eval(const TextQuery& t) const {

    auto result = query.eval(t);
    // an empty set to store results
    auto ret_lines = std::make_shared<set<line_no>>();
    // get the iterator 
    auto beg = result.begin(), end = result.end();

    auto sz = result.get_file()->size();
    for(size_t n = 0; n != sz; ++n) {
        
        if(*beg != n || beg == end) 
            ret_lines->insert(n);
        else if(beg != end)
            ++beg;
    }

    return QueryResult(rep(), ret_lines, result.get_file());
}