MOAB: Mesh Oriented datABase  (version 5.5.0)
iRel_Lasso.cpp
Go to the documentation of this file.
1 /**
2  * Copyright 2006 Sandia Corporation. Under the terms of Contract
3  * DE-AC04-94AL85000 with Sandia Coroporation, the U.S. Government
4  * retains certain rights in this software.
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  */
12 #include "iRel_Lasso.hpp"
13 
14 #include "Lasso.hpp"
15 #include "AssocPair.hpp"
16 #include "ArrayManager.hpp"
17 
18 #include <algorithm>
19 #include <cmath>
20 #include <cstdio>
21 #include <iostream>
22 #include <map>
23 #include <vector>
24 
25 const bool debug = false;
26 
27 void iRel_getErrorType( iRel_Instance instance, int* error_type )
28 {
29  if( instance == NULL )
30  *error_type = iBase_FAILURE;
31  else
32  *error_type = LASSOI->lastErrorType;
33 }
34 
35 void iRel_getDescription( iRel_Instance instance, char* descr, int descr_len )
36 {
37  if( instance == NULL )
38  {
39  strcpy( descr, "iRel_getDescription: Invalid instance" );
40  }
41  else
42  {
43  unsigned int len = std::min( strlen( LASSOI->lastErrorDescription ), static_cast< size_t >( descr_len ) );
44  strncpy( descr, LASSOI->lastErrorDescription, len );
45  descr[len] = '\0';
46  }
47 }
48 
49 void iRel_create( /* in */ const char* /* options */, iRel_Instance* instance, int* err, const int options_len )
50 {
51  if( 0 != options_len )
52  {
53  *instance = NULL;
54  *err = iBase_NOT_SUPPORTED;
55  }
56 
57  *instance = new Lasso();
58  *err = iBase_SUCCESS;
59 }
60 
61 void iRel_destroy( iRel_Instance instance, int* err )
62 {
63  delete LASSOI;
64  *err = iBase_SUCCESS;
65 }
66 
68  iBase_Instance iface1,
69  const int ent_or_set1,
70  const int iface_type1,
71  const int irel_status1,
72  iBase_Instance iface2,
73  const int ent_or_set2,
74  const int iface_type2,
75  const int irel_status2,
76  iRel_PairHandle* pair,
77  int* err )
78 {
79  AssocPair* assoc_pair = new AssocPair(
80  instance, iface1, static_cast< iRel_RelationType >( ent_or_set1 ), static_cast< iRel_IfaceType >( iface_type1 ),
81  static_cast< iRel_RelationStatus >( irel_status1 ), iface2, static_cast< iRel_RelationType >( ent_or_set2 ),
82  static_cast< iRel_IfaceType >( iface_type2 ), static_cast< iRel_RelationStatus >( irel_status2 ) );
83  LASSOI->insert_pair( assoc_pair );
84 
85  *pair = reinterpret_cast< iRel_PairHandle >( assoc_pair );
87 }
88 
90  iRel_PairHandle pair,
91  iBase_Instance* iface1,
92  int* ent_or_set1,
93  int* iface_type1,
94  int* irel_status1,
95  iBase_Instance* iface2,
96  int* ent_or_set2,
97  int* iface_type2,
98  int* irel_status2,
99  int* err )
100 {
101  CHK_PAIR();
102 
103  *iface1 = ASSOCPAIRI->iface_instance( 0 );
104  *ent_or_set1 = ASSOCPAIRI->relation_type( 0 );
105  *iface_type1 = ASSOCPAIRI->iface_type( 0 );
106  *irel_status1 = ASSOCPAIRI->relation_status( 0 );
107  *iface2 = ASSOCPAIRI->iface_instance( 1 );
108  *iface_type2 = ASSOCPAIRI->iface_type( 1 );
109  *ent_or_set2 = ASSOCPAIRI->relation_type( 1 );
110  *irel_status2 = ASSOCPAIRI->relation_status( 1 );
111 
113 }
114 
115 void iRel_changePairType( iRel_Instance instance, iRel_PairHandle pair, int ent_or_set1, int ent_or_set2, int* err )
116 {
117  CHK_PAIR();
118 
119  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 ) ) );
120 }
121 
122 void iRel_changePairStatus( iRel_Instance instance, iRel_PairHandle pair, int irel_status1, int irel_status2, int* err )
123 {
124  CHK_PAIR();
125 
126  CHK_ERROR( ASSOCPAIRI->change_status( 0, static_cast< iRel_RelationStatus >( irel_status1 ) ) );CHK_ERROR( ASSOCPAIRI->change_status( 1, static_cast< iRel_RelationStatus >( irel_status2 ) ) );
127 }
128 
129 void iRel_destroyPair( iRel_Instance instance, iRel_PairHandle pair, int* err )
130 {
131  CHK_PAIR();
132 
133  CHK_ERROR( LASSOI->erase_pair( ASSOCPAIRI ) );
134 }
135 
138  iRel_PairHandle** pairs,
139  int* pairs_allocated,
140  int* pairs_size,
141  int* err )
142 {
143  std::vector< AssocPair* > tmp_pairs;
144  LASSOI->find_pairs( iface, tmp_pairs );
145 
146  ALLOC_CHECK_ARRAY_NOFAIL( pairs, tmp_pairs.size() );
147  for( size_t i = 0; i < tmp_pairs.size(); ++i )
148  {
149  ( *pairs )[i] = reinterpret_cast< iRel_PairHandle >( tmp_pairs[i] );
150  }
151 
153 }
154 
156  iRel_PairHandle pair,
157  iBase_EntityHandle ent1,
158  iBase_EntityHandle ent2,
159  int* err )
160 {
161  CHK_PAIR();CHK_ERROR( ASSOCPAIRI->set_relation( ent1, ent2 ) );
162 }
163 
165  iRel_PairHandle pair,
166  iBase_EntityHandle ent1,
168  int* err )
169 {
170  CHK_PAIR();CHK_ERROR( ASSOCPAIRI->set_relation( ent1, set2 ) );
171 }
172 
174  iRel_PairHandle pair,
176  iBase_EntityHandle ent2,
177  int* err )
178 {
179  CHK_PAIR();CHK_ERROR( ASSOCPAIRI->set_relation( set1, ent2 ) );
180 }
181 
183  iRel_PairHandle pair,
186  int* err )
187 {
188  CHK_PAIR();CHK_ERROR( ASSOCPAIRI->set_relation( set1, set2 ) );
189 }
190 
192  iRel_PairHandle pair,
193  iBase_EntityHandle* ent_array_1,
194  int num_entities1,
195  iBase_EntityHandle* ent_array_2,
196  int num_entities2,
197  int* err )
198 {
199  CHK_PAIR();
200 
201  if( num_entities1 != num_entities2 )
202  ERROR( iBase_INVALID_ENTITY_COUNT, "setEntArrEntArrRelation doesn't support "
203  "different #'s of entities." );
204 
205  int result = iBase_SUCCESS;
206  char descr[200];
207  for( int i = 0; i < num_entities1; i++ )
208  {
209  int tmp_result = ASSOCPAIRI->set_relation( ent_array_1[i], ent_array_2[i] );
210  if( result == iBase_SUCCESS && tmp_result != iBase_SUCCESS )
211  {
212  result = tmp_result;
213  iRel_getDescription( instance, descr, sizeof( descr ) );
214  }
215  }
216 
217  if( result != iBase_SUCCESS ) ERROR( result, descr );
219 }
220 
222  iRel_PairHandle pair,
223  iBase_EntityHandle* ent_array_1,
224  int num_entities1,
225  iBase_EntitySetHandle* set_array_2,
226  int num_sets2,
227  int* err )
228 {
229  CHK_PAIR();
230 
231  if( num_entities1 != num_sets2 )
232  ERROR( iBase_INVALID_ENTITY_COUNT, "setEntArrSetArrRelation doesn't support "
233  "different #'s of entities." );
234 
235  int result = iBase_SUCCESS;
236  char descr[200];
237  for( int i = 0; i < num_entities1; i++ )
238  {
239  int tmp_result = ASSOCPAIRI->set_relation( ent_array_1[i], set_array_2[i] );
240  if( result == iBase_SUCCESS && tmp_result != iBase_SUCCESS )
241  {
242  result = tmp_result;
243  iRel_getDescription( instance, descr, sizeof( descr ) );
244  }
245  }
246 
247  if( result != iBase_SUCCESS ) ERROR( result, descr );
249 }
250 
252  iRel_PairHandle pair,
253  iBase_EntitySetHandle* set_array_1,
254  int num_sets1,
255  iBase_EntityHandle* ent_array_2,
256  int num_entities2,
257  int* err )
258 {
259  CHK_PAIR();
260 
261  if( num_sets1 != num_entities2 )
262  ERROR( iBase_INVALID_ENTITY_COUNT, "setSetArrEntArrRelation doesn't support "
263  "different #'s of entities." );
264 
265  int result = iBase_SUCCESS;
266  char descr[200];
267  for( int i = 0; i < num_sets1; i++ )
268  {
269  int tmp_result = ASSOCPAIRI->set_relation( set_array_1[i], ent_array_2[i] );
270  if( result == iBase_SUCCESS && tmp_result != iBase_SUCCESS )
271  {
272  result = tmp_result;
273  iRel_getDescription( instance, descr, sizeof( descr ) );
274  }
275  }
276 
277  if( result != iBase_SUCCESS ) ERROR( result, descr );
279 }
280 
282  iRel_PairHandle pair,
283  iBase_EntitySetHandle* set_array_1,
284  int num_sets1,
285  iBase_EntitySetHandle* set_array_2,
286  int num_sets2,
287  int* err )
288 {
289  CHK_PAIR();
290 
291  if( num_sets1 != num_sets2 )
292  ERROR( iBase_INVALID_ENTITY_COUNT, "setSetArrSetArrRelation doesn't support "
293  "different #'s of entities." );
294 
295  int result = iBase_SUCCESS;
296  char descr[200];
297  for( int i = 0; i < num_sets1; i++ )
298  {
299  int tmp_result = ASSOCPAIRI->set_relation( set_array_1[i], set_array_2[i] );
300  if( result == iBase_SUCCESS && tmp_result != iBase_SUCCESS )
301  {
302  result = tmp_result;
303  iRel_getDescription( instance, descr, sizeof( descr ) );
304  }
305  }
306 
307  if( result != iBase_SUCCESS ) ERROR( result, descr );
309 }
310 
312  iRel_PairHandle pair,
313  iBase_EntityHandle ent1,
314  int switch_order,
315  iBase_EntityHandle* ent2,
316  int* err )
317 {
318  CHK_PAIR();
319 
320  int iface_no = ( switch_order ? 1 : 0 );CHK_ERROR( ASSOCPAIRI->get_relation( iface_no, &ent1, 1, ent2 ) );
321 }
322 
324  iRel_PairHandle pair,
325  iBase_EntityHandle ent1,
326  int switch_order,
327  iBase_EntitySetHandle* set2,
328  int* err )
329 {
330  CHK_PAIR();
331 
332  int iface_no = ( switch_order ? 1 : 0 );CHK_ERROR( ASSOCPAIRI->get_relation( iface_no, &ent1, 1, set2 ) );
333 }
334 
336  iRel_PairHandle pair,
338  int switch_order,
339  iBase_EntityHandle* ent2,
340  int* err )
341 {
342  CHK_PAIR();
343 
344  int iface_no = ( switch_order ? 1 : 0 );CHK_ERROR( ASSOCPAIRI->get_relation( iface_no, &set1, 1, ent2 ) );
345 }
346 
348  iRel_PairHandle pair,
350  int switch_order,
351  iBase_EntitySetHandle* set2,
352  int* err )
353 {
354  CHK_PAIR();
355 
356  int iface_no = ( switch_order ? 1 : 0 );CHK_ERROR( ASSOCPAIRI->get_relation( iface_no, &set1, 1, set2 ) );
357 }
358 
360  iRel_PairHandle pair,
361  iBase_EntityHandle ent1,
362  int switch_order,
363  iBase_EntityIterator* entset2,
364  int* err )
365 {
366  CHK_PAIR();
367 
368  int iface_no = ( switch_order ? 1 : 0 );CHK_ERROR( ASSOCPAIRI->get_relation( iface_no, &ent1, 1, entset2 ) );
369 }
370 
372  iRel_PairHandle pair,
373  iBase_EntityHandle* ent_array_1,
374  int ent_array_1_size,
375  int switch_order,
376  iBase_EntityHandle** ent_array_2,
377  int* ent_array_2_allocated,
378  int* ent_array_2_size,
379  int* err )
380 {
381  CHK_PAIR();
382 
383  int iface_no = ( switch_order ? 1 : 0 );
384  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 ) );
385 
386  KEEP_ARRAY( ent_array_2 );
388 }
389 
391  iRel_PairHandle pair,
392  iBase_EntityHandle* ent_array_1,
393  int ent_array_1_size,
394  int switch_order,
395  iBase_EntitySetHandle** set_array_2,
396  int* set_array_2_allocated,
397  int* set_array_2_size,
398  int* err )
399 {
400  CHK_PAIR();
401 
402  int iface_no = ( switch_order ? 1 : 0 );
403  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 ) );
404 
405  KEEP_ARRAY( set_array_2 );
407 }
408 
410  iRel_PairHandle pair,
411  iBase_EntitySetHandle* set_array_1,
412  int set_array_1_size,
413  int switch_order,
414  iBase_EntityHandle** ent_array_2,
415  int* ent_array_2_allocated,
416  int* ent_array_2_size,
417  int* err )
418 {
419  CHK_PAIR();
420 
421  int iface_no = ( switch_order ? 1 : 0 );
422  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 ) );
423 
424  KEEP_ARRAY( ent_array_2 );
426 }
427 
429  iRel_PairHandle pair,
430  iBase_EntitySetHandle* set_array_1,
431  int set_array_1_size,
432  int switch_order,
433  iBase_EntitySetHandle** set_array_2,
434  int* set_array_2_allocated,
435  int* set_array_2_size,
436  int* err )
437 {
438  CHK_PAIR();
439 
440  int iface_no = ( switch_order ? 1 : 0 );
441  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 ) );
442 
443  KEEP_ARRAY( set_array_2 );
445 }
446 
448  iRel_PairHandle pair,
449  iBase_EntityHandle* ent_array_1,
450  int ent_array_1_size,
451  int switch_order,
452  iBase_EntityIterator** entiter,
453  int* entiter_allocated,
454  int* entiter_size,
455  int* err )
456 {
457  CHK_PAIR();
458 
459  int iface_no = ( switch_order ? 1 : 0 );
460  ;
461  ALLOC_CHECK_ARRAY( entiter, ent_array_1_size );CHK_ERROR( ASSOCPAIRI->get_relation( iface_no, ent_array_1, ent_array_1_size, *entiter ) );
462 
463  KEEP_ARRAY( entiter );
465 }
466 
468  /*in*/ iRel_PairHandle pair,
469  /*in*/ iBase_EntityHandle ent,
470  /*in*/ int switch_order,
471  /*out*/ int* err )
472 {
473  CHK_PAIR();
474 
475  int iface_no = ( switch_order ? 1 : 0 );CHK_ERROR( ASSOCPAIRI->rmv_relation( iface_no, &ent, 1 ) );
476 }
477 
479  /*in*/ iRel_PairHandle pair,
480  /*in*/ iBase_EntitySetHandle entset,
481  /*in*/ int switch_order,
482  /*out*/ int* err )
483 {
484  CHK_PAIR();
485 
486  int iface_no = ( switch_order ? 1 : 0 );CHK_ERROR( ASSOCPAIRI->rmv_relation( iface_no, &entset, 1 ) );
487 }
488 
490  /*in*/ iRel_PairHandle pair,
491  /*in*/ iBase_EntityHandle* ent_array,
492  /*in*/ int num_ent,
493  /*in*/ int switch_order,
494  /*out*/ int* err )
495 {
496  CHK_PAIR();
497 
498  int iface_no = ( switch_order ? 1 : 0 );CHK_ERROR( ASSOCPAIRI->rmv_relation( iface_no, ent_array, num_ent ) );
499 }
500 
502  /*in*/ iRel_PairHandle pair,
503  /*in*/ iBase_EntitySetHandle* entset_array,
504  /*in*/ int num_ent,
505  /*in*/ int switch_order,
506  /*out*/ int* err )
507 {
508  CHK_PAIR();
509 
510  int iface_no = ( switch_order ? 1 : 0 );CHK_ERROR( ASSOCPAIRI->rmv_relation( iface_no, entset_array, num_ent ) );
511 }
512 
514  int iface_no,
515  iBase_EntityHandle* ents,
516  int ents_size,
517  int ent_or_set,
518  std::vector< int >& ents_gids,
519  std::vector< int >& ents_dims )
520 {
521  int result;
522  iBase_EntitySetHandle* sets = reinterpret_cast< iBase_EntitySetHandle* >( ents );
523 
524  ents_gids.resize( ents_size );
525  if( ent_or_set == iRel_ENTITY )
526  result = ASSOCPAIRI->get_gids( iface_no, ents, ents_size, &ents_gids[0] );
527  else
528  result = ASSOCPAIRI->get_gids( iface_no, sets, ents_size, &ents_gids[0] );
529 
530  if( iBase_SUCCESS != result && iBase_TAG_NOT_FOUND != result ) return result;
531 
532  ents_dims.resize( ents_size, -1 );
533  if( ent_or_set == iRel_ENTITY )
534  {
535  int* ents_dims_ptr = &ents_dims[0];
536  int ents_dims_alloc = ents_dims.size(), ents_dims_size;
537  result =
538  ASSOCPAIRI->get_ents_dims( iface_no, ents, ents_size, &ents_dims_ptr, &ents_dims_alloc, &ents_dims_size );
539  }
540  else
541  {
542  result = ASSOCPAIRI->get_dims( iface_no, sets, ents_size, &ents_dims[0] );
543  }
544 
545  if( iBase_SUCCESS != result && iBase_TAG_NOT_FOUND != result ) return result;
546 
547  return iBase_SUCCESS;
548 }
549 
551  iRel_PairHandle pair,
552  iBase_EntityHandle* ents1,
553  const int ents1_size,
554  int ent_or_set1,
555  iBase_EntityHandle* ents2,
556  const int ents2_size,
557  int ent_or_set2,
558  int* err )
559 {
560  int result;
561 
562  std::vector< int > ents_gids, ents_dims;
563  std::map< const int, iBase_EntityHandle > ents_gid_map[4];
564 
565  get_gids_and_dims( pair, 0, ents1, ents1_size, ent_or_set1, ents_gids, ents_dims );
566  for( int i = 0; i < ents1_size; i++ )
567  {
568  int dim = ents_dims[i];
569  if( 0 <= dim && 3 >= dim ) ents_gid_map[dim][ents_gids[i]] = ents1[i];
570  }
571 
572  get_gids_and_dims( pair, 1, ents2, ents2_size, ent_or_set2, ents_gids, ents_dims );
573  for( int i = 0; i < ents2_size; i++ )
574  {
575  int dim = ents_dims[i];
576 
577  // only check entities for which the dimension entry is in a reasonable
578  // range
579  if( 0 > dim || 3 < dim ) continue;
580 
581  // there's a match if there's an entity with that dimension with matching id
582  std::map< const int, iBase_EntityHandle >::iterator iter = ents_gid_map[dim].find( ents_gids[i] );
583 
584  // if it matches, set the relation tags for those entities
585  if( iter != ents_gid_map[dim].end() )
586  {
587  if( ent_or_set1 == iRel_ENTITY && ent_or_set2 == iRel_ENTITY )
588  {
589  result = ASSOCPAIRI->set_relation( ( *iter ).second, ents2[i] );
590  }
591  else if( ent_or_set1 != iRel_ENTITY && ent_or_set2 == iRel_ENTITY )
592  {
593  result = ASSOCPAIRI->set_relation( (iBase_EntitySetHandle)( *iter ).second, ents2[i] );
594  }
595  else if( ent_or_set1 == iRel_ENTITY && ent_or_set2 != iRel_ENTITY )
596  {
597  result = ASSOCPAIRI->set_relation( ( *iter ).second, (iBase_EntitySetHandle)ents2[i] );
598  }
599  else
600  { // ent_or_set1 != iRel_ENTITY && ent_or_set2 != iRel_ENTITY
601  result = ASSOCPAIRI->set_relation( (iBase_EntitySetHandle)( *iter ).second,
602  (iBase_EntitySetHandle)ents2[i] );
603  }
604 
605  CHK_ERROR( result );
606  }
607  }
608 
610 }
611 
613  iRel_PairHandle pair,
614  iBase_EntityHandle* ents1,
615  const int ents1_size,
616  iBase_EntityHandle* ents2,
617  const int ents2_size,
618  int* err )
619 {
620  iRel_inferArrArrRelations( instance, pair, ents1, ents1_size, 0, ents2, ents2_size, 0, err );
621 }
622 
624  iRel_PairHandle pair,
625  iBase_EntityHandle* ents1,
626  const int ents1_size,
627  iBase_EntitySetHandle* ents2,
628  const int ents2_size,
629  int* err )
630 {
631  iRel_inferArrArrRelations( instance, pair, ents1, ents1_size, 0, (iBase_EntityHandle*)ents2, ents2_size, 1, err );
632 }
633 
635  iRel_PairHandle pair,
636  iBase_EntitySetHandle* ents1,
637  const int ents1_size,
638  iBase_EntityHandle* ents2,
639  const int ents2_size,
640  int* err )
641 {
642  iRel_inferArrArrRelations( instance, pair, (iBase_EntityHandle*)ents1, ents1_size, 1, ents2, ents2_size, 0, err );
643 }
644 
646  iRel_PairHandle pair,
647  iBase_EntitySetHandle* ents1,
648  const int ents1_size,
649  int /*is_set1*/,
650  iBase_EntitySetHandle* ents2,
651  const int ents2_size,
652  int /*is_set2*/,
653  int* err )
654 
655 {
656  iRel_inferArrArrRelations( instance, pair, (iBase_EntityHandle*)ents1, ents1_size, 1, (iBase_EntityHandle*)ents2,
657  ents2_size, 1, err );
658 }
659 
660 void iRel_inferAllRelations( iRel_Instance instance, iRel_PairHandle pair, int* err )
661 {
662  CHK_PAIR();
663 
664  // get all entities in those interfaces
665  int result;
666 
667  iBase_EntityHandle* ents1 = NULL;
668  int ents1_alloc = 0, ents1_size;
669  if( ASSOCPAIRI->relation_type( 0 ) != iRel_ENTITY )
670  result = ASSOCPAIRI->get_all_sets( 0, (iBase_EntitySetHandle**)&ents1, &ents1_alloc, &ents1_size );
671  else
672  result = ASSOCPAIRI->get_all_entities( 0, -1, &ents1, &ents1_alloc, &ents1_size );CHK_ERROR( result );
673 
674  iBase_EntityHandle* ents2 = NULL;
675  int ents2_alloc = 0, ents2_size;
676  if( ASSOCPAIRI->relation_type( 1 ) != iRel_ENTITY )
677  result = ASSOCPAIRI->get_all_sets( 1, (iBase_EntitySetHandle**)&ents2, &ents2_alloc, &ents2_size );
678  else
679  result = ASSOCPAIRI->get_all_entities( 1, -1, &ents2, &ents2_alloc, &ents2_size );CHK_ERROR( result );
680 
681  iRel_inferArrArrRelations( instance, pair, ents1, ents1_size, ASSOCPAIRI->relation_type( 0 ), ents2, ents2_size,
682  ASSOCPAIRI->relation_type( 1 ), &result );
683 
684  free( ents1 );
685  free( ents2 );CHK_ERROR( result );
686 }
687 
688 void iRel_inferAllRelationsAndType( iRel_Instance instance, iRel_PairHandle* /*pair*/, int* err )
689 {
690  ERROR( iBase_NOT_SUPPORTED, "Not currently supported." );
691 }
692 
694  iRel_PairHandle pair,
695  iBase_EntityHandle entity,
696  int iface_no,
697  int* err )
698 {
699  iRel_inferEntArrRelations( instance, pair, &entity, 1, iface_no, err );
700 }
701 
703  iRel_PairHandle pair,
704  iBase_EntitySetHandle entity,
705  int iface_no,
706  int* err )
707 {
708  iRel_inferSetArrRelations( instance, pair, &entity, 1, iface_no, err );
709 }
710 
711 static void iRel_inferArrRelations( iRel_Instance instance,
712  iRel_PairHandle pair,
714  int entities_size,
715  bool is_set,
716  int iface_no,
717  int* err )
718 {
719  CHK_PAIR();
720 
721  if( 0 > iface_no || 1 < iface_no )
722  {
723  ERROR( iBase_INVALID_ARGUMENT, "Interface number must be 0 or 1" );
724  }
725  else if( ( is_set && ASSOCPAIRI->relation_type( iface_no ) == iRel_ENTITY ) ||
726  ( !is_set && ASSOCPAIRI->relation_type( iface_no ) != iRel_ENTITY ) )
727  {
728  ERROR( iBase_INVALID_ARGUMENT, "is_set must match entOrSet in call to "
729  "inferArrRelations" );
730  }
731 
732  // get all entities in iface2
733  int result;
734  iBase_EntityHandle* ents1 = entities;
735  int ents1_size = entities_size;
736  iBase_EntityHandle* ents2 = NULL;
737  int ents2_alloc = 0, ents2_size;
738  if( ASSOCPAIRI->relation_type( 1 - iface_no ) != iRel_ENTITY )
739  result = ASSOCPAIRI->get_all_sets( !iface_no, (iBase_EntitySetHandle**)&ents2, &ents2_alloc, &ents2_size );
740  else
741  result = ASSOCPAIRI->get_all_entities( !iface_no, -1, &ents2, &ents2_alloc, &ents2_size );CHK_ERROR( result );
742 
743  // switch so that entity lists always go into inferArrArrRelations in
744  // forward order wrt pair
745  if( 1 == iface_no )
746  {
747  std::swap( ents1, ents2 );
748  std::swap( ents1_size, ents2_size );
749  }
750 
751  iRel_inferArrArrRelations( instance, pair, ents1, ents1_size, ASSOCPAIRI->relation_type( 0 ), ents2, ents2_size,
752  ASSOCPAIRI->relation_type( 1 ), &result );
753 
754  free( 1 == iface_no ? ents1 : ents2 );
755 
756  CHK_ERROR( result );
757 }
758 
760  iRel_PairHandle pair,
762  int entities_size,
763  int iface_no,
764  int* err )
765 {
766  iRel_inferArrRelations( instance, pair, entities, entities_size, false, iface_no, err );
767 }
768 
770  iRel_PairHandle pair,
772  int entities_size,
773  int iface_no,
774  int* err )
775 {
776  iRel_inferArrRelations( instance, pair, (iBase_EntityHandle*)entities, entities_size, true, iface_no, err );
777 }