BWAPI
|
00001 // Copyright (c) 1997-2000 Max-Planck-Institute Saarbruecken (Germany). 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/Nef_2/include/CGAL/Nef_2/Object_index.h $ 00015 // $Id: Object_index.h 41628 2008-01-14 23:08:43Z spion $ 00016 // 00017 // 00018 // Author(s) : Michael Seel <seel@mpi-sb.mpg.de> 00019 00020 #ifndef CGAL_NEF_2_OBJECT_INDEX_H 00021 #define CGAL_NEF_2_OBJECT_INDEX_H 00022 00023 #include <CGAL/basic.h> 00024 #include <CGAL/Unique_hash_map.h> 00025 #include <string> 00026 #include <sstream> 00027 00028 CGAL_BEGIN_NAMESPACE 00029 00030 template <typename I> 00031 class Object_index { 00032 char _prefix; 00033 CGAL::Unique_hash_map<I,int> _index; 00034 public: 00035 Object_index() : _prefix('\0'), _index(-1) {} 00036 Object_index(I first, I beyond, char c=' ') : _prefix(c), _index(-1) 00037 { for(int i=0 ; first!=beyond; ++i,++first) _index[first]=i; } 00038 int operator[](const I& it) const { return _index[it]; } 00039 int& operator[](const I& it) { return _index[it]; } 00040 00041 void index(I first, I beyond, char c=' ') 00042 { _prefix=c; 00043 for(int i=0 ; first!=beyond; ++i,++first) _index[first]=i; 00044 } 00045 std::string operator()(const I& it, bool verbose=true) const 00046 { if (verbose && _index[it]==-1) return "nil"; 00047 if (verbose && _index[it]==-2) return "end"; 00048 std::ostringstream os; 00049 if (verbose) os << _prefix; 00050 os << _index[it]; 00051 return os.str(); 00052 } 00053 }; 00054 00055 CGAL_END_NAMESPACE 00056 00057 #endif //CGAL_NEF_2_OBJECT_INDEX_H