95 lines
2.4 KiB
C++
95 lines
2.4 KiB
C++
/*
|
|
* CDE - Common Desktop Environment
|
|
*
|
|
* Copyright (c) 1993-2012, The Open Group. All rights reserved.
|
|
*
|
|
* These libraries and programs are free software; you can
|
|
* redistribute them and/or modify them under the terms of the GNU
|
|
* Lesser General Public License as published by the Free Software
|
|
* Foundation; either version 2 of the License, or (at your option)
|
|
* any later version.
|
|
*
|
|
* These libraries and programs are distributed in the hope that
|
|
* they will be useful, but WITHOUT ANY WARRANTY; without even the
|
|
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
* PURPOSE. See the GNU Lesser General Public License for more
|
|
* details.
|
|
*
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
* License along with these librararies and programs; if not, write
|
|
* to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
|
|
* Floor, Boston, MA 02110-1301 USA
|
|
*/
|
|
/* $XConsortium: RangeMap.h /main/1 1996/07/29 17:02:22 cde-hp $ */
|
|
// Copyright (c) 1994 James Clark
|
|
// See the file COPYING for copying permission.
|
|
|
|
#ifndef RangeMap_INCLUDED
|
|
#define RangeMap_INCLUDED 1
|
|
|
|
#include "Vector.h"
|
|
#include "Boolean.h"
|
|
#include "ISet.h"
|
|
#include "types.h"
|
|
#include <stddef.h>
|
|
|
|
#ifdef SP_NAMESPACE
|
|
namespace SP_NAMESPACE {
|
|
#endif
|
|
|
|
template<class From, class To>
|
|
struct RangeMapRange {
|
|
RangeMapRange() { }
|
|
~RangeMapRange() { }
|
|
From fromMin;
|
|
From fromMax;
|
|
To toMin;
|
|
};
|
|
|
|
template<class From, class To> class RangeMapIter;
|
|
|
|
template<class From, class To>
|
|
class RangeMap {
|
|
public:
|
|
RangeMap();
|
|
Boolean map(From, To &, From &alsoMax) const;
|
|
// Return 0 for no matches, 1 for 1, 2 for more than 1.
|
|
unsigned inverseMap(To, From &, ISet<WideChar> &, WideChar &count) const;
|
|
void addRange(From, From, To);
|
|
private:
|
|
Vector<RangeMapRange<From,To> > ranges_;
|
|
friend class RangeMapIter<From,To>;
|
|
};
|
|
|
|
template<class From, class To>
|
|
class RangeMapIter {
|
|
public:
|
|
RangeMapIter(const RangeMap<From,To> &map);
|
|
Boolean next(From &fromMin, From &fromMax, To &toMin) {
|
|
if (!count_)
|
|
return 0;
|
|
else {
|
|
fromMin = ptr_->fromMin;
|
|
fromMax = ptr_->fromMax;
|
|
toMin = ptr_->toMin;
|
|
ptr_++;
|
|
count_--;
|
|
return 1;
|
|
}
|
|
}
|
|
private:
|
|
size_t count_;
|
|
const RangeMapRange<From,To> *ptr_;
|
|
// Vector<RangeMapRange<From,To> >::const_iterator ptr_;
|
|
};
|
|
|
|
#ifdef SP_NAMESPACE
|
|
}
|
|
#endif
|
|
|
|
#endif /* not RangeMap_INCLUDED */
|
|
|
|
#ifdef SP_DEFINE_TEMPLATES
|
|
#include "RangeMap.C"
|
|
#endif
|