BWAPI
SPAR/AIModule/BWTA/vendors/CGAL/CGAL/Sweep_line_2/Sweep_line_curve_pair.h
Go to the documentation of this file.
00001 // Copyright (c) 2006  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/Sweep_line_2/Sweep_line_curve_pair.h $
00015 // $Id: Sweep_line_curve_pair.h 40154 2007-09-02 16:49:16Z golubevs $
00016 // 
00017 //
00018 // Author(s)     : Baruch Zukerman <baruchzu@post.tau.ac.il>
00019 //                 Ron Wein <wein@post.tau.ac.il>
00020 
00021 #ifndef CGAL_SWEEP_LINE_CURVE_PAIR_H
00022 #define CGAL_SWEEP_LINE_CURVE_PAIR_H
00023 
00028 CGAL_BEGIN_NAMESPACE
00029 
00033 template <class Subcurve_>
00034 class Curve_pair
00035 {
00036 public:
00037 
00038   typedef Subcurve_                      Subcurve;
00039 
00040 private:
00041 
00042   // Data members:
00043   std::pair<Subcurve*, Subcurve*>    m_pair;
00044 
00045 public:
00046 
00048   Curve_pair(){}
00049 
00051   Curve_pair (Subcurve *sc1, Subcurve *sc2)
00052   {
00053     // The smallest pointer will be the first. 
00054     if(sc1 < sc2)
00055       m_pair = std::make_pair (sc1,sc2);
00056     else
00057       m_pair = std::make_pair (sc2,sc1);
00058   }
00059 
00061   Subcurve* first() const
00062   {
00063     return (m_pair.first);
00064   }
00065 
00067   Subcurve* second() const
00068   {
00069     return (m_pair.second);
00070   }
00071 };
00072 
00076 template <class Subcurve_>
00077 struct Less_curve_pair
00078 {
00079   typedef Subcurve_               Subcurve;
00080   typedef class Curve_pair<Subcurve>   Curve_pair;
00081 
00082   bool operator() (const Curve_pair& pair1, const Curve_pair& pair2) const
00083   {
00084     if (pair1.first() < pair2.first())
00085       return true;
00086     if (pair1.first() > pair2.first())
00087       return false;
00088     if (pair1.second() < pair2.second())
00089       return true;
00090     return false;
00091   }
00092 };
00093 
00097 template <class Subcurve_>
00098 struct Curve_pair_hasher
00099 {
00100   typedef Subcurve_               Subcurve;
00101   typedef class Curve_pair<Subcurve>   Curve_pair;
00102 
00103   size_t operator() (const Curve_pair& pair) const
00104   {
00105     const size_t  half_n_bits = sizeof(size_t) * 8 / 2;
00106     const size_t  val1 = reinterpret_cast<size_t> (pair.first());
00107     const size_t  val2 = reinterpret_cast<size_t> (pair.second());
00108 
00109     return (((val1 << half_n_bits) | (val1 >> half_n_bits)) ^ val2);
00110   }
00111 };
00112 
00116 template <class Subcurve_>
00117 struct Equal_curve_pair
00118 {
00119   typedef Subcurve_               Subcurve;
00120   typedef class Curve_pair<Subcurve>   Curve_pair;
00121 
00122   bool operator() (const Curve_pair& pair1, const Curve_pair& pair2) const
00123   {
00124     return (pair1.first() == pair2.first() &&
00125             pair1.second() == pair2.second());
00126   }
00127 };
00128 
00132 template <class Container_>
00133 class random_access_input_iterator
00134 {
00135 public:
00136   
00137   typedef Container_                                Container;
00138   typedef typename Container::value_type            value_type;
00139   typedef random_access_input_iterator<Container>   Self;
00140 
00141 private:
00142   
00143   // Data members:
00144   Container          *m_container;      // The container.
00145   unsigned int        m_index;          // The current index.
00146 
00147 public:
00148 
00149   random_access_input_iterator()
00150   {}
00151 
00152   random_access_input_iterator (Container& _container,
00153                                 unsigned int _index = 0):
00154     m_container(&_container),
00155     m_index(_index)
00156   {}
00157 
00158   value_type& operator*()
00159   {
00160     if(m_index >= m_container->capacity())
00161     {
00162       m_container->reserve(2 * m_index + 1);
00163       m_container->resize(m_index+1);
00164     }
00165     else
00166       if(m_index >= m_container->size())
00167          m_container->resize(m_index+1);
00168     return (*m_container)[m_index];
00169   }
00170 
00171   Self& operator++()
00172   {
00173     ++m_index;
00174     return (*this);
00175   }
00176 
00177   Self operator++ (int)
00178   {
00179     Self temp = *this;
00180     ++m_index;
00181     return (temp);
00182   }
00183 
00184   Self& operator--()
00185   {
00186     --m_index;
00187     return (*this);
00188   }
00189 
00190   Self operator-- (int)
00191   {
00192     Self temp = *this;
00193     --m_index;
00194     return (temp);
00195   }
00196 
00197   bool operator== (const Self& other)
00198   {
00199     CGAL_precondition (m_container == other.m_container);
00200     return (m_index == other.m_index);
00201   }
00202 
00203   bool operator!=(const Self& other)
00204   {
00205     CGAL_precondition(m_container == other.m_container);
00206     return !(*this == other);
00207   }
00208 
00209   unsigned int operator-(const Self& other)
00210   {
00211     CGAL_precondition(m_container == other.m_container);
00212     return (m_index - other.m_index);
00213   }
00214 };
00215 
00216 CGAL_END_NAMESPACE
00217 
00218 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines