00001 // This is gel/vtol/vtol_chain.cxx 00002 #include "vtol_chain.h" 00003 //: 00004 // \file 00005 00006 #include <vcl_cassert.h> 00007 00008 //*************************************************************************** 00009 // Initialization 00010 //*************************************************************************** 00011 00012 //--------------------------------------------------------------------------- 00013 // Default constructor 00014 //--------------------------------------------------------------------------- 00015 vtol_chain::vtol_chain(void) 00016 { 00017 } 00018 00019 //--------------------------------------------------------------------------- 00020 // Destructor 00021 //--------------------------------------------------------------------------- 00022 vtol_chain::~vtol_chain() 00023 { 00024 } 00025 00026 //*************************************************************************** 00027 // Access 00028 //*************************************************************************** 00029 00030 //--------------------------------------------------------------------------- 00031 //: Return a pointer to the inferiors (no copy) 00032 //--------------------------------------------------------------------------- 00033 const chain_list * 00034 vtol_chain::chain_inferiors(void) const 00035 { 00036 return &chain_inferiors_; 00037 } 00038 00039 //--------------------------------------------------------------------------- 00040 //: Return a copy of the chain_superiors list 00041 // The return value must be deleted by the caller 00042 // 00043 // Deprecated. 00044 //--------------------------------------------------------------------------- 00045 const chain_list * 00046 vtol_chain::chain_superiors(void) const 00047 { 00048 chain_list *result=new chain_list; 00049 result->reserve(chain_superiors_.size()); 00050 vcl_list<vtol_chain*>::const_iterator i; 00051 for (i=chain_superiors_.begin();i!=chain_superiors_.end();i++) 00052 result->push_back(*i); 00053 return result; 00054 } 00055 00056 //*************************************************************************** 00057 // Status report 00058 //*************************************************************************** 00059 00060 //--------------------------------------------------------------------------- 00061 //: Is `inferior' already an inferior of `this' ? 00062 //--------------------------------------------------------------------------- 00063 bool 00064 vtol_chain::is_chain_inferior(vtol_chain_sptr chain_inferior) const 00065 { 00066 chain_list::const_iterator i; 00067 00068 for (i=chain_inferiors_.begin(); 00069 i!=chain_inferiors_.end() && (*i)!=chain_inferior; 00070 ++i) 00071 ; 00072 return i!=chain_inferiors_.end(); 00073 } 00074 00075 //--------------------------------------------------------------------------- 00076 //: Is `superior' already a superior of `this' ? 00077 //--------------------------------------------------------------------------- 00078 bool 00079 vtol_chain::is_chain_superior(vtol_chain const* chain_superior) const 00080 { 00081 vcl_list<vtol_chain*>::const_iterator i; 00082 for (i=chain_superiors_.begin(); 00083 i!=chain_superiors_.end() && (*i)!=chain_superior; 00084 ++i) 00085 /*nothing*/; 00086 00087 return i!=chain_superiors_.end(); 00088 } 00089 00090 //*************************************************************************** 00091 // Basic operations 00092 //*************************************************************************** 00093 00094 //--------------------------------------------------------------------------- 00095 //: Link `this' with an inferior `chain_inferior' 00096 // Require: valid_chain_type(chain_inferior) 00097 // and !is_chain_inferior(chain_inferior) 00098 //--------------------------------------------------------------------------- 00099 void vtol_chain::link_chain_inferior(vtol_chain_sptr chain_inferior) 00100 { 00101 // require 00102 assert(valid_chain_type(chain_inferior)); 00103 assert(!is_chain_inferior(chain_inferior)); 00104 assert(!chain_inferior->is_chain_superior(this)); 00105 00106 chain_inferiors_.push_back(chain_inferior); 00107 chain_inferior->chain_superiors_.push_back(this); 00108 touch(); 00109 } 00110 00111 //--------------------------------------------------------------------------- 00112 //: Unlink `this' with the chain_inferior `chain_inferior' 00113 // Require: valid_chain_type(chain_inferior) 00114 // and is_chain_inferior(chain_inferior) 00115 //--------------------------------------------------------------------------- 00116 void vtol_chain::unlink_chain_inferior(vtol_chain_sptr chain_inferior) 00117 { 00118 // require 00119 assert(valid_chain_type(chain_inferior)); 00120 assert(is_chain_inferior(chain_inferior)); 00121 assert(chain_inferior->is_chain_superior(this)); 00122 00123 vcl_list<vtol_chain*>::iterator i=chain_inferior->chain_superiors_.begin(); 00124 while ( i!=chain_inferior->chain_superiors_.end() && *i!=this ) ++i; 00125 // check presence in "chain_superiors_" list of chain_inferior: 00126 assert(*i==this); 00127 00128 // unlink "this" from chain_superiors_ list of chain_inferior: 00129 chain_inferior->chain_superiors_.erase(i); 00130 00131 chain_list::iterator j=chain_inferiors_.begin(); 00132 while ( j!=chain_inferiors_.end() && (*j)!=chain_inferior ) ++j; 00133 // check presence in "chain_inferiors_" list: 00134 assert((*j)==chain_inferior); 00135 00136 chain_inferiors_.erase(j); 00137 touch(); 00138 } 00139 00140 //--------------------------------------------------------------------------- 00141 //: Unlink `this' with all its chain inferiors 00142 //--------------------------------------------------------------------------- 00143 void vtol_chain::unlink_all_chain_inferiors(void) 00144 { 00145 while (chain_inferiors_.size()>0) 00146 unlink_chain_inferior(chain_inferiors_.back()); 00147 } 00148 00149 //--------------------------------------------------------------------------- 00150 //: Unlink `this' of the network 00151 //--------------------------------------------------------------------------- 00152 void vtol_chain::unlink(void) 00153 { 00154 while (chain_superiors_.size()>0) 00155 chain_superiors_.front()->unlink_chain_inferior(this); 00156 unlink_all_chain_inferiors(); 00157 vtol_topology_object::unlink(); 00158 } 00159 00160 //--------------------------------------------------------------------------- 00161 //: Is `this' a connected chain ? 00162 //--------------------------------------------------------------------------- 00163 bool vtol_chain::is_cycle(void) const 00164 { 00165 return is_cycle_; 00166 } 00167 00168 //--------------------------------------------------------------------------- 00169 //: Reset the chain 00170 //--------------------------------------------------------------------------- 00171 void vtol_chain::clear(void) 00172 { 00173 directions_.clear(); 00174 unlink_all_chain_inferiors(); 00175 }