|
AMRange
201909
String localization library
|
Go to the documentation of this file.
8 #ifndef AMCORE_AMRANGE_H
9 #define AMCORE_AMRANGE_H
120 inline bool valid()
const;
135 inline bool in(T num)
const;
143 inline bool in(
const AMRange &rng)
const;
150 inline bool empty()
const;
299 if (from < right.
from) {
301 }
else if (from == right.
from) {
302 return to < right.
to;
313 if (!right.
valid()) {
318 if (from < right.
from) {
323 }
else if (to > right.
from) {
329 }
else if (from < right.
to) {
339 if (from < right.
from) {
357 if (!right.
valid()) {
362 if (to < right.from || from > right.
to) {
375 if (from > right.
from) {
385 return (from == right.
from && to == right.
to);
391 return (from != right.
from || to != right.
to);
404 return ((num >= from) && (num < to));
422 return ((_rng.
from >= from) && (_rng.
to <= to) && (_rng.
from < _rng.
to));
452 typename std::set<AMRange<T> >::iterator it = s.begin();
456 typename std::set<AMRange<T> >::iterator itn = it;
461 while (itn != s.end()) {
462 if (itn->from > it->to) {
478 for(
typename std::set<
AMRange<T> >::iterator it = s.begin(); it != s.end(); it++) {
490 std::set<AMRange<T> > result;
492 typename std::set<AMRange<T> >::iterator it = s.begin();
527 std::set<AMRange<T> > result = left;
528 std::merge(left.begin(), left.end(),
529 right.begin(), right.end(),
530 std::inserter(result, result.begin()));
531 result =
pack(result);
538 if (left.size() == 0) {
539 return std::set<AMRange<T> >();
541 if (right.size() == 0) {
544 std::set<AMRange<T> > ls =
pack(left);
545 std::set<AMRange<T> > rs =
pack(right);
546 std::set<AMRange<T> > result;
547 typename std::set<AMRange<T> >::iterator lit = ls.begin();
548 typename std::set<AMRange<T> >::iterator rit = rs.begin();
551 if (lit != ls.end()) {
552 if (rit != rs.end()) {
563 if (lit->to > rit->to) {
567 if (lit != ls.end()) {
576 if (lit != ls.end()) {
584 if (rit != rs.end()) {
600 std::set<AMRange<T> > result = right;
602 result =
pack(result);
608 std::set<AMRange<T> > ls = {left};
614 std::set<AMRange<T> > result = left;
615 result.insert(right);
616 result =
pack(result);
622 std::set<AMRange<T> > rs = {right};
629 #endif //AMCORE_AMRANGE_H
bool operator==(const AMRange &right) const
comparison operator Tests both bounds for equality.
Definition: AMRange.h:383
AMRange< T > operator+(const AMRange< T > &left, const AMRange< T > &right)
plus operator Cut part of range by intersect with right operand. If right range is inside left,...
Definition: AMRange.h:426
AMRange & operator+=(const AMRange &right)
plus operator Cut part of range by intersect with right operand. If right range is inside left,...
Definition: AMRange.h:352
bool operator!=(const AMRange &right) const
comparison operator If at least one bound not equalt to rught bound.
Definition: AMRange.h:389
Range and set of range operations.
Definition: AMRange.h:34
AMRange< T > intersect(const AMRange< T > &left, const AMRange< T > &right)
intersect Intersection with right interval If ranges are in disjunction, returnned rage is empty
Definition: AMRange.h:442
AMRange< T > operator-(const AMRange< T > &left, const AMRange< T > &right)
minus operator Cut part of range by intersect with right operand. If ranges are in disjunction,...
Definition: AMRange.h:434
AMRange & operator-=(const AMRange &right)
minus operator Cut part of range by intersect with right operand. If ranges are in disjunction,...
Definition: AMRange.h:308
T to
right bound
Definition: AMRange.h:44
T from
left bound
Definition: AMRange.h:40
bool nonEmpty() const
test for validity and empty Simply checks that from bound > to bound
Definition: AMRange.h:414
bool valid() const
test for validity Simply checks that from bound >= to bound
Definition: AMRange.h:396
AMRange()
empty constructor Uses T() for init bounds.
Definition: AMRange.h:283
bool operator<(const AMRange &right) const
less operator Used namely for std::set container
Definition: AMRange.h:297
bool valid(const std::set< AMRange< T > > &s)
valid test Set of ranges is valid when all range in are valid
Definition: AMRange.h:476
bool in(T num) const
check that number is inside Remember that interval is open from right, so if num == to,...
Definition: AMRange.h:402
AMRange & intersect(const AMRange &right)
intersect Intersection with right interval If ranges are in disjunction, range become empty
Definition: AMRange.h:337
std::set< AMRange< T > > pack(const std::set< AMRange< T > > &s)
pack a set of ranges Set of ranges is packed when, ranges has not intersections. E....
Definition: AMRange.h:487
bool isPacked(const std::set< AMRange< T > > &s)
packed test Set of ranges is packed when, ranges has not intersections. E.q. Second range starts abov...
Definition: AMRange.h:450
bool empty() const
test for empty Simply checks that from bound == to bound
Definition: AMRange.h:408