cgma
ToolDataUser.cpp
Go to the documentation of this file.
00001 // Class: ToolDataUser
00002 
00003 #include <cassert>
00004 #include "ToolDataUser.hpp"
00005 #include "ToolData.hpp"
00006 #include "DLIList.hpp"
00007 
00008 ToolData *ToolDataUser::remove_TD( IdentityFn specified_type )
00009 {
00010   ToolData *td = tool_data();
00011   ToolData *td_prev = NULL;
00012   while (td) {
00013     if ( (*specified_type)(td) ) {
00014       if (td_prev)
00015         td_prev->next_tool_data( td->next_tool_data() );
00016       else
00017         toolData = td->next_tool_data();
00018       td->next_tool_data( NULL );
00019       return td;
00020     }
00021     td_prev = td;
00022     td = td->next_tool_data();
00023   }
00024   return NULL;
00025 }
00026 
00027 ToolData *ToolDataUser::remove_TD( ToolData *td_remove )
00028 {
00029   ToolData *td = tool_data();
00030   ToolData *td_prev = NULL;
00031   while (td) {
00032     if ( td_remove == td ) {
00033       if (td_prev)
00034         td_prev->next_tool_data( td->next_tool_data() );
00035       else
00036         toolData = td->next_tool_data();
00037       td->next_tool_data( NULL );
00038       return td;
00039     }
00040     td_prev = td;
00041     td = td->next_tool_data();
00042   }
00043   return NULL;
00044 }
00045 
00046 CubitBoolean ToolDataUser::delete_TD( IdentityFn specified_type )
00047 {
00048   ToolData *td = remove_TD( specified_type );
00049   if (td)
00050   {
00051     delete td;
00052     return CUBIT_TRUE;
00053   }
00054   return CUBIT_FALSE;
00055 }
00056 
00057 CubitBoolean ToolDataUser::delete_TD( ToolData *td_remove )
00058 {
00059   ToolData *td = remove_TD( td_remove );
00060   if (td)
00061   {
00062     delete td;
00063     return CUBIT_TRUE;
00064   }
00065   return CUBIT_FALSE;
00066 }
00067 
00068 void ToolDataUser::add_TD( ToolData *new_td )
00069 {
00070   assert( new_td != NULL );
00071   new_td->next_tool_data( toolData );
00072   toolData = new_td;
00073 }
00074 
00075 ToolData *ToolDataUser::get_TD( IdentityFn specified_type )
00076 {
00077   ToolData *td = tool_data();
00078   while (td) {
00079     if ( (*specified_type)(td) ) 
00080       return td;
00081     td = td->next_tool_data();
00082   }
00083   return NULL;
00084 }
00085 
00086 ToolData const* ToolDataUser::get_TD( IdentityFn specified_type ) const
00087 {
00088   ToolData *td = tool_data();
00089   while (td) {
00090     if ( (*specified_type)(td) ) 
00091       return td;
00092     td = td->next_tool_data();
00093   }
00094   return NULL;
00095 }
00096 
00097 void ToolDataUser::get_all_TDs(IdentityFn specified_type, 
00098                                DLIList <ToolData *> *all_tds) const
00099 {
00100   ToolData *td = tool_data();
00101   while (td) 
00102   {
00103     if ( (*specified_type)(td) ) 
00104       all_tds->append(td);
00105     td = td->next_tool_data();
00106   }  
00107 }
00108 
00109 void ToolDataUser::get_all_TDs(DLIList <ToolData *> *all_tds) const
00110 {
00111   ToolData *td = tool_data();
00112   while (td) 
00113   {
00114     all_tds->append(td);
00115     td = td->next_tool_data();
00116   }  
00117 }
00118 
00119 ToolDataUser::~ToolDataUser()
00120 {
00121   //delete all ToolData's chained off this user.
00122   ToolData *td = tool_data();
00123   while ( td ) {
00124     ToolData *next = td->next_tool_data();
00125     delete td;
00126     td = next;
00127   }
00128 
00129     // set the first TD to NULL
00130   tool_data(NULL);
00131 }
00132 
00133 
00134 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines