Ejemplo n.º 1
0
//gets the topological relationship between this GeoObject and another
int ccGeoObject::getRelationTo(ccGeoObject* obj, ccTopologyRelation** out)
{
	ccTopologyRelation* r = getRelation(this, getUniqueID(), obj->getUniqueID()); //search for a relation belonging to us
	bool invert = false;
	if (!r) //not found - search for a relation belonging to obj
	{
		r = getRelation(obj, getUniqueID(), obj->getUniqueID());
		invert = true; //we need to invert backwards relationships (i.e. Obj OLDER THAN this, so this YOUNGER THAN Obj)
	}

	if (r) //a relation was found
	{
		*out = r; //set out pointer

		if (!invert)
		{
			return r->getType();
		}
		else
		{   //we need to invert backwards relationships (i.e. Obj OLDER THAN this, so this YOUNGER THAN Obj)
			return ccTopologyRelation::invertType(r->getType());
		}
	}
	else
	{
		*out = nullptr;
		return ccTopologyRelation::UNKNOWN;
	}
}
Ejemplo n.º 2
0
QmvSqlQuery::QmvSqlQuery( QmvClass * cls, const QString name )
        : QObject ( cls, name)
{
    setRelation( cls );
        // defaults
    setOffset( getRelation()->queryOffset().toInt() );
    setLimit( getRelation()->queryLimit().toInt() );
    setOrderby( getRelation()->orderBy() );
    controller = 0;
    
        // get a list of attribute titles and index them
    QmvAttList atlist = getRelation()->sortedAttlist( "mtat_view_order",
                                                      QmvClass::NoBlank|QmvClass::NoSystem );

    for ( QmvAttribute * at_ptr = atlist.first(); at_ptr != 0; at_ptr = atlist.next())
    {

#ifdef QMVSQLQUERY_DEBUG
        qDebug("printReport:%s, mtat_title = %s",
               at_ptr->find("mtat_name")->latin1(),
               at_ptr->find("mtat_title")->latin1());
#endif
        
            // load the label
        QString *title = at_ptr->find( "mtat_title");
        if ( !title )
            continue;
        
        attribute_titles += *title;
            // index a pointer to the QmvAttribute object
        attribute_index.insert( *title , at_ptr );
    }
}
Ejemplo n.º 3
0
//recurse down the tree looking for the specified topology relationship
ccTopologyRelation* ccGeoObject::getRelation(ccHObject* obj, int id1, int id2)
{
	//is this object the relation we are looking for?
	if (ccTopologyRelation::isTopologyRelation(obj))
	{
		ccTopologyRelation* r = dynamic_cast<ccTopologyRelation*> (obj);
		if (r)
		{
			if ( (r->getOlderID() == id1 && r->getYoungerID() == id2) || 
				 (r->getOlderID() == id2 && r->getYoungerID() == id1) )
			{
				return r; //already has relationship between these objects
			}
		}
	}

	//search children
	for (unsigned i = 0; i < obj->getChildrenNumber(); i++)
	{
		ccTopologyRelation* r = getRelation(obj->getChild(i), id1, id2);
		if (r)
		{
			return r; //cascade positive respones up
		}
	}

	return nullptr; //nothing found
}
Ejemplo n.º 4
0
//--------------------------------------------------------------------------------
//--------------------------------------------------------------------------------
void QmvSqlQuery::setOrderby( const QString & new_orderby )
{
    if ( new_orderby.isNull() || !new_orderby.length() )
        query_orderby = getRelation()->orderBy();
    else
        query_orderby = new_orderby;

    query_orderby.replace( QRegExp( "order +by" ), "" );
}
Ejemplo n.º 5
0
//--------------------------------------------------------------------------------
bool QmvSqlQuery::updateRelationSet()
{
    int status = getRelation()->open( sqlQuery(), controller );
    if ( controller )
        controller->reset();
    
    if ( status < 0 )
    {
        query_errormessage = getRelation()->lastError();
        query_status = false;
    } else {
        query_errormessage = "";
        query_status = true;
        emit relationChanged( getRelation() );
    }
    
    emit queryStatus( status, getRelation() );        
    return query_status;
}
Ejemplo n.º 6
0
  virtual void updateRelation(float income, CityPtr city)
  {
    RomeDivinityBase::updateRelation( income, city );

    if( getRelation() < 1 && _lastActionDate.getMonthToDate( GameDate::current() ) > 10 )
    {
      _lastActionDate = GameDate::current();
      ShowInfoboxEvent::create( _("##wrath_of_ceres_title##"), _("##wrath_of_ceres_description##") );

      CityHelper helper( city );
      FarmList farms = helper.getBuildings<Farm>( B_MAX );
      foreach( FarmPtr farm, farms )
      {
        farm->updateProgress( -farm->getProgress() );
      }
Ejemplo n.º 7
0
bool PlayerRelationsManager::checkBadRelation(const std::string &name) const
{
    if (name.empty())
        return true;

    const RelationT relation = getRelation(name);

    if (relation == Relation::IGNORED
        || relation == Relation::DISREGARDED
        || relation == Relation::BLACKLISTED
        || relation == Relation::ERASED
        || relation == Relation::ENEMY2)
    {
        return true;
    }
    return false;
}
Ejemplo n.º 8
0
void PlayerRelationsManager::ignoreTrade(const std::string &name) const
{
    if (name.empty())
        return;

    const RelationT relation = getRelation(name);

    if (relation == Relation::IGNORED
        || relation == Relation::DISREGARDED
        || relation == Relation::BLACKLISTED
        || relation == Relation::ERASED)
    {
        return;
    }
    else
    {
        player_relations.setRelation(name, Relation::BLACKLISTED);
    }
}
Ejemplo n.º 9
0
int State::update(trackingC *obj1, trackingC *obj2)
{
	if (marked && obj1 !=  NULL && obj2 !=  NULL) 
	{
		t_object1 = obj1;
		t_object2 = obj2;
		getRelation();
	}
	else if(!marked && timeWindow.size() > 0)
	{
		timeWindow.pop_front();
	}
	
	strength = 0;
	for (unsigned int count = 0; count < timeWindow.size(); count++) {
		strength += timeWindow[count];
	}
	
	return relation;
}
Ejemplo n.º 10
0
inline void Map3::update_topo_shortcuts()
{
	Map2::update_topo_shortcuts();
	m_phi3 = getRelation("phi3");
}
Ejemplo n.º 11
0
inline void GMap0::update_topo_shortcuts()
{
	GenericMap::update_topo_shortcuts();
	m_beta0 = getRelation("beta0");
}
Ejemplo n.º 12
0
inline void GMap2::update_topo_shortcuts()
{
	GMap1::update_topo_shortcuts();
	m_beta2 = getRelation("beta2");
}
Ejemplo n.º 13
0
int UT_destroy( int argc, char* argv[] )
{
    int recId, attrcnt, indexcnt, return_val;
    char * relName, * record;
    relDesc * relPtr;

    if ( argc != 2 ) {
        printf( "Error: Two arguments expected for function UT_destroy\n" );
        return AMINIREL_GE;
    }

    return_val = AMINIREL_OK;

    inline cleanup() {
        if ( record != NULL ) {
            free( record );
        }

        if ( attrcnt > 0 ) {
            printf( "Error: De diagraftikan ola ta records twn attributes ths sxeshs '%s'\n", relName );
            return_val = AMINIREL_GE;
        }

        if ( indexcnt > 0 ) {
            printf( "Error: De diagraftikan ola ta indeces twn attributes ths sxeshs '%s'\n", relName );
            return_val = AMINIREL_GE;
        }

        if ( relName != NULL ) {
            if ( HF_DestroyFile( relName ) != HFE_OK ) {
                HF_PrintError( "Could not destroy relation in UT_destroy() " );
                return_val =  AMINIREL_GE;
            }
        }
    }

    /* Arxikopoihseis */
    relName = argv[1];
    record = NULL;

    /* Kanoume retrieve tis plhrofories gia thn relation */
    if (( relPtr = getRelation( relName, &recId ) ) == NULL ) {
        printf( "Error: Cannot destroy relation '%s'. Could not retrieve information about relation.\n", argv[1] );
        return_val = AMINIREL_GE;
        cleanup();
        return return_val;
    }

    /* an th vrhkame, swzoume posa attributes kai indeces exei, kai th diagrafoume */
    attrcnt = relPtr->attrcnt;
    indexcnt = relPtr->indexcnt;
    free( relPtr );

    /* Diagrafoume thn eggrafh sto relCat */
    if ( HF_DeleteRec( this_db.relCatDesc, recId, sizeof( relDesc ) ) != HFE_OK ) {
        HF_PrintError( "Error in UT Destroy: Could not delete record from relCat\n" );
        return_val = AMINIREL_GE;
        cleanup();
        return return_val;
    }


    /* An th vrhkame sto relCat arxeio, anoigoume to attrCat arxeio gia na diagrapsoume ola ta records gia ta
       attrcnt synolika attributes ths */


    /* sto record tha apothikeyetai h eggrafh tou arxeiou attrCat */
    if (( record = malloc( sizeof( attrDesc ) ) ) == NULL ) {
        printf( MEM_ERROR );
        return_val = AMINIREL_GE;
        cleanup();
        return return_val;
    }

    /* Ksekiname to psaksimo apo thn arxh tou arxeiou */
    if (( recId = HF_GetFirstRec( this_db.attrCatDesc, record, sizeof( attrDesc ) ) ) < 0 ) {
        HF_PrintError( "Could not retrieve first Record from file relCat" );
        return_val = AMINIREL_GE;
        cleanup();
        return return_val;
    }

    do {
        /* To onoma ths sxeshs einai sthn arxh tou record */
        if ( !strcmp( record, relName ) ) {
            char * pch;
            int indexed;

            /* to pch twra deixnei sto 'indexed' melos tou struct attrDesc */
            pch = record + 2 * MAXNAME * sizeof( char ) + 2 * sizeof( int ) + sizeof( char );
            memcpy( &indexed, pch, sizeof( int ) );

            /* An exei eurethrio, prepei na diagrafei kai auto */
            if ( indexed == TRUE ) {
                int indexno;

                /* to pch twra deixnei sto indexno melos tou struct attrDesc */
                pch += sizeof( int );
                memcpy( &indexno, pch, sizeof( int ) );

                /* diagrafoume to eurethrio */
                if ( AM_DestroyIndex( relName, indexno ) != AME_OK ) {
                    AM_PrintError( "Could not delete index: " );
                    return_val = AMINIREL_GE;
                    cleanup();
                    return return_val;
                }

                indexcnt--;
            }

            /* diagrafoume thn eggrafh tou attribute sto attrCat */
            if ( HF_DeleteRec( this_db.attrCatDesc, recId, sizeof( attrDesc ) ) != HFE_OK ) {
                return_val = AMINIREL_GE;
                cleanup();
                return return_val;
            }

            attrcnt--;
        }

    }
    while (( recId = HF_GetNextRec( this_db.attrCatDesc, recId, record  , sizeof( attrDesc ) ) ) >= 0 );

    if ( recId != HFE_EOF ) {
        HF_PrintError( "Error in UT Destroy while deleting records from file attrCat\n" );
        return_val = AMINIREL_GE;
        cleanup();
        return return_val;
    }


    cleanup();
    return return_val;
}
Ejemplo n.º 14
0
int UT_buildindex( int argc, char* argv[] )
{
    relDesc * relInfo;
    attrDesc * attrInfo;
    char * relName, * attrName, * record, * value;
    int relRecId, attrRecId, return_val, recId, indexFileDesc, fileDesc;

    if ( argc != 3 ) {
        printf( "Error: Three arguments expected for function UT_buildindex\n" );
        return AMINIREL_GE;
    }

    inline cleanup() {
        /* apodesmeush dynamikhs mnhmhs */
        if ( relInfo != NULL ) {
            free( relInfo );
        }

        if ( attrInfo != NULL ) {
            free( attrInfo );
        }

        if ( record != NULL ) {
            free( record );
        }

        /* Kleinoyme arxeia pou isws anoiksame */

        /* kleinoyme to arxeio ths sxeshs */
        if ( fileDesc >= 0 ) {
            if ( HF_CloseFile( fileDesc ) != HFE_OK ) {
                HF_PrintError( "Could not close relation's file" );
                return_val = AMINIREL_GE;
            }
        }

        /* kleinoyme to eyrethrio */
        if ( indexFileDesc >= 0 ) {
            if ( AM_CloseIndex( indexFileDesc ) != AME_OK ) {
                AM_PrintError( "Could not close index" );
                return_val = AMINIREL_GE;
            }
        }
    }

    /* initialization */
    relName = argv[1];
    attrName = argv[2];
    relInfo = NULL;
    attrInfo = NULL;
    record = NULL;
    return_val = AMINIREL_OK;
    fileDesc = indexFileDesc = AMINIREL_INVALID;

    /* kanoume retrieve tis plhrofories gia th sxesh me onoma relName */
    if (( relInfo = getRelation( relName, &relRecId ) ) == NULL ) {
        printf( "Error: Could not retrieve information about relation '%s'\n", relName );
        return AMINIREL_GE;
    }

    /* Mias kai mporoume na exoume to poly 1 eurethrio gia kathe attribute, an o arithmos twn eurethriwn
       isoutai me ton arithmo twn attributes tote de ginetai na ftiaksoume allo index */
    if ( relInfo->attrcnt == relInfo->indexcnt ) {
        printf( "Error: Cannot create yet another index for any of %s's attributes, delete one first\n", relName );
        return_val =  AMINIREL_GE;
        cleanup();
        return return_val;
    }

    /* afou mporesame na vroume th sxesh relName, twra kanoume retrieve tis plhrofories gia to attribute ths */
    if (( attrInfo = getAttribute( relName, attrName, &attrRecId ) ) == NULL ) {
        printf( "Error: Could not retrieve information about attribute '%s' of relation %s\n", attrName, relName );
        return_val = AMINIREL_GE;
        cleanup();
        return return_val;
    }

    /* Vrhkame to attribute, twra elegxoume an yparxei hdh ena eurethrio gia to attribute! */
    if ( attrInfo->indexed == TRUE ) {
        printf( "Error: There is already an index for attribute '%s' of relation '%s'\n", attrName, relName );
        return_val =  AMINIREL_GE;
        cleanup();
        return return_val;
    }
    else {

        /* Mporoume na ftiaksoume neo eurethrio! :v */
        /* Enhmerwnoume to indexed kai indexno tou attrInfo */
        attrInfo->indexed = TRUE;
        attrInfo->indexno = relInfo->indexcnt;

        /* Enhmerwnoume ton indexcnt tou relInfo */
        ( relInfo->indexcnt )++;

        /* Mias kai to HF epipedo mas epistrefei antigrafa twn records, emeis twra pou exoume tis nees versions twn records
           prepei na diagrapsoume ta original kai na eisagoume pali ta kainourgia! */

        /* Diagrafh ths eggrafhs sto relCat */
        if ( HF_DeleteRec( this_db.relCatDesc, relRecId, sizeof( relDesc ) ) != HFE_OK ) {
            HF_PrintError( "Could not Destroy record in relCat " );
            return_val =  AMINIREL_GE;
            cleanup();
            return return_val;
        }

        /* Diagrafh ths eggrafhs sto attrCat */
        if ( HF_DeleteRec( this_db.attrCatDesc, attrRecId, sizeof( attrDesc ) ) != HFE_OK ) {
            HF_PrintError( "Could not Destroy record in attrCat " );
            return_val =  AMINIREL_GE;
            cleanup();
            return return_val;
        }

        /* Eisagwgh twn updated records sto relCat */
        if ( updateRelCat( relInfo ) != AMINIREL_OK ) {
            printf( "ton hpie h update relcat\n" )  ;
            return_val =  AMINIREL_GE;
            cleanup();
            return return_val;
        }

        /* kai sto attrCat */
        if ( updateAttrCat( attrInfo ) != AMINIREL_OK ) {
            printf( "ton hpie h update attrcat\n" )  ;
            return_val =  AMINIREL_GE;
            cleanup();
            return return_val;
        }


        /* Telos, dhmioyrgoyme to eurethrio */

        if ( AM_CreateIndex( relName, attrInfo->indexno, attrInfo->attrtype, attrInfo->attrlength ) != AME_OK ) {
            AM_PrintError( "Could not Create Index in UT_buildindex() " );
            return_val = AMINIREL_GE;
            cleanup();
            return return_val;
        }

        /*
           Twra pou dhmioyrghsame to eyrethrio, prepei oses eggrafes yparxoun sto arxeio ths sxeshs na perastoun sto
           eurethrio!
        */

        /* Desmeuoume xwro gia to xwro pou tha apothikeuetai to kathe record tou arxeiou */
        if (( record = malloc( relInfo->relwidth ) ) == NULL ) {
            printf( MEM_ERROR );
            return_val = AMINIREL_GE;
            cleanup();
            return return_val;
        }

        memset( record, 0, relInfo->relwidth );

        /* Anoigoume to eurethrio */
        if (( indexFileDesc = AM_OpenIndex( relName, attrInfo->indexno ) ) < 0 ) {
            AM_PrintError( "Could not Open Index in UT_buildindex() " );
            return_val = AMINIREL_GE;
            cleanup();
            return return_val;
        }

        /* Anoigoume to arxeio ths sxeshs */

        if (( fileDesc = HF_OpenFile( relName ) ) < 0 ) {
            HF_PrintError( "Could not Open relation's file in UT_buildindex() " );
            return_val = AMINIREL_GE;
            cleanup();
            return return_val;
        }

        /* ksekiname me thn prwth eggrafh */
        if (( recId = HF_GetFirstRec( fileDesc, record, relInfo->relwidth ) ) < 0 ) {
            /* Yparxei h periptwsh to arxeio na mhn exei eggrafes */
            if ( recId != HFE_EOF ) {
                HF_PrintError( "Could not retrieve first Record from relation's file" );
                return_val = AMINIREL_GE;
            }

            cleanup();
            return return_val;
        }

        /* Eisagoume oles tis eggrafes tou arxeiou ths sxeshs, sto eurethrio */
        do {
            /* Thetoume ton pointer value sto swsto shmeio ths eggrafhs ap opou tha paroume tin timh mas */
            value = record + attrInfo->offset;

            /* Eisagoume thn eggrafh sto eurethrio */
            if ( AM_InsertEntry( indexFileDesc, attrInfo->attrtype, attrInfo->attrlength, value, recId ) != AME_OK ) {
                AM_PrintError( "Could not insert into index" );
                return_val = AMINIREL_GE;
            }
        }
        while (( recId = HF_GetNextRec( fileDesc, recId, record , relInfo->relwidth ) ) >= 0 );

        if ( recId != HFE_EOF ) {
            HF_PrintError( "Error: Cannot build index\n" );
            cleanup();
            return return_val;
        }

        return_val = AMINIREL_OK;
    }

    cleanup();
    return return_val;
}
Ejemplo n.º 15
0
int UT_create( int argc, char* argv[] )
{
    relDesc relInfo, * relPtr;
    attrDesc attrInfo;
    char * pch, * relName;
    int i, j, offset, num;

    /* Apaitoume, ektos apo to onoma ths sxeshs:
       - toulaxiston ena gnwrisma kai ton typo tou
       - oloklhrwmena zeugh <onomatos gnwrismatos, typou gnwrismatos>
    */
    if (( argc < 4 ) || ( argc % 2 != 0 ) ) {
        printf( "Error: Cannot create relation: Not enough information\n" );
        return AMINIREL_GE;
    }

    relName = argv[1];

    /* max epitrepto mhkos onomatos = MAXNAME */
    if ( strlen( relName ) >= MAXNAME ) {
        printf( "Error: Cannot create relation: Relation name too long\n" );
        return AMINIREL_GE;
    }

    /* mhpws yparxei hdh h relation ? */
    if (( relPtr = getRelation( relName, &i ) ) != NULL ) {
        printf( "Error: Cannot create relation '%s'. Relation already exists.\n", relName );
        free( relPtr );
        return AMINIREL_GE;
    }

    /*
      * H relation "temp_relation" einai reserved apo to systhma
      * Epitrepetai na dimioyrgithei mono apo tis dm_select & dm_join
    */
    if (strcmp(relName, "temp_relation") == 0 && strcmp(argv[0], "\"DMcreate\"") != 0) {
        printf("Error: Cannot create 'temp_relation'. It is a relation reserved by the system\n");
        return AMINIREL_GE;
    }

    /* Elegxoume an dwthikan idia onomata se 2 attributes ths relation to opoio einai lathos */
    for ( i = 2; i < argc; i += 2 ) {
        for ( j = i + 2; j < argc; j += 2 ) {
            if ( strcmp( argv[i], argv[j] ) == 0 ) {
                printf( "Error: More than one attributes named '%s'.\n", argv[i] );
                return AMINIREL_GE;
            }
        }
    }


    /* Arxikopoihsh ths eggrafhs perigrafhs pleiadas */
    memset( relInfo.relname, 0, MAXNAME );
    strcpy( relInfo.relname, relName );
    /* To relwidth 8a symplhrw8ei meta, otan tha swsoume tis plhrofories twn attributes */
    relInfo.relwidth = 0;
    relInfo.attrcnt = ( argc - 2 ) / 2;
    relInfo.indexcnt = 0;

    /* Arxikopoihsh ths eggrafhs perigrafhs pediwn */
    memset( attrInfo.relname, 0, MAXNAME );
    strcpy( attrInfo.relname, relName );
    attrInfo.indexed = FALSE;
    attrInfo.indexno = 0;

    /* Fortwsh twn plhroforiwn twn pediwn */
    for ( i = 2, offset = 0 ; argv[i] != NULL ; i += 2 ) {
        if ( strlen( argv[i] ) >= MAXNAME ) {
            printf( "Error: Cannot create relation: Attribute name too long\n" );
            return AMINIREL_GE;
        }

        memset( attrInfo.attrname, 0, MAXNAME );
        strcpy( attrInfo.attrname, argv[i] );
        attrInfo.offset = offset;

        pch = argv[i+1];

        /* Prospername to arxiko eisagwgiko ' */
        pch++;

        switch ( *pch ) {
        case 'i':
            offset += sizeof( int );
            attrInfo.attrtype = 'i';
            attrInfo.attrlength = sizeof( int );
            break;
        case 'f':
            offset += sizeof( float );
            attrInfo.attrtype = 'f';
            attrInfo.attrlength = sizeof( float );
            break;
        case 'c':
            num = atoi( pch + 1 );

            if ( num <= 0 || num > 255 ) {
                printf( "Error: Wrong attribute size\n" );
                return AMINIREL_GE;
            }

            offset += num;
            attrInfo.attrtype = 'c';
            attrInfo.attrlength = num;

            break;
        default:
            printf( "Error: Unrecognised type\n" );
            return AMINIREL_GE;
        }

        /* Pros8etoume thn eggrafh gia to sygkekrimeno gnwrisma */
        if ( updateAttrCat( &attrInfo ) != AMINIREL_OK ) {
            printf( "Error: Couldn't update attrCat\n" );
            return AMINIREL_GE;
        }
    }

    relInfo.relwidth = offset;

    /* Pros8etoume thn eggrafh ths sxeshs sto relCat */
    if ( updateRelCat( &relInfo ) != AMINIREL_OK ) {
        printf( "Error: Couldn't update relCat\n" );
        return AMINIREL_GE;
    }

    /* Dhmioyrgoyme to neo arxeio */
    if ( HF_CreateFile( relName ) != HFE_OK ) {
        HF_PrintError( "Could not create new relation file in UT_create() " );
        return AMINIREL_GE;
    }

    return AMINIREL_OK;
}