Mesh Oriented datABase  (version 5.4.1)
Array-based unstructured mesh datastructure
iRel_Lasso.cpp
Go to the documentation of this file.
00001 /**
00002  * Copyright 2006 Sandia Corporation.  Under the terms of Contract
00003  * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
00004  * retains certain rights in this software.
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  */
00012 #include "iRel_Lasso.hpp"
00013 
00014 #include "Lasso.hpp"
00015 #include "AssocPair.hpp"
00016 #include "ArrayManager.hpp"
00017 
00018 #include <algorithm>
00019 #include <cmath>
00020 #include <cstdio>
00021 #include <iostream>
00022 #include <map>
00023 #include <vector>
00024 
00025 const bool debug = false;
00026 
00027 void iRel_getErrorType( iRel_Instance instance, int* error_type )
00028 {
00029     if( instance == NULL )
00030         *error_type = iBase_FAILURE;
00031     else
00032         *error_type = LASSOI->lastErrorType;
00033 }
00034 
00035 void iRel_getDescription( iRel_Instance instance, char* descr, int descr_len )
00036 {
00037     if( instance == NULL )
00038     {
00039         strcpy( descr, "iRel_getDescription: Invalid instance" );
00040     }
00041     else
00042     {
00043         unsigned int len = std::min( strlen( LASSOI->lastErrorDescription ), static_cast< size_t >( descr_len ) );
00044         strncpy( descr, LASSOI->lastErrorDescription, len );
00045         descr[len] = '\0';
00046     }
00047 }
00048 
00049 void iRel_create( /* in */ const char* /* options */, iRel_Instance* instance, int* err, const int options_len )
00050 {
00051     if( 0 != options_len )
00052     {
00053         *instance = NULL;
00054         *err      = iBase_NOT_SUPPORTED;
00055     }
00056 
00057     *instance = new Lasso();
00058     *err      = iBase_SUCCESS;
00059 }
00060 
00061 void iRel_destroy( iRel_Instance instance, int* err )
00062 {
00063     delete LASSOI;
00064     *err = iBase_SUCCESS;
00065 }
00066 
00067 void iRel_createPair( iRel_Instance instance,
00068                       iBase_Instance iface1,
00069                       const int ent_or_set1,
00070                       const int iface_type1,
00071                       const int irel_status1,
00072                       iBase_Instance iface2,
00073                       const int ent_or_set2,
00074                       const int iface_type2,
00075                       const int irel_status2,
00076                       iRel_PairHandle* pair,
00077                       int* err )
00078 {
00079     AssocPair* assoc_pair = new AssocPair(
00080         instance, iface1, static_cast< iRel_RelationType >( ent_or_set1 ), static_cast< iRel_IfaceType >( iface_type1 ),
00081         static_cast< iRel_RelationStatus >( irel_status1 ), iface2, static_cast< iRel_RelationType >( ent_or_set2 ),
00082         static_cast< iRel_IfaceType >( iface_type2 ), static_cast< iRel_RelationStatus >( irel_status2 ) );
00083     LASSOI->insert_pair( assoc_pair );
00084 
00085     *pair = reinterpret_cast< iRel_PairHandle >( assoc_pair );
00086     RETURN( iBase_SUCCESS );
00087 }
00088 
00089 void iRel_getPairInfo( iRel_Instance instance,
00090                        iRel_PairHandle pair,
00091                        iBase_Instance* iface1,
00092                        int* ent_or_set1,
00093                        int* iface_type1,
00094                        int* irel_status1,
00095                        iBase_Instance* iface2,
00096                        int* ent_or_set2,
00097                        int* iface_type2,
00098                        int* irel_status2,
00099                        int* err )
00100 {
00101     CHK_PAIR();
00102 
00103     *iface1       = ASSOCPAIRI->iface_instance( 0 );
00104     *ent_or_set1  = ASSOCPAIRI->relation_type( 0 );
00105     *iface_type1  = ASSOCPAIRI->iface_type( 0 );
00106     *irel_status1 = ASSOCPAIRI->relation_status( 0 );
00107     *iface2       = ASSOCPAIRI->iface_instance( 1 );
00108     *iface_type2  = ASSOCPAIRI->iface_type( 1 );
00109     *ent_or_set2  = ASSOCPAIRI->relation_type( 1 );
00110     *irel_status2 = ASSOCPAIRI->relation_status( 1 );
00111 
00112     RETURN( iBase_SUCCESS );
00113 }
00114 
00115 void iRel_changePairType( iRel_Instance instance, iRel_PairHandle pair, int ent_or_set1, int ent_or_set2, int* err )
00116 {
00117     CHK_PAIR();
00118 
00119     CHK_ERROR( ASSOCPAIRI->change_type( 0, static_cast< iRel_RelationType >( ent_or_set1 ) ) );CHK_ERROR( ASSOCPAIRI->change_type( 1, static_cast< iRel_RelationType >( ent_or_set2 ) ) );
00120 }
00121 
00122 void iRel_changePairStatus( iRel_Instance instance, iRel_PairHandle pair, int irel_status1, int irel_status2, int* err )
00123 {
00124     CHK_PAIR();
00125 
00126     CHK_ERROR( ASSOCPAIRI->change_status( 0, static_cast< iRel_RelationStatus >( irel_status1 ) ) );CHK_ERROR( ASSOCPAIRI->change_status( 1, static_cast< iRel_RelationStatus >( irel_status2 ) ) );
00127 }
00128 
00129 void iRel_destroyPair( iRel_Instance instance, iRel_PairHandle pair, int* err )
00130 {
00131     CHK_PAIR();
00132 
00133     CHK_ERROR( LASSOI->erase_pair( ASSOCPAIRI ) );
00134 }
00135 
00136 void iRel_findPairs( iRel_Instance instance,
00137                      iBase_Instance iface,
00138                      iRel_PairHandle** pairs,
00139                      int* pairs_allocated,
00140                      int* pairs_size,
00141                      int* err )
00142 {
00143     std::vector< AssocPair* > tmp_pairs;
00144     LASSOI->find_pairs( iface, tmp_pairs );
00145 
00146     ALLOC_CHECK_ARRAY_NOFAIL( pairs, tmp_pairs.size() );
00147     for( size_t i = 0; i < tmp_pairs.size(); ++i )
00148     {
00149         ( *pairs )[i] = reinterpret_cast< iRel_PairHandle >( tmp_pairs[i] );
00150     }
00151 
00152     RETURN( iBase_SUCCESS );
00153 }
00154 
00155 void iRel_setEntEntRelation( iRel_Instance instance,
00156                              iRel_PairHandle pair,
00157                              iBase_EntityHandle ent1,
00158                              iBase_EntityHandle ent2,
00159                              int* err )
00160 {
00161     CHK_PAIR();CHK_ERROR( ASSOCPAIRI->set_relation( ent1, ent2 ) );
00162 }
00163 
00164 void iRel_setEntSetRelation( iRel_Instance instance,
00165                              iRel_PairHandle pair,
00166                              iBase_EntityHandle ent1,
00167                              iBase_EntitySetHandle set2,
00168                              int* err )
00169 {
00170     CHK_PAIR();CHK_ERROR( ASSOCPAIRI->set_relation( ent1, set2 ) );
00171 }
00172 
00173 void iRel_setSetEntRelation( iRel_Instance instance,
00174                              iRel_PairHandle pair,
00175                              iBase_EntitySetHandle set1,
00176                              iBase_EntityHandle ent2,
00177                              int* err )
00178 {
00179     CHK_PAIR();CHK_ERROR( ASSOCPAIRI->set_relation( set1, ent2 ) );
00180 }
00181 
00182 void iRel_setSetSetRelation( iRel_Instance instance,
00183                              iRel_PairHandle pair,
00184                              iBase_EntitySetHandle set1,
00185                              iBase_EntitySetHandle set2,
00186                              int* err )
00187 {
00188     CHK_PAIR();CHK_ERROR( ASSOCPAIRI->set_relation( set1, set2 ) );
00189 }
00190 
00191 void iRel_setEntArrEntArrRelation( iRel_Instance instance,
00192                                    iRel_PairHandle pair,
00193                                    iBase_EntityHandle* ent_array_1,
00194                                    int num_entities1,
00195                                    iBase_EntityHandle* ent_array_2,
00196                                    int num_entities2,
00197                                    int* err )
00198 {
00199     CHK_PAIR();
00200 
00201     if( num_entities1 != num_entities2 )
00202         ERROR( iBase_INVALID_ENTITY_COUNT, "setEntArrEntArrRelation doesn't support "
00203                                            "different #'s of entities." );
00204 
00205     int result = iBase_SUCCESS;
00206     char descr[200];
00207     for( int i = 0; i < num_entities1; i++ )
00208     {
00209         int tmp_result = ASSOCPAIRI->set_relation( ent_array_1[i], ent_array_2[i] );
00210         if( result == iBase_SUCCESS && tmp_result != iBase_SUCCESS )
00211         {
00212             result = tmp_result;
00213             iRel_getDescription( instance, descr, sizeof( descr ) );
00214         }
00215     }
00216 
00217     if( result != iBase_SUCCESS ) ERROR( result, descr );
00218     RETURN( iBase_SUCCESS );
00219 }
00220 
00221 void iRel_setEntArrSetArrRelation( iRel_Instance instance,
00222                                    iRel_PairHandle pair,
00223                                    iBase_EntityHandle* ent_array_1,
00224                                    int num_entities1,
00225                                    iBase_EntitySetHandle* set_array_2,
00226                                    int num_sets2,
00227                                    int* err )
00228 {
00229     CHK_PAIR();
00230 
00231     if( num_entities1 != num_sets2 )
00232         ERROR( iBase_INVALID_ENTITY_COUNT, "setEntArrSetArrRelation doesn't support "
00233                                            "different #'s of entities." );
00234 
00235     int result = iBase_SUCCESS;
00236     char descr[200];
00237     for( int i = 0; i < num_entities1; i++ )
00238     {
00239         int tmp_result = ASSOCPAIRI->set_relation( ent_array_1[i], set_array_2[i] );
00240         if( result == iBase_SUCCESS && tmp_result != iBase_SUCCESS )
00241         {
00242             result = tmp_result;
00243             iRel_getDescription( instance, descr, sizeof( descr ) );
00244         }
00245     }
00246 
00247     if( result != iBase_SUCCESS ) ERROR( result, descr );
00248     RETURN( iBase_SUCCESS );
00249 }
00250 
00251 void iRel_setSetArrEntArrRelation( iRel_Instance instance,
00252                                    iRel_PairHandle pair,
00253                                    iBase_EntitySetHandle* set_array_1,
00254                                    int num_sets1,
00255                                    iBase_EntityHandle* ent_array_2,
00256                                    int num_entities2,
00257                                    int* err )
00258 {
00259     CHK_PAIR();
00260 
00261     if( num_sets1 != num_entities2 )
00262         ERROR( iBase_INVALID_ENTITY_COUNT, "setSetArrEntArrRelation doesn't support "
00263                                            "different #'s of entities." );
00264 
00265     int result = iBase_SUCCESS;
00266     char descr[200];
00267     for( int i = 0; i < num_sets1; i++ )
00268     {
00269         int tmp_result = ASSOCPAIRI->set_relation( set_array_1[i], ent_array_2[i] );
00270         if( result == iBase_SUCCESS && tmp_result != iBase_SUCCESS )
00271         {
00272             result = tmp_result;
00273             iRel_getDescription( instance, descr, sizeof( descr ) );
00274         }
00275     }
00276 
00277     if( result != iBase_SUCCESS ) ERROR( result, descr );
00278     RETURN( iBase_SUCCESS );
00279 }
00280 
00281 void iRel_setSetArrSetArrRelation( iRel_Instance instance,
00282                                    iRel_PairHandle pair,
00283                                    iBase_EntitySetHandle* set_array_1,
00284                                    int num_sets1,
00285                                    iBase_EntitySetHandle* set_array_2,
00286                                    int num_sets2,
00287                                    int* err )
00288 {
00289     CHK_PAIR();
00290 
00291     if( num_sets1 != num_sets2 )
00292         ERROR( iBase_INVALID_ENTITY_COUNT, "setSetArrSetArrRelation doesn't support "
00293                                            "different #'s of entities." );
00294 
00295     int result = iBase_SUCCESS;
00296     char descr[200];
00297     for( int i = 0; i < num_sets1; i++ )
00298     {
00299         int tmp_result = ASSOCPAIRI->set_relation( set_array_1[i], set_array_2[i] );
00300         if( result == iBase_SUCCESS && tmp_result != iBase_SUCCESS )
00301         {
00302             result = tmp_result;
00303             iRel_getDescription( instance, descr, sizeof( descr ) );
00304         }
00305     }
00306 
00307     if( result != iBase_SUCCESS ) ERROR( result, descr );
00308     RETURN( iBase_SUCCESS );
00309 }
00310 
00311 void iRel_getEntEntRelation( iRel_Instance instance,
00312                              iRel_PairHandle pair,
00313                              iBase_EntityHandle ent1,
00314                              int switch_order,
00315                              iBase_EntityHandle* ent2,
00316                              int* err )
00317 {
00318     CHK_PAIR();
00319 
00320     int iface_no = ( switch_order ? 1 : 0 );CHK_ERROR( ASSOCPAIRI->get_relation( iface_no, &ent1, 1, ent2 ) );
00321 }
00322 
00323 void iRel_getEntSetRelation( iRel_Instance instance,
00324                              iRel_PairHandle pair,
00325                              iBase_EntityHandle ent1,
00326                              int switch_order,
00327                              iBase_EntitySetHandle* set2,
00328                              int* err )
00329 {
00330     CHK_PAIR();
00331 
00332     int iface_no = ( switch_order ? 1 : 0 );CHK_ERROR( ASSOCPAIRI->get_relation( iface_no, &ent1, 1, set2 ) );
00333 }
00334 
00335 void iRel_getSetEntRelation( iRel_Instance instance,
00336                              iRel_PairHandle pair,
00337                              iBase_EntitySetHandle set1,
00338                              int switch_order,
00339                              iBase_EntityHandle* ent2,
00340                              int* err )
00341 {
00342     CHK_PAIR();
00343 
00344     int iface_no = ( switch_order ? 1 : 0 );CHK_ERROR( ASSOCPAIRI->get_relation( iface_no, &set1, 1, ent2 ) );
00345 }
00346 
00347 void iRel_getSetSetRelation( iRel_Instance instance,
00348                              iRel_PairHandle pair,
00349                              iBase_EntitySetHandle set1,
00350                              int switch_order,
00351                              iBase_EntitySetHandle* set2,
00352                              int* err )
00353 {
00354     CHK_PAIR();
00355 
00356     int iface_no = ( switch_order ? 1 : 0 );CHK_ERROR( ASSOCPAIRI->get_relation( iface_no, &set1, 1, set2 ) );
00357 }
00358 
00359 void iRel_getEntSetIterRelation( iRel_Instance instance,
00360                                  iRel_PairHandle pair,
00361                                  iBase_EntityHandle ent1,
00362                                  int switch_order,
00363                                  iBase_EntityIterator* entset2,
00364                                  int* err )
00365 {
00366     CHK_PAIR();
00367 
00368     int iface_no = ( switch_order ? 1 : 0 );CHK_ERROR( ASSOCPAIRI->get_relation( iface_no, &ent1, 1, entset2 ) );
00369 }
00370 
00371 void iRel_getEntArrEntArrRelation( iRel_Instance instance,
00372                                    iRel_PairHandle pair,
00373                                    iBase_EntityHandle* ent_array_1,
00374                                    int ent_array_1_size,
00375                                    int switch_order,
00376                                    iBase_EntityHandle** ent_array_2,
00377                                    int* ent_array_2_allocated,
00378                                    int* ent_array_2_size,
00379                                    int* err )
00380 {
00381     CHK_PAIR();
00382 
00383     int iface_no = ( switch_order ? 1 : 0 );
00384     ALLOC_CHECK_ARRAY( ent_array_2, ent_array_1_size );CHK_ERROR( ASSOCPAIRI->get_relation( iface_no, ent_array_1, ent_array_1_size, *ent_array_2 ) );
00385 
00386     KEEP_ARRAY( ent_array_2 );
00387     RETURN( iBase_SUCCESS );
00388 }
00389 
00390 void iRel_getEntArrSetArrRelation( iRel_Instance instance,
00391                                    iRel_PairHandle pair,
00392                                    iBase_EntityHandle* ent_array_1,
00393                                    int ent_array_1_size,
00394                                    int switch_order,
00395                                    iBase_EntitySetHandle** set_array_2,
00396                                    int* set_array_2_allocated,
00397                                    int* set_array_2_size,
00398                                    int* err )
00399 {
00400     CHK_PAIR();
00401 
00402     int iface_no = ( switch_order ? 1 : 0 );
00403     ALLOC_CHECK_ARRAY( set_array_2, ent_array_1_size );CHK_ERROR( ASSOCPAIRI->get_relation( iface_no, ent_array_1, ent_array_1_size, *set_array_2 ) );
00404 
00405     KEEP_ARRAY( set_array_2 );
00406     RETURN( iBase_SUCCESS );
00407 }
00408 
00409 void iRel_getSetArrEntArrRelation( iRel_Instance instance,
00410                                    iRel_PairHandle pair,
00411                                    iBase_EntitySetHandle* set_array_1,
00412                                    int set_array_1_size,
00413                                    int switch_order,
00414                                    iBase_EntityHandle** ent_array_2,
00415                                    int* ent_array_2_allocated,
00416                                    int* ent_array_2_size,
00417                                    int* err )
00418 {
00419     CHK_PAIR();
00420 
00421     int iface_no = ( switch_order ? 1 : 0 );
00422     ALLOC_CHECK_ARRAY( ent_array_2, set_array_1_size );CHK_ERROR( ASSOCPAIRI->get_relation( iface_no, set_array_1, set_array_1_size, *ent_array_2 ) );
00423 
00424     KEEP_ARRAY( ent_array_2 );
00425     RETURN( iBase_SUCCESS );
00426 }
00427 
00428 void iRel_getSetArrSetArrRelation( iRel_Instance instance,
00429                                    iRel_PairHandle pair,
00430                                    iBase_EntitySetHandle* set_array_1,
00431                                    int set_array_1_size,
00432                                    int switch_order,
00433                                    iBase_EntitySetHandle** set_array_2,
00434                                    int* set_array_2_allocated,
00435                                    int* set_array_2_size,
00436                                    int* err )
00437 {
00438     CHK_PAIR();
00439 
00440     int iface_no = ( switch_order ? 1 : 0 );
00441     ALLOC_CHECK_ARRAY( set_array_2, set_array_1_size );CHK_ERROR( ASSOCPAIRI->get_relation( iface_no, set_array_1, set_array_1_size, *set_array_2 ) );
00442 
00443     KEEP_ARRAY( set_array_2 );
00444     RETURN( iBase_SUCCESS );
00445 }
00446 
00447 void iRel_getEntArrSetIterArrRelation( iRel_Instance instance,
00448                                        iRel_PairHandle pair,
00449                                        iBase_EntityHandle* ent_array_1,
00450                                        int ent_array_1_size,
00451                                        int switch_order,
00452                                        iBase_EntityIterator** entiter,
00453                                        int* entiter_allocated,
00454                                        int* entiter_size,
00455                                        int* err )
00456 {
00457     CHK_PAIR();
00458 
00459     int iface_no = ( switch_order ? 1 : 0 );
00460     ;
00461     ALLOC_CHECK_ARRAY( entiter, ent_array_1_size );CHK_ERROR( ASSOCPAIRI->get_relation( iface_no, ent_array_1, ent_array_1_size, *entiter ) );
00462 
00463     KEEP_ARRAY( entiter );
00464     RETURN( iBase_SUCCESS );
00465 }
00466 
00467 void iRel_rmvEntRelation( iRel_Instance instance,
00468                           /*in*/ iRel_PairHandle pair,
00469                           /*in*/ iBase_EntityHandle ent,
00470                           /*in*/ int switch_order,
00471                           /*out*/ int* err )
00472 {
00473     CHK_PAIR();
00474 
00475     int iface_no = ( switch_order ? 1 : 0 );CHK_ERROR( ASSOCPAIRI->rmv_relation( iface_no, &ent, 1 ) );
00476 }
00477 
00478 void iRel_rmvSetRelation( iRel_Instance instance,
00479                           /*in*/ iRel_PairHandle pair,
00480                           /*in*/ iBase_EntitySetHandle entset,
00481                           /*in*/ int switch_order,
00482                           /*out*/ int* err )
00483 {
00484     CHK_PAIR();
00485 
00486     int iface_no = ( switch_order ? 1 : 0 );CHK_ERROR( ASSOCPAIRI->rmv_relation( iface_no, &entset, 1 ) );
00487 }
00488 
00489 void iRel_rmvEntArrRelation( iRel_Instance instance,
00490                              /*in*/ iRel_PairHandle pair,
00491                              /*in*/ iBase_EntityHandle* ent_array,
00492                              /*in*/ int num_ent,
00493                              /*in*/ int switch_order,
00494                              /*out*/ int* err )
00495 {
00496     CHK_PAIR();
00497 
00498     int iface_no = ( switch_order ? 1 : 0 );CHK_ERROR( ASSOCPAIRI->rmv_relation( iface_no, ent_array, num_ent ) );
00499 }
00500 
00501 void iRel_rmvSetArrRelation( iRel_Instance instance,
00502                              /*in*/ iRel_PairHandle pair,
00503                              /*in*/ iBase_EntitySetHandle* entset_array,
00504                              /*in*/ int num_ent,
00505                              /*in*/ int switch_order,
00506                              /*out*/ int* err )
00507 {
00508     CHK_PAIR();
00509 
00510     int iface_no = ( switch_order ? 1 : 0 );CHK_ERROR( ASSOCPAIRI->rmv_relation( iface_no, entset_array, num_ent ) );
00511 }
00512 
00513 static int get_gids_and_dims( iRel_PairHandle pair,
00514                               int iface_no,
00515                               iBase_EntityHandle* ents,
00516                               int ents_size,
00517                               int ent_or_set,
00518                               std::vector< int >& ents_gids,
00519                               std::vector< int >& ents_dims )
00520 {
00521     int result;
00522     iBase_EntitySetHandle* sets = reinterpret_cast< iBase_EntitySetHandle* >( ents );
00523 
00524     ents_gids.resize( ents_size );
00525     if( ent_or_set == iRel_ENTITY )
00526         result = ASSOCPAIRI->get_gids( iface_no, ents, ents_size, &ents_gids[0] );
00527     else
00528         result = ASSOCPAIRI->get_gids( iface_no, sets, ents_size, &ents_gids[0] );
00529 
00530     if( iBase_SUCCESS != result && iBase_TAG_NOT_FOUND != result ) return result;
00531 
00532     ents_dims.resize( ents_size, -1 );
00533     if( ent_or_set == iRel_ENTITY )
00534     {
00535         int* ents_dims_ptr  = &ents_dims[0];
00536         int ents_dims_alloc = ents_dims.size(), ents_dims_size;
00537         result =
00538             ASSOCPAIRI->get_ents_dims( iface_no, ents, ents_size, &ents_dims_ptr, &ents_dims_alloc, &ents_dims_size );
00539     }
00540     else
00541     {
00542         result = ASSOCPAIRI->get_dims( iface_no, sets, ents_size, &ents_dims[0] );
00543     }
00544 
00545     if( iBase_SUCCESS != result && iBase_TAG_NOT_FOUND != result ) return result;
00546 
00547     return iBase_SUCCESS;
00548 }
00549 
00550 static void iRel_inferArrArrRelations( iRel_Instance instance,
00551                                        iRel_PairHandle pair,
00552                                        iBase_EntityHandle* ents1,
00553                                        const int ents1_size,
00554                                        int ent_or_set1,
00555                                        iBase_EntityHandle* ents2,
00556                                        const int ents2_size,
00557                                        int ent_or_set2,
00558                                        int* err )
00559 {
00560     int result;
00561 
00562     std::vector< int > ents_gids, ents_dims;
00563     std::map< const int, iBase_EntityHandle > ents_gid_map[4];
00564 
00565     get_gids_and_dims( pair, 0, ents1, ents1_size, ent_or_set1, ents_gids, ents_dims );
00566     for( int i = 0; i < ents1_size; i++ )
00567     {
00568         int dim = ents_dims[i];
00569         if( 0 <= dim && 3 >= dim ) ents_gid_map[dim][ents_gids[i]] = ents1[i];
00570     }
00571 
00572     get_gids_and_dims( pair, 1, ents2, ents2_size, ent_or_set2, ents_gids, ents_dims );
00573     for( int i = 0; i < ents2_size; i++ )
00574     {
00575         int dim = ents_dims[i];
00576 
00577         // only check entities for which the dimension entry is in a reasonable
00578         // range
00579         if( 0 > dim || 3 < dim ) continue;
00580 
00581         // there's a match if there's an entity with that dimension with matching id
00582         std::map< const int, iBase_EntityHandle >::iterator iter = ents_gid_map[dim].find( ents_gids[i] );
00583 
00584         // if it matches, set the relation tags for those entities
00585         if( iter != ents_gid_map[dim].end() )
00586         {
00587             if( ent_or_set1 == iRel_ENTITY && ent_or_set2 == iRel_ENTITY )
00588             {
00589                 result = ASSOCPAIRI->set_relation( ( *iter ).second, ents2[i] );
00590             }
00591             else if( ent_or_set1 != iRel_ENTITY && ent_or_set2 == iRel_ENTITY )
00592             {
00593                 result = ASSOCPAIRI->set_relation( (iBase_EntitySetHandle)( *iter ).second, ents2[i] );
00594             }
00595             else if( ent_or_set1 == iRel_ENTITY && ent_or_set2 != iRel_ENTITY )
00596             {
00597                 result = ASSOCPAIRI->set_relation( ( *iter ).second, (iBase_EntitySetHandle)ents2[i] );
00598             }
00599             else
00600             {  // ent_or_set1 != iRel_ENTITY && ent_or_set2 != iRel_ENTITY
00601                 result = ASSOCPAIRI->set_relation( (iBase_EntitySetHandle)( *iter ).second,
00602                                                    (iBase_EntitySetHandle)ents2[i] );
00603             }
00604 
00605             CHK_ERROR( result );
00606         }
00607     }
00608 
00609     RETURN( iBase_SUCCESS );
00610 }
00611 
00612 void iRel_inferEntArrEntArrRelations( iRel_Instance instance,
00613                                       iRel_PairHandle pair,
00614                                       iBase_EntityHandle* ents1,
00615                                       const int ents1_size,
00616                                       iBase_EntityHandle* ents2,
00617                                       const int ents2_size,
00618                                       int* err )
00619 {
00620     iRel_inferArrArrRelations( instance, pair, ents1, ents1_size, 0, ents2, ents2_size, 0, err );
00621 }
00622 
00623 void iRel_inferEntArrSetArrRelations( iRel_Instance instance,
00624                                       iRel_PairHandle pair,
00625                                       iBase_EntityHandle* ents1,
00626                                       const int ents1_size,
00627                                       iBase_EntitySetHandle* ents2,
00628                                       const int ents2_size,
00629                                       int* err )
00630 {
00631     iRel_inferArrArrRelations( instance, pair, ents1, ents1_size, 0, (iBase_EntityHandle*)ents2, ents2_size, 1, err );
00632 }
00633 
00634 void iRel_inferSetArrEntArrRelations( iRel_Instance instance,
00635                                       iRel_PairHandle pair,
00636                                       iBase_EntitySetHandle* ents1,
00637                                       const int ents1_size,
00638                                       iBase_EntityHandle* ents2,
00639                                       const int ents2_size,
00640                                       int* err )
00641 {
00642     iRel_inferArrArrRelations( instance, pair, (iBase_EntityHandle*)ents1, ents1_size, 1, ents2, ents2_size, 0, err );
00643 }
00644 
00645 void iRel_inferSetArrSetArrRelations( iRel_Instance instance,
00646                                       iRel_PairHandle pair,
00647                                       iBase_EntitySetHandle* ents1,
00648                                       const int ents1_size,
00649                                       int /*is_set1*/,
00650                                       iBase_EntitySetHandle* ents2,
00651                                       const int ents2_size,
00652                                       int /*is_set2*/,
00653                                       int* err )
00654 
00655 {
00656     iRel_inferArrArrRelations( instance, pair, (iBase_EntityHandle*)ents1, ents1_size, 1, (iBase_EntityHandle*)ents2,
00657                                ents2_size, 1, err );
00658 }
00659 
00660 void iRel_inferAllRelations( iRel_Instance instance, iRel_PairHandle pair, int* err )
00661 {
00662     CHK_PAIR();
00663 
00664     // get all entities in those interfaces
00665     int result;
00666 
00667     iBase_EntityHandle* ents1 = NULL;
00668     int ents1_alloc           = 0, ents1_size;
00669     if( ASSOCPAIRI->relation_type( 0 ) != iRel_ENTITY )
00670         result = ASSOCPAIRI->get_all_sets( 0, (iBase_EntitySetHandle**)&ents1, &ents1_alloc, &ents1_size );
00671     else
00672         result = ASSOCPAIRI->get_all_entities( 0, -1, &ents1, &ents1_alloc, &ents1_size );CHK_ERROR( result );
00673 
00674     iBase_EntityHandle* ents2 = NULL;
00675     int ents2_alloc           = 0, ents2_size;
00676     if( ASSOCPAIRI->relation_type( 1 ) != iRel_ENTITY )
00677         result = ASSOCPAIRI->get_all_sets( 1, (iBase_EntitySetHandle**)&ents2, &ents2_alloc, &ents2_size );
00678     else
00679         result = ASSOCPAIRI->get_all_entities( 1, -1, &ents2, &ents2_alloc, &ents2_size );CHK_ERROR( result );
00680 
00681     iRel_inferArrArrRelations( instance, pair, ents1, ents1_size, ASSOCPAIRI->relation_type( 0 ), ents2, ents2_size,
00682                                ASSOCPAIRI->relation_type( 1 ), &result );
00683 
00684     free( ents1 );
00685     free( ents2 );CHK_ERROR( result );
00686 }
00687 
00688 void iRel_inferAllRelationsAndType( iRel_Instance instance, iRel_PairHandle* /*pair*/, int* err )
00689 {
00690     ERROR( iBase_NOT_SUPPORTED, "Not currently supported." );
00691 }
00692 
00693 void iRel_inferEntRelations( iRel_Instance instance,
00694                              iRel_PairHandle pair,
00695                              iBase_EntityHandle entity,
00696                              int iface_no,
00697                              int* err )
00698 {
00699     iRel_inferEntArrRelations( instance, pair, &entity, 1, iface_no, err );
00700 }
00701 
00702 void iRel_inferSetRelations( iRel_Instance instance,
00703                              iRel_PairHandle pair,
00704                              iBase_EntitySetHandle entity,
00705                              int iface_no,
00706                              int* err )
00707 {
00708     iRel_inferSetArrRelations( instance, pair, &entity, 1, iface_no, err );
00709 }
00710 
00711 static void iRel_inferArrRelations( iRel_Instance instance,
00712                                     iRel_PairHandle pair,
00713                                     iBase_EntityHandle* entities,
00714                                     int entities_size,
00715                                     bool is_set,
00716                                     int iface_no,
00717                                     int* err )
00718 {
00719     CHK_PAIR();
00720 
00721     if( 0 > iface_no || 1 < iface_no )
00722     {
00723         ERROR( iBase_INVALID_ARGUMENT, "Interface number must be 0 or 1" );
00724     }
00725     else if( ( is_set && ASSOCPAIRI->relation_type( iface_no ) == iRel_ENTITY ) ||
00726              ( !is_set && ASSOCPAIRI->relation_type( iface_no ) != iRel_ENTITY ) )
00727     {
00728         ERROR( iBase_INVALID_ARGUMENT, "is_set must match entOrSet in call to "
00729                                        "inferArrRelations" );
00730     }
00731 
00732     // get all entities in iface2
00733     int result;
00734     iBase_EntityHandle* ents1 = entities;
00735     int ents1_size            = entities_size;
00736     iBase_EntityHandle* ents2 = NULL;
00737     int ents2_alloc           = 0, ents2_size;
00738     if( ASSOCPAIRI->relation_type( 1 - iface_no ) != iRel_ENTITY )
00739         result = ASSOCPAIRI->get_all_sets( !iface_no, (iBase_EntitySetHandle**)&ents2, &ents2_alloc, &ents2_size );
00740     else
00741         result = ASSOCPAIRI->get_all_entities( !iface_no, -1, &ents2, &ents2_alloc, &ents2_size );CHK_ERROR( result );
00742 
00743     // switch so that entity lists always go into inferArrArrRelations in
00744     // forward order wrt pair
00745     if( 1 == iface_no )
00746     {
00747         std::swap( ents1, ents2 );
00748         std::swap( ents1_size, ents2_size );
00749     }
00750 
00751     iRel_inferArrArrRelations( instance, pair, ents1, ents1_size, ASSOCPAIRI->relation_type( 0 ), ents2, ents2_size,
00752                                ASSOCPAIRI->relation_type( 1 ), &result );
00753 
00754     free( 1 == iface_no ? ents1 : ents2 );
00755 
00756     CHK_ERROR( result );
00757 }
00758 
00759 void iRel_inferEntArrRelations( iRel_Instance instance,
00760                                 iRel_PairHandle pair,
00761                                 iBase_EntityHandle* entities,
00762                                 int entities_size,
00763                                 int iface_no,
00764                                 int* err )
00765 {
00766     iRel_inferArrRelations( instance, pair, entities, entities_size, false, iface_no, err );
00767 }
00768 
00769 void iRel_inferSetArrRelations( iRel_Instance instance,
00770                                 iRel_PairHandle pair,
00771                                 iBase_EntitySetHandle* entities,
00772                                 int entities_size,
00773                                 int iface_no,
00774                                 int* err )
00775 {
00776     iRel_inferArrRelations( instance, pair, (iBase_EntityHandle*)entities, entities_size, true, iface_no, err );
00777 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines