Пример #1
0
 void visitData( const IData& d ) override
 {
   SpatialIndex::IShape* shape;
   d.getShape( &shape );
   mNewIndex->insertData( 0, 0, *shape, d.getIdentifier() );
   delete shape;
 }
Пример #2
0
	virtual void visitData(const IData& in) 
	{
		uint64_t id = in.getIdentifier();

		const bool doDataDeserialization = true;
		if(doDataDeserialization)
		{
			uint32_t dataLen;
			byte* data;
			in.getData(dataLen, &data);

			MGArchive archive((const char*)data, dataLen);
			Way way;
			archive << way;

			for (size_t i = 0; i < way.tags.size(); i++)
			{
				if (way.tags[i].key == key)
				{
					ways.push_back(id);
					break;
				}
			}

			delete data;
		}
	}
Пример #3
0
void VisitadorGP::visitData(const IData& d) {
	IShape* pS;
	d.getShape(&pS);
	// do something.
	Region r;
	pS->getMBR(r);

//	cout << "punto " << contador++ << ": " << r.m_pHigh[0] << " - " << r.m_pHigh[1] << endl;
	//cout << r.m_pHigh[0] << " " << r.m_pHigh[1] << endl;
	xy_pts_B.push_back(std::make_pair(r.m_pHigh[0], r.m_pHigh[1]));
	contador++;
	//cout<< "contador " << contador << endl;
	delete pS;

	// data should be an array of characters representing a Region as a string.
	byte* pData = 0;
	uint32_t cLen = 0;
	d.getData(cLen, &pData);
	// do something.
	//string s = reinterpret_cast<char*>(pData);
	//cout << s << endl;
	delete[] pData;

	//cout << d.getIdentifier() << endl;
	// the ID of this data entry is an answer to the query. I will just print it to stdout.
}
Пример #4
0
/** 
  * DbManager::addDataNode
  *
  * Adds the DataNode to the Entity table.
  *
  * @param parentKey The pkey of the parent.
  * @return unsigned int The pkey of the datanode.
  */
unsigned int DbManager::addDataNode( std::string name, unsigned int agentKey )
{
    unsigned int dataNodeType = getEntityTypeKey( "DataNode" );
    unsigned int dataNodeKey = 0;

    IData* id = NULL;
    std::vector<std::string> columns;
    columns.push_back( "pkey" );

    // See if the agent already exists.
    id = m_db.executeQuery( "SELECT pkey FROM entity WHERE name = '"+name+"'", columns );

    // Add the agent if it doesn't.
    if ( id->getNumRows() == 0 )
    {
        delete id;
        id = NULL;

        std::ostringstream query;
        query << "INSERT INTO entity ";
        query << "(pkey,name,address,description,subsystemkey,locationkey,typekey,";
        query << "agentkey,parentkey) VALUES (ENTITY_SEQ.NEXTVAL,'";
        query << name;
        query << "','Test DataNode','Test DataNode',6,1,";
        query << dataNodeType;
        query << ",";
        query << agentKey;
        query << ",";
        query << agentKey;
        query << ")";
        m_db.executeModification( query.str() );

        // Get the DataNode's pkey.
        id = m_db.executeQuery( "SELECT pkey FROM entity WHERE name = '"+name+"'", columns );
        dataNodeKey = id->getUnsignedLongData( 0, "pkey" );

        delete id;
        id = NULL;
    }
    else
    {
        // If the DataNode exists, make sure no parameters are set.
        dataNodeKey = id->getUnsignedLongData( 0, "pkey" );

        delete id;
        id = NULL;

        // Make sure the DataNode has no parameters.
        removeParameters( dataNodeKey );
    }
    
    return dataNodeKey;
}
Пример #5
0
 void visitData( const IData& d ) override
 {
   QgsFeatureId id = d.getIdentifier();
   QgsGeometry* g = mLocator->mGeoms.value( id );
   if ( g->intersects( mGeomPt ) )
     mList << QgsPointLocator::Match( QgsPointLocator::Area, mLocator->mLayer, id, 0, QgsPoint() );
 }
Пример #6
0
/** 
  * DbManager::getEntityParameterKey
  *
  * Determines the pkey for EntityParameter 'name' associated with 'type'.
  *
  * @param name The name to find.
  * @param type The type of the parameter.
  *
  * @return unsigned int The pkey.
  *
  */
unsigned int DbManager::getEntityParameterKey( std::string name, unsigned int type )
{
    // Search the type key map for the provided type name.
    ParameterMap::iterator it = m_parameterKeys.find( StringUintPair(name,type) );
    if ( it != m_parameterKeys.end() )
    {
	    return it->second;
    }

    // If the key wasn't found retrieve it from the database.
    
    unsigned int pkey = 0;

    IData* id = NULL;
    std::vector<std::string> columns;
    columns.push_back( "pkey" );

    std::ostringstream query;
    query << "SELECT pkey FROM entityparameter WHERE name = '";
    query << name;
    query << "' AND typekey = ";
    query << type;
    id = m_db.executeQuery( query.str(), columns );

    if ( id->getNumRows() == 1 )
    {
        pkey = id->getUnsignedLongData( 0, "pkey" );

        delete id;
        id = NULL;
    }
    else
    {
        delete id;
        id = NULL;

        std::string message = "Couldnt find unique EntityParameter "+name;
        throw DatabaseException( message.c_str(), DatabaseException::REQUEST_FAILED );
    }

    // Insert the parameter into the map.
    m_parameterKeys.insert( std::pair<StringUintPair,unsigned int>( StringUintPair(name,type), pkey ) );

    return pkey;
}
Пример #7
0
	bool Manager::VTrigger ( IData const & inEvent ) const
	{
		if ( ! VValidateType( inEvent.GetTypeId() ) )
			return false;

		EventListenerMap::const_iterator itWC = m_registry.find( 0 );

		if ( itWC != m_registry.end() )
		{
			EventListenerTable const & table = itWC->second;

			bool processed = false;
	
			for ( EventListenerTable::const_iterator it2 = table.begin(), it2End = table.end();
					it2 != it2End;
						it2++ )
			{
				(*it2)->HandleEvent( inEvent );
			}
		}
	
		EventListenerMap::const_iterator it = m_registry.find( inEvent.GetTypeId().Value() );

		if ( it == m_registry.end() )
			return false;

		EventListenerTable const & table = it->second;

		bool processed = false;
	
		for ( EventListenerTable::const_iterator it2 = table.begin(), it2End = table.end();
				it2 != it2End;
					it2++ )
		{
			ListenerPtr listener = *it2;
			if ( listener->HandleEvent( inEvent ) )
			{
				processed = true;
			}
		}
		return processed;
	}
Пример #8
0
/** 
  * DbManager::addTestAgent
  *
  * Adds the test agent to the Entity table.
  *
  * @return unsigned int The pkey of the test agent.
  */
unsigned int DbManager::addTestAgent( unsigned int scadaRootType )
{
    unsigned int agentKey = 0;

    // Get the SCADAROOT type.
    IData* id = NULL;
    std::vector<std::string> columns;
    columns.push_back( "pkey" );

    // See if the agent already exists.
    id = m_db.executeQuery( "SELECT pkey FROM entity WHERE name = '"+AgentName+"'", columns );

    // Add the agent if it doesn't.
    if ( id->getNumRows() == 0 )
    {
        delete id;
        id = NULL;

        std::ostringstream query;
        query << "INSERT INTO entity ";
        query << "(pkey,name,address,description,subsystemkey,locationkey,typekey,";
        query << "agentkey,parentkey) VALUES (ENTITY_SEQ.NEXTVAL,'";
        query << AgentName;
        query << "','VIRTUAL','Test Agent',6,1,";
        query << scadaRootType;
        query << ",ENTITY_SEQ.NEXTVAL,0)";
        m_db.executeModification( query.str() );

        // Get the pkey of the agent.
        id = m_db.executeQuery( "SELECT pkey FROM entity WHERE name = '"+AgentName+"'", columns );
    }

    agentKey = id->getUnsignedLongData( 0, "pkey" );

    delete id;
    id = NULL;
   
    return agentKey;
}
Пример #9
0
/** 
  * DbManager::getEntityTypeKey
  *
  * Determines the pkey for EntityType 'name'.
  *
  * @param name The name to find.
  *
  * @return unsigned int The pkey.
  *
  */
unsigned int DbManager::getEntityTypeKey( std::string name )
{
    // Search the type key map for the provided type name.
    KeyMap::iterator it = m_typeKeys.find( name );
    if ( it != m_typeKeys.end() )
    {
	    return it->second;
    }

    // If the key wasn't found retrieve it from the database.
    unsigned int pkey = 0;

    IData* id = NULL;
    std::vector<std::string> columns;
    columns.push_back( "pkey" );
    id = m_db.executeQuery( "SELECT pkey FROM entitytype WHERE name = '"+name+"'", columns );

    if ( id->getNumRows() == 1 )
    {
        pkey = id->getUnsignedLongData( 0, "pkey" );

        delete id;
        id = NULL;
    }
    else
    {
        delete id;
        id = NULL;

        std::string message = "Couldnt find EntityType "+name;
        throw DatabaseException( message.c_str(), DatabaseException::REQUEST_FAILED );
    }

    // Insert the type into the map.
    m_typeKeys.insert( std::pair<std::string,unsigned int>( name, pkey ) );

    return pkey;
}
Пример #10
0
    void visitData( const IData& d ) override
    {
      QgsFeatureId id = d.getIdentifier();
      QgsGeometry* geom = mLocator->mGeoms.value( id );

      Q_FOREACH ( const QgsPointLocator::Match& m, _geometrySegmentsInRect( geom, mSrcRect, mLocator->mLayer, id ) )
      {
        // in range queries the filter may reject some matches
        if ( mFilter && !mFilter->acceptMatch( m ) )
          continue;

        mList << m;
      }
    }
Пример #11
0
    void visitData( const IData& d ) override
    {
      QgsFeatureId id = d.getIdentifier();
      QgsGeometry* geom = mLocator->mGeoms.value( id );
      int vertexIndex, beforeVertex, afterVertex;
      double sqrDist;
      QgsPoint pt = geom->closestVertex( mSrcPoint, vertexIndex, beforeVertex, afterVertex, sqrDist );

      QgsPointLocator::Match m( QgsPointLocator::Vertex, mLocator->mLayer, id, sqrt( sqrDist ), pt, vertexIndex );
      // in range queries the filter may reject some matches
      if ( mFilter && !mFilter->acceptMatch( m ) )
        return;

      if ( !mBest.isValid() || m.distance() < mBest.distance() )
        mBest = m;
    }
Пример #12
0
    void visitData( const IData& d ) override
    {
      QgsFeatureId id = d.getIdentifier();
      QgsGeometry* geom = mLocator->mGeoms.value( id );
      QgsPoint pt;
      int afterVertex;
      double sqrDist = geom->closestSegmentWithContext( mSrcPoint, pt, afterVertex, nullptr, POINT_LOC_EPSILON );
      if ( sqrDist < 0 )
        return;

      QgsPoint edgePoints[2];
      edgePoints[0] = geom->vertexAt( afterVertex - 1 );
      edgePoints[1] = geom->vertexAt( afterVertex );
      QgsPointLocator::Match m( QgsPointLocator::Edge, mLocator->mLayer, id, sqrt( sqrDist ), pt, afterVertex - 1, edgePoints );
      // in range queries the filter may reject some matches
      if ( mFilter && !mFilter->acceptMatch( m ) )
        return;

      if ( !mBest.isValid() || m.distance() < mBest.distance() )
        mBest = m;
    }
Пример #13
0
/**
  * DbManager::addSafetyOutputInfo
  *
  * Adds the correct information to the SafetyOutputDataPoint.
  *
  * @param entityKey The entity key to add the information to.
  */
void DbManager::addSafetyOutputInfo( unsigned int safetyKey, unsigned int output0Key, unsigned int output1Key )
{
    unsigned int state0Key = 0;
    unsigned int state1Key = 0;
    IData* id = NULL;
    std::vector<std::string> columns;
    columns.push_back( "scdsta_id" );

    std::ostringstream query;

    // Add the states.
    query.str("");
    query << "INSERT INTO sc_derived_state ( scdsta_id,derived_dp_pkey,state_value,";
    query << "state_description,alarm_enabled,alarm_delay,alarm_message,";
    query << "alarm_severity ) VALUES ( SCADA_SEQ.NEXTVAL,";
    query << safetyKey;
    query << ",0,'State 0',0,0,'State 0 Alarm',0 )";
    m_db.executeModification( query.str() );

    query.str("");
    query << "INSERT INTO sc_derived_state ( scdsta_id,derived_dp_pkey,state_value,";
    query << "state_description,alarm_enabled,alarm_delay,alarm_message,";
    query << "alarm_severity ) VALUES ( SCADA_SEQ.NEXTVAL,";
    query << safetyKey;
    query << ",1,'State 1',0,0,'State 1 Alarm',0 )";
    m_db.executeModification( query.str() );

    // Get the keys.
    query.str("");
    query << "SELECT scdsta_id FROM sc_derived_state WHERE derived_dp_pkey = ";
    query << safetyKey;
    query << " ORDER BY scdsta_id";
    id = m_db.executeQuery( query.str(), columns );
    if ( id->getNumRows() != 2 )
    {
        delete id;
        id = NULL;
        throw DatabaseException( "Couldn't find both safety output states!", DatabaseException::REQUEST_FAILED );
    }
    state0Key = id->getUnsignedLongData( 0, "scdsta_id" );
    state1Key = id->getUnsignedLongData( 1, "scdsta_id" );
    delete id;
    id = NULL;

    // Add the output associations.
    query.str("");
    query << "INSERT INTO sc_derived_output_association ( scdoas_id,scdsta_id,";
    query << "output_dp_pkey,output_value ) VALUES ( SCADA_SEQ.NEXTVAL,";
    query << state0Key;
    query << ",";
    query << output0Key;
    query << ",1 )";
    m_db.executeModification( query.str() );

    query.str("");
    query << "INSERT INTO sc_derived_output_association ( scdoas_id,scdsta_id,";
    query << "output_dp_pkey,output_value ) VALUES ( SCADA_SEQ.NEXTVAL,";
    query << state0Key;
    query << ",";
    query << output1Key;
    query << ",0 )";
    m_db.executeModification( query.str() );

    query.str("");
    query << "INSERT INTO sc_derived_output_association ( scdoas_id,scdsta_id,";
    query << "output_dp_pkey,output_value ) VALUES ( SCADA_SEQ.NEXTVAL,";
    query << state1Key;
    query << ",";
    query << output0Key;
    query << ",0 )";
    m_db.executeModification( query.str() );

    query.str("");
    query << "INSERT INTO sc_derived_output_association ( scdoas_id,scdsta_id,";
    query << "output_dp_pkey,output_value ) VALUES ( SCADA_SEQ.NEXTVAL,";
    query << state1Key;
    query << ",";
    query << output1Key;
    query << ",1 )";
    m_db.executeModification( query.str() );
}
Пример #14
0
 void visitData( const IData& d ) override
 {
   mList.append( d.getIdentifier() );
 }
Пример #15
0
	void visitData(const IData& d)
	{
	    hits.push_back(d.getIdentifier());
	    //std::cout << d.getIdentifier()<< std::endl;
	}