Initial import of the CDE 2.1.30 sources from the Open Group.
[oweals/cde.git] / cde / programs / nsgmls / RangeMap.h
1 /* $XConsortium: RangeMap.h /main/1 1996/07/29 17:02:22 cde-hp $ */
2 // Copyright (c) 1994 James Clark
3 // See the file COPYING for copying permission.
4
5 #ifndef RangeMap_INCLUDED
6 #define RangeMap_INCLUDED 1
7
8 #include "Vector.h"
9 #include "Boolean.h"
10 #include "ISet.h"
11 #include "types.h"
12 #include <stddef.h>
13
14 #ifdef SP_NAMESPACE
15 namespace SP_NAMESPACE {
16 #endif
17
18 template<class From, class To>
19 struct RangeMapRange {
20   RangeMapRange() { }
21   ~RangeMapRange() { }
22   From fromMin;
23   From fromMax;
24   To toMin;
25 };
26
27 template<class From, class To> class RangeMapIter;
28
29 template<class From, class To>
30 class RangeMap {
31 public:
32   RangeMap();
33   Boolean map(From, To &, From &alsoMax) const;
34   // Return 0 for no matches, 1 for 1, 2 for more than 1.
35   unsigned inverseMap(To, From &, ISet<WideChar> &, WideChar &count) const;
36   void addRange(From, From, To);
37 private:
38   Vector<RangeMapRange<From,To> > ranges_;
39   friend class RangeMapIter<From,To>;
40 };
41
42 template<class From, class To>
43 class RangeMapIter {
44 public:
45   RangeMapIter(const RangeMap<From,To> &map);
46   Boolean next(From &fromMin, From &fromMax, To &toMin) {
47     if (!count_)
48       return 0;
49     else {
50       fromMin = ptr_->fromMin;
51       fromMax = ptr_->fromMax;
52       toMin = ptr_->toMin;
53       ptr_++;
54       count_--;
55       return 1;
56     }
57   }
58 private:
59   size_t count_;
60   const RangeMapRange<From,To> *ptr_;
61 //  Vector<RangeMapRange<From,To> >::const_iterator ptr_;
62 };
63
64 #ifdef SP_NAMESPACE
65 }
66 #endif
67
68 #endif /* not RangeMap_INCLUDED */
69
70 #ifdef SP_DEFINE_TEMPLATES
71 #include "RangeMap.C"
72 #endif