BWAPI
SPAR/AIModule/BWTA/vendors/CGAL/CGAL/Arr_geometry_traits/Consolidated_curve_data_aux.h
Go to the documentation of this file.
00001 // Copyright (c) 2005  Tel-Aviv University (Israel).
00002 // All rights reserved.
00003 //
00004 // This file is part of CGAL (www.cgal.org); you may redistribute it under
00005 // the terms of the Q Public License version 1.0.
00006 // See the file LICENSE.QPL distributed with CGAL.
00007 //
00008 // Licensees holding a valid commercial license may use this file in
00009 // accordance with the commercial license agreement provided with the software.
00010 //
00011 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00012 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00013 //
00014 // $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/CGAL-3.5-branch/Arrangement_on_surface_2/include/CGAL/Arr_geometry_traits/Consolidated_curve_data_aux.h $
00015 // $Id: Consolidated_curve_data_aux.h 33081 2006-08-07 07:46:37Z wein $
00016 // 
00017 //
00018 // Author(s)     : Ron Wein          <wein@post.tau.ac.il>
00019 //                 Efi Fogel         <efif@post.tau.ac.il>
00020 #ifndef CGAL_CONSOLIDATED_CURVE_DATA_AUX_H
00021 #define CGAL_CONSOLIDATED_CURVE_DATA_AUX_H
00022 
00028 CGAL_BEGIN_NAMESPACE
00029 
00034 template <class Data_>
00035 class _Unique_list
00036 {
00037 public:
00038   typedef Data_                Data;
00039   typedef _Unique_list<Data>   Self;
00040 
00041   typedef typename std::list<Data>::const_iterator  const_iterator;
00042 
00043 private:
00044   
00045   std::list<Data>     m_list;
00046 
00047 public:
00048 
00050   _Unique_list () :
00051     m_list()
00052   {}
00053 
00055   _Unique_list (const Data& data) :
00056     m_list ()
00057   {
00058     m_list.push_back (data);
00059   }
00060 
00062   const_iterator begin () const
00063   {
00064     return (m_list.begin());
00065   }
00066 
00067   const_iterator end () const
00068   {
00069     return (m_list.end());
00070   }
00071 
00073   std::size_t size () const
00074   {
00075     return (m_list.size());
00076   }
00077 
00079   const Data& front () const
00080   {
00081     return (m_list.front());
00082   }
00083 
00084   const Data& back () const
00085   {
00086     return (m_list.back());
00087   }
00088 
00090   bool operator== (const Self& other) const
00091   {
00092     if (size() != other.size())
00093       return (false);
00094 
00095     const_iterator    iter;
00096 
00097     for (iter = begin(); iter != end(); ++iter)
00098     {
00099       if (other.find (*iter) == other.end())
00100         return (false);
00101     }
00102 
00103     for (iter = other.begin(); iter != other.end(); ++iter)
00104     {
00105       if (find (*iter) == end())
00106         return (false);
00107     }
00108 
00109     return (true);
00110   }
00111 
00117   const_iterator find (const Data& data) const
00118   {
00119     const_iterator   iter = m_list.begin();
00120 
00121     while (iter != m_list.end())
00122     {
00123       if (*iter == data)
00124         break;
00125       ++iter;
00126     }
00127     return (iter);
00128   }
00129   
00136   bool insert (const Data& data)
00137   {
00138     if (find (data) != m_list.end())
00139       return (false);
00140 
00141     m_list.push_back (data);
00142     return (true);
00143   }
00144   
00151   bool erase (const Data& data)
00152   {
00153     typename std::list<Data>::iterator  iter = m_list.begin();
00154 
00155     while (iter != m_list.end())
00156     {
00157       if (*iter == data)
00158       {
00159         // Erase the current data object.
00160         m_list.erase (iter);
00161         return (true);
00162       }
00163       ++iter;
00164     }
00165 
00166     // The data object is not found in the list:
00167     return (false);
00168   }
00169 
00171   void clear ()
00172   {
00173     m_list.clear();
00174     return;
00175   }
00176 };
00177 
00181 template <class Data>
00182 struct _Consolidate_unique_lists
00183 {
00184   _Unique_list<Data> operator() (const _Unique_list<Data>& list1,
00185                                  const _Unique_list<Data>& list2) const
00186   {
00187     _Unique_list<Data>  result = list1;
00188 
00189     typename _Unique_list<Data>::const_iterator  iter;
00190 
00191     for (iter = list2.begin(); iter != list2.end(); ++iter)
00192       result.insert (*iter);
00193 
00194     return (result);
00195   }
00196 };
00197 
00198 CGAL_END_NAMESPACE
00199 
00200 #endif
00201 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines