BWAPI
SPAR/AIModule/BWTA/vendors/CGAL/CGAL/Tools/Counter.h
Go to the documentation of this file.
00001 // Copyright (c) 2005  Stanford University (USA).
00002 // All rights reserved.
00003 //
00004 // This file is part of CGAL (www.cgal.org); you can redistribute it and/or
00005 // modify it under the terms of the GNU Lesser General Public License as
00006 // published by the Free Software Foundation; version 2.1 of the License.
00007 // See the file LICENSE.LGPL distributed with CGAL.
00008 //
00009 // Licensees holding a valid commercial license may use this file in
00010 // accordance with the commercial license agreement provided with the software.
00011 //
00012 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00013 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00014 //
00015 // $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/CGAL-3.5-branch/Kinetic_data_structures/include/CGAL/Tools/Counter.h $
00016 // $Id: Counter.h 36338 2007-02-15 21:30:59Z spion $
00017 // 
00018 //
00019 // Author(s)     : Daniel Russel <drussel@alumni.princeton.edu>
00020 
00021 #ifndef CGAL_DSR_COUNTER_H
00022 #define CGAL_DSR_COUNTER_H
00023 
00024 #include <iterator>
00025 #include <CGAL/basic.h>
00026 #include <CGAL/Tools/Label.h>
00027 
00028 CGAL_BEGIN_NAMESPACE
00029 
00031 
00036 template <class T=int, class W=T>
00037 class Counter
00038 {
00039     typedef Counter<T, W> This;
00040     public:
00041         Counter(T t=0):t_(t) {
00042         }
00043         This &operator++() {
00044             ++t_;
00045             return *this;
00046         }
00047         This operator++(int) {
00048             This ret= *this;
00049             ++t_;
00050             return ret;
00051         }
00053         W operator*() const
00054         {
00055             return W(t_);
00056         }
00058         W* operator->() const
00059         {
00060             static W ret;
00061             ret=W(t_);
00062             return &ret;
00063         }
00064         bool operator==(const This &o) const
00065         {
00066             return t_ == o.t_;
00067         }
00068         bool operator!=(const This &o) const
00069         {
00070             return t_ != o.t_;
00071         }
00072         bool operator<(const This &o) const
00073         {
00074             return t_ < o.t_;
00075         }
00076         T operator-(const This &o) const
00077         {
00078             return t_-o.t_;
00079         }
00080 /*const This& operator+=(T &v) {
00081   t_+=v;
00082   return *this;
00083   }*/
00084         const This& operator+=(unsigned int v) {
00085             t_+=v;
00086             return *this;
00087         }
00088         const This& operator-=(T &v) {
00089             t_-=v;
00090             return *this;
00091         }
00093         template <class J>
00094         void operator()(const J&) {
00095             ++*this;
00096         }
00097         typedef std::random_access_iterator_tag iterator_category;
00098         typedef W value_type;
00099         typedef T difference_type;
00100         typedef W* pointer;
00101         typedef W& reference;
00102     protected:
00103         T t_;
00104 };
00105 
00107 
00110 /*template <>
00111 template <class LT>
00112 class Counter<int, Label<LT> >{
00113   typedef Label<LT> Label;
00114   typedef Counter<int, Label > This;
00115 public:
00116 
00117   Counter(int t=0):t_(t){
00118   }
00119   This &operator++(){
00120     t_= Label(t_.index()+1);
00121 return *this;
00122 }
00123 This operator++(int){
00124 This ret= *this;
00125 t_= Label(t_.index()+1);;
00126 return ret;
00127 }
00128 Label operator*() const {
00129 return t_;
00130 }
00131 const Label* operator->() const {
00132 return &t_;
00133 }
00134 bool operator==(const This &o) const {
00135 return t_ == o.t_;
00136 }
00137 bool operator!=(const This &o) const {
00138 return t_ != o.t_;
00139 }
00140 bool operator<(const This &o) const {
00141 return t_ < o.t_;
00142 }
00143 int operator-(const This &o) const {
00144 return t_.index()-o.t_.index();
00145 }
00146 
00147 const This& operator+=(unsigned int v) {
00148 t_= Label(t_.index()+v);
00149 return *this;
00150 }
00151 const This& operator-=(int &v) {
00152 t_ = Label(t_.index()-v);
00153 return *this;
00154 }
00155 template <class J>
00156 void operator()(const J&){
00157 ++*this;
00158 }
00159 typedef std::random_access_iterator_tag iterator_category;
00160 typedef Label value_type;
00161 typedef int difference_type;
00162 typedef Label* pointer;
00163 typedef Label& reference;
00164 protected:
00165 Label t_;
00166 };*/
00167 
00168 template <class T>
00169 Counter<T> counter(T t)
00170 {
00171     return Counter<T>(t);
00172 }
00173 
00174 CGAL_END_NAMESPACE
00175 
00176 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines