1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// Class: ToolDataUser<--- Skipping configuration 'DBL_MAX' since the value of 'DBL_MAX' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'DBL_MIN' since the value of 'DBL_MIN' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.<--- Skipping configuration 'M_PI' since the value of 'M_PI' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.

#include <cassert>
#include "ToolDataUser.hpp"
#include "ToolData.hpp"
#include "DLIList.hpp"

ToolData *ToolDataUser::remove_TD( IdentityFn specified_type )
{
  ToolData *td = tool_data();
  ToolData *td_prev = NULL;
  while (td) {
    if ( (*specified_type)(td) ) {
      if (td_prev)
        td_prev->next_tool_data( td->next_tool_data() );
      else
        toolData = td->next_tool_data();
      td->next_tool_data( NULL );
      return td;
    }
    td_prev = td;
    td = td->next_tool_data();
  }
  return NULL;
}

ToolData *ToolDataUser::remove_TD( ToolData *td_remove )
{
  ToolData *td = tool_data();
  ToolData *td_prev = NULL;
  while (td) {
    if ( td_remove == td ) {
      if (td_prev)
        td_prev->next_tool_data( td->next_tool_data() );
      else
        toolData = td->next_tool_data();
      td->next_tool_data( NULL );
      return td;
    }
    td_prev = td;
    td = td->next_tool_data();
  }
  return NULL;
}

CubitBoolean ToolDataUser::delete_TD( IdentityFn specified_type )
{
  ToolData *td = remove_TD( specified_type );
  if (td)
  {
    delete td;
    return CUBIT_TRUE;
  }
  return CUBIT_FALSE;
}

CubitBoolean ToolDataUser::delete_TD( ToolData *td_remove )
{
  ToolData *td = remove_TD( td_remove );
  if (td)
  {
    delete td;
    return CUBIT_TRUE;
  }
  return CUBIT_FALSE;
}

void ToolDataUser::add_TD( ToolData *new_td )
{
  assert( new_td != NULL );
  new_td->next_tool_data( toolData );
  toolData = new_td;
}

ToolData *ToolDataUser::get_TD( IdentityFn specified_type )
{
  ToolData *td = tool_data();
  while (td) {
    if ( (*specified_type)(td) ) 
      return td;
    td = td->next_tool_data();
  }
  return NULL;
}

ToolData const* ToolDataUser::get_TD( IdentityFn specified_type ) const
{
  ToolData *td = tool_data();
  while (td) {
    if ( (*specified_type)(td) ) 
      return td;
    td = td->next_tool_data();
  }
  return NULL;
}

void ToolDataUser::get_all_TDs(IdentityFn specified_type, 
                               DLIList <ToolData *> *all_tds) const
{
  ToolData *td = tool_data();
  while (td) 
  {
    if ( (*specified_type)(td) ) 
      all_tds->append(td);
    td = td->next_tool_data();
  }  
}

void ToolDataUser::get_all_TDs(DLIList <ToolData *> *all_tds) const
{
  ToolData *td = tool_data();
  while (td) 
  {
    all_tds->append(td);
    td = td->next_tool_data();
  }  
}

ToolDataUser::~ToolDataUser()
{
  //delete all ToolData's chained off this user.
  ToolData *td = tool_data();
  while ( td ) {
    ToolData *next = td->next_tool_data();
    delete td;
    td = next;
  }

    // set the first TD to NULL
  tool_data(NULL);
}