contrib/gel/vtol/vtol_list_functions.txx
Go to the documentation of this file.
00001 #ifndef vtol_list_functions_txx_
00002 #define vtol_list_functions_txx_
00003 //:
00004 // \file
00005 #include "vtol_list_functions.h"
00006 
00007 //: Note if you really want a tagged union...this is it...
00008 // otherwise you can call remove_duplicates and get the
00009 // same result....pav
00010 // Also note that T must be a pointer or smart pointer to a derived class of
00011 // vsol_spatial_object_[23]d as {s,g}et_tagged_union_flag() must exist.
00012 
00013 template <class T>
00014 vcl_vector<T>* tagged_union(vcl_vector<T>* topolist)
00015 {
00016   if (!topolist) return 0; // null pointer invalid
00017   vcl_vector<T> temp;
00018   typename vcl_vector<T>::iterator i;
00019 
00020   // Clearing the tags before processing...
00021   for (i=topolist->begin();i!=topolist->end(); ++i)
00022     (*i)->unset_tagged_union_flag();
00023 
00024   // Performing the Union by looping over
00025   // the elements and removing duplicates.
00026 
00027   for (i=topolist->begin(); i!=topolist->end(); ++i)
00028     if (! (*i)->get_tagged_union_flag())
00029     {
00030       (*i)->set_tagged_union_flag();
00031       temp.push_back(*i);
00032     }
00033   // now overwrite the original list with the new one:
00034   (*topolist)=temp;
00035   return topolist;
00036 }
00037 
00038 template <class T>
00039 vcl_list<T>* tagged_union(vcl_list<T>* topolist)
00040 {
00041   if (!topolist) return 0; // null pointer invalid
00042   vcl_list<T> temp;
00043   typename vcl_list<T>::iterator i;
00044 
00045   // Clearing the tags before processing...
00046   for (i=topolist->begin();i!=topolist->end(); ++i)
00047     (*i)->unset_tagged_union_flag();
00048 
00049   // Performing the Union by looping over
00050   // the elements and removing duplicates.
00051 
00052   for (i=topolist->begin(); i!=topolist->end(); ++i)
00053     if (! (*i)->get_tagged_union_flag())
00054     {
00055       (*i)->set_tagged_union_flag();
00056       temp.push_back(*i);
00057     }
00058   // now overwrite the original list with the new one:
00059   (*topolist)=temp;
00060   return topolist;
00061 }
00062 
00063 #endif // vtol_list_functions_txx_