1 /* 2 * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 3 * Use is subject to license terms. 4 */ 5 6 /* 7 * Copyright 1994 James Clark 8 * See the file COPYING for copying permission. 9 */ 10 11 #pragma ident "%Z%%M% %I% %E% SMI" 12 13 #ifndef _RANGEMAP_H 14 #define _RANGEMAP_H 15 16 #ifndef RangeMap_INCLUDED 17 #define RangeMap_INCLUDED 1 18 19 #include "Vector.h" 20 #include "Boolean.h" 21 #include "ISet.h" 22 #include "types.h" 23 #include <stddef.h> 24 25 #ifdef SP_NAMESPACE 26 namespace SP_NAMESPACE { 27 #endif 28 29 template < class From, class To > 30 struct RangeMapRange { 31 From fromMin; 32 From fromMax; 33 To toMin; 34 }; 35 36 template < class From, class To > class RangeMapIter; 37 template < class From, class To > class RangeMap; 38 39 template < class From, class To > 40 class RangeMap { 41 public: 42 RangeMap(); 43 Boolean map(From, To &, From &alsoMax) const; 44 // Return 0 for no matches, 1 for 1, 2 for more than 1. 45 unsigned inverseMap(To, From &, ISet < WideChar > &, \ 46 WideChar &count) const; 47 void addRange(From, From, To); 48 private: 49 Vector < RangeMapRange < From, To > > ranges_; 50 friend class RangeMapIter < From, To >\ 51 ; 52 }; 53 54 template < class From, class To > 55 class RangeMapIter { 56 public: 57 RangeMapIter(const RangeMap < From, To > &map); next(From & fromMin,From & fromMax,To & toMin)58 Boolean next(From &fromMin, From &fromMax, To &toMin) { 59 if (!count_) 60 return (0); 61 else { 62 fromMin = ptr_->fromMin; 63 fromMax = ptr_->fromMax; 64 toMin = ptr_->toMin; 65 ptr_++; 66 count_--; 67 return (1); 68 } 69 } 70 private: 71 size_t count_; 72 typename Vector < RangeMapRange < From, To > >\ 73 ::const_iterator ptr_; 74 }; 75 76 #ifdef SP_NAMESPACE 77 } 78 #endif 79 80 #endif /* not RangeMap_INCLUDED */ 81 82 #ifdef SP_DEFINE_TEMPLATES 83 #include "RangeMap.cxx" 84 #endif 85 86 #endif /* _RANGEMAP_H */ 87