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