LCOV - code coverage report
Current view: top level - geom - TDCAGE.cpp (source / functions) Hit Total Coverage
Test: coverage_sk.info Lines: 39 50 78.0 %
Date: 2020-06-30 00:58:45 Functions: 7 7 100.0 %
Branches: 38 94 40.4 %

           Branch data     Line data    Source code
       1                 :            : #include "TDCAGE.hpp"
       2                 :            : #include "RefGroup.hpp"
       3                 :            : #include "RefEntity.hpp"
       4                 :            : #include "DLIList.hpp"
       5                 :            : #include "CastTo.hpp"
       6                 :            : 
       7                 :         11 : int TDCAGE::is_cage(const ToolData* td)
       8                 :            : {
       9 [ +  - ][ +  - ]:         11 :   return (CAST_TO(const_cast<ToolData*>(td), TDCAGE) != NULL);
      10                 :            : }
      11                 :            : 
      12                 :            : 
      13                 :         11 : int TDCAGE::td_sequence_number(const RefGroup *group)
      14                 :            : {
      15                 :            :     // go through the group list and get the sequence number;
      16                 :            :     // return -1 if the group isn't in the list
      17                 :            : 
      18                 :         11 :   groupList.reset();
      19                 :         11 :   sequenceList.reset();
      20         [ +  - ]:         11 :   for (int i = groupList.size(); i > 0; i--) {
      21         [ +  - ]:         11 :     if (group == groupList.get_and_step()) return sequenceList.get();
      22                 :            : 
      23                 :          0 :     else sequenceList.step();
      24                 :            :   }
      25                 :            :   
      26                 :          0 :   return -1;
      27                 :            : }
      28                 :            : 
      29                 :         11 : void TDCAGE::insert_entity(RefEntity *entity, const int seq_num,
      30                 :            :                            RefGroup *into_group)
      31                 :            : {
      32                 :            :     //- insert the entity into the group following the sequence number
      33                 :            :     //- given
      34                 :            :   TDCAGE *td_cage;
      35                 :         11 :   CubitBoolean inserted = CUBIT_FALSE;
      36         [ +  - ]:         11 :   DLIList<RefEntity*> copy_group_list;
      37         [ +  - ]:         11 :   copy_group_list = into_group->entityList;
      38                 :            :   
      39         [ +  - ]:         11 :   into_group->entityList.last();
      40 [ +  - ][ -  + ]:         11 :   for (int i = into_group->entityList.size(); i > 0; i--) {
      41         [ #  # ]:          0 :     RefEntity *into_entity = into_group->entityList.get();
      42         [ #  # ]:          0 :     td_cage = (TDCAGE *) into_entity->get_TD(&TDCAGE::is_cage);
      43 [ #  # ][ #  # ]:          0 :     if (td_cage && td_cage->td_sequence_number(into_group) < seq_num) {
         [ #  # ][ #  # ]
      44 [ #  # ][ #  # ]:          0 :           if ( !copy_group_list.move_to(entity) )
      45         [ #  # ]:          0 :         into_group->entityList.insert(entity);
      46                 :          0 :       inserted = CUBIT_TRUE;
      47                 :          0 :       break;
      48                 :            :     }
      49         [ #  # ]:          0 :     else into_group->entityList.back();
      50                 :            :   }
      51                 :            :   
      52                 :            :     // if we got here and didn't insert, either the list is empty
      53                 :            :     // or it isn't and our seq_num is less than all items; either
      54                 :            :     // way, we insert at beginning
      55         [ +  - ]:         11 :   if (inserted == CUBIT_FALSE){
      56 [ +  - ][ +  - ]:         11 :           if ( !copy_group_list.move_to(entity) )
      57         [ +  - ]:         11 :             into_group->entityList.insert_first(entity);
      58                 :            :   }
      59                 :            : 
      60                 :            :     // now register the observable entity in the group
      61 [ +  - ][ +  - ]:         11 :   into_group->register_observable(entity);
      62                 :            : 
      63                 :            :     // now, make sure the inserted entity has a td_cage and this group
      64                 :            :     // and seq number are registered
      65         [ +  - ]:         11 :   td_cage = (TDCAGE *) entity->get_TD(&TDCAGE::is_cage);
      66         [ +  - ]:         11 :   if (!td_cage) {
      67 [ +  - ][ +  - ]:         11 :     td_cage = new TDCAGE(-1);
      68         [ +  - ]:         11 :     entity->add_TD(td_cage);
      69                 :            :   }
      70                 :            :   
      71 [ +  - ][ +  - ]:         11 :   td_cage->insert_group(into_group, seq_num);
      72                 :         11 : }
      73                 :            : 
      74                 :         11 : int TDCAGE::group_sequence_number(RefGroup *group, const RefEntity *entity)
      75                 :            : {
      76                 :            :     //- return the sequence number of the given entity in the given group
      77                 :            : 
      78                 :            :     // built for speed; don't accumulate index, use loop counter for that
      79                 :         11 :   group->entityList.reset();
      80         [ +  - ]:         11 :   for (int i = group->entityList.size(); i > 0; i--) {
      81         [ +  - ]:         11 :     if (group->entityList.get_and_step() == entity)
      82                 :            :         // index in reverse direction, so subtract to get real index
      83                 :         11 :       return group->entityList.size() - i;
      84                 :            :   }
      85                 :            :   
      86                 :          0 :   return -1;
      87                 :            : }
      88                 :            : 
      89                 :         22 : void TDCAGE::initialize_group_sequence_list(RefEntity *entity) 
      90                 :            : {
      91                 :            :     //- get the groups owning entity and build the sequence lists
      92         [ +  - ]:         22 :   DLIList<RefGroup*> ref_groups;
      93         [ +  - ]:         22 :   RefGroup::get_groups_within(entity, ref_groups, CUBIT_FALSE);
      94                 :            : 
      95         [ +  - ]:         22 :   groupList.clean_out();
      96         [ +  - ]:         22 :   sequenceList.clean_out();
      97                 :            :   
      98 [ +  - ][ +  + ]:         33 :   for (int i = ref_groups.size(); i > 0; i--) {
      99         [ +  - ]:         11 :     RefGroup *ref_group = ref_groups.get_and_step();
     100         [ +  - ]:         11 :     groupList.append(ref_group);
     101 [ +  - ][ +  - ]:         11 :     sequenceList.append(group_sequence_number(ref_group, entity));
     102         [ +  - ]:         22 :   }
     103 [ +  - ][ +  - ]:       6562 : }
     104                 :            : 
     105                 :            :     
     106                 :            :   

Generated by: LCOV version 1.11