contrib/gel/vtol/vtol_chain.cxx

Go to the documentation of this file.
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 
00086   return i!=chain_superiors_.end();
00087 }
00088 
00089 //***************************************************************************
00090 // Basic operations
00091 //***************************************************************************
00092 
00093 //---------------------------------------------------------------------------
00094 //: Link `this' with an inferior `chain_inferior'
00095 // Require: valid_chain_type(chain_inferior)
00096 //          and !is_chain_inferior(chain_inferior)
00097 //---------------------------------------------------------------------------
00098 void vtol_chain::link_chain_inferior(vtol_chain_sptr chain_inferior)
00099 {
00100   // require
00101   assert(valid_chain_type(chain_inferior));
00102   assert(!is_chain_inferior(chain_inferior));
00103   assert(!chain_inferior->is_chain_superior(this));
00104 
00105   chain_inferiors_.push_back(chain_inferior);
00106   chain_inferior->chain_superiors_.push_back(this);
00107   touch();
00108 }
00109 
00110 //---------------------------------------------------------------------------
00111 //: Unlink `this' with the chain_inferior `chain_inferior'
00112 // Require: valid_chain_type(chain_inferior)
00113 //          and is_chain_inferior(chain_inferior)
00114 //---------------------------------------------------------------------------
00115 void vtol_chain::unlink_chain_inferior(vtol_chain_sptr chain_inferior)
00116 {
00117   // require
00118   assert(valid_chain_type(chain_inferior));
00119   assert(is_chain_inferior(chain_inferior));
00120   assert(chain_inferior->is_chain_superior(this));
00121 
00122   vcl_list<vtol_chain*>::iterator i=chain_inferior->chain_superiors_.begin();
00123   while ( i!=chain_inferior->chain_superiors_.end() && *i!=this ) ++i;
00124   // check presence in "chain_superiors_" list of chain_inferior:
00125   assert(*i==this);
00126 
00127   // unlink "this" from chain_superiors_ list of chain_inferior:
00128   chain_inferior->chain_superiors_.erase(i);
00129 
00130   chain_list::iterator j=chain_inferiors_.begin();
00131   while ( j!=chain_inferiors_.end() && (*j)!=chain_inferior ) ++j;
00132   // check presence in "chain_inferiors_" list:
00133   assert((*j)==chain_inferior);
00134 
00135   chain_inferiors_.erase(j);
00136   touch();
00137 }
00138 
00139 //---------------------------------------------------------------------------
00140 //: Unlink `this' with all its chain inferiors
00141 //---------------------------------------------------------------------------
00142 void vtol_chain::unlink_all_chain_inferiors(void)
00143 {
00144   while (chain_inferiors_.size()>0)
00145     unlink_chain_inferior(chain_inferiors_.back());
00146 }
00147 
00148 //---------------------------------------------------------------------------
00149 //: Unlink `this' of the network
00150 //---------------------------------------------------------------------------
00151 void vtol_chain::unlink(void)
00152 {
00153   while (chain_superiors_.size()>0)
00154     chain_superiors_.front()->unlink_chain_inferior(this);
00155   unlink_all_chain_inferiors();
00156   vtol_topology_object::unlink();
00157 }
00158 
00159 //---------------------------------------------------------------------------
00160 //: Is `this' a connected chain ?
00161 //---------------------------------------------------------------------------
00162 bool vtol_chain::is_cycle(void) const
00163 {
00164   return is_cycle_;
00165 }
00166 
00167 //---------------------------------------------------------------------------
00168 //: Reset the chain
00169 //---------------------------------------------------------------------------
00170 void vtol_chain::clear(void)
00171 {
00172   directions_.clear();
00173   unlink_all_chain_inferiors();
00174 }

Generated on Tue Dec 2 05:15:29 2008 for contrib/gel/vtol by  doxygen 1.5.1