5 #include <libutl/MemStream.h> 46 template <
class T,
class D = T>
58 Span(
const T& begin,
const T& end,
bool relaxed =
false);
100 set(
const T& begin,
const T& end)
110 return _begin >= _end;
124 return getFlag(flg_relaxed);
131 setFlag(flg_relaxed, relaxed);
138 return _end - _begin;
149 if (t > _begin) _begin = t;
157 if (t < _end) _end = t;
165 return (_begin <= span._begin) && (_end >= span._end);
172 return ((v >= _begin) && (v < _end));
187 _end =
max(_end, span.
end());
197 return !overlap(span).isNil();
236 init(
bool relaxed =
false)
260 template <
class T,
class D = T>
267 virtual int cmp(
const Object* lhs,
const Object* rhs)
const;
283 template <
class T,
class D = T>
312 template <
class T,
class D>
322 template <
class T,
class D>
327 if (rhs.isA2(
Span, T, D))
329 auto& span = utl::cast<Span<T, D>>(rhs);
332 if ((isRelaxed() || span.isRelaxed()) && overlaps(span))
339 if (res != 0)
return res;
352 template <
class T,
class D>
356 auto& span = utl::cast<Span<T, D>>(rhs);
357 FlagsMI::copyFlags(span);
358 _begin = span._begin;
364 template <
class T,
class D>
374 template <
class T,
class D>
379 ms <<
"[" << _begin <<
"," << _end <<
")" <<
'\0';
385 template <
class T,
class D>
391 if (_begin < span._begin) _begin = span._begin;
392 if (_end > span._end) _end = span._end;
398 template <
class T,
class D>
402 T beg =
max(_begin, span._begin);
403 T end =
min(_end, span._end);
409 template <
class T,
class D>
418 template <
class T,
class D>
441 if (_begin == overlap.
begin())
443 setBegin(overlap.
end());
446 else if (_end == overlap.
end())
448 setEnd(overlap.
begin());
457 setEnd(overlap.
begin());
467 template <
class T,
class D>
473 if (!lhsKey.isA2(
Span, T, D) || !rhsKey.isA2(
Span, T, D))
480 int res = lhsSpan.
size() - rhsSpan.
size();
483 res = lhsSpan.
compare(rhsSpan);
492 template <
class T,
class D>
496 this->_begin.serialize(stream, io, mode);
497 this->_end.serialize(stream, io, mode);
#define UTL_CLASS_DEFID
Default init() and deInit() (which are merely place-holders).
const T & begin() const
Get the beginning of the span.
void merge(const Span< T, D > &span)
Merge with the given span.
String toString(const FwdIt &begin, const FwdIt &end, const String &sep, bool key=false)
Obtain a string representation of a sequence (via Object::toString()).
void serialize(bool &b, Stream &stream, uint_t io, uint_t mode=ser_default)
Serialize a boolean.
bool overlaps(const Span< T, D > &span) const
Determine whether self overlaps with the given span.
void deInit()
De-initialize UTL++.
void merge(const FwdIt &lhsBegin, const FwdIt &lhsEnd, const FwdIt &rhsBegin, const FwdIt &rhsEnd, FwdIt &out, const Ordering *ordering=nullptr, bool cloning=false)
Merge two sorted sequences into a single sorted sequence.
Object comparison abstraction.
const T & max(const T &a, const T &b, const R &... args)
Return the largest value among two or more provided values of the same type.
#define UTL_CLASS_DECL_TPL2_TPL2(DC, DC_T1, DC_T2, BC, BC_T1, BC_T2)
Declaration of standard UTL++ functionality for a template class with two parameters, where the base class also has two template parameters.
void setEnd(const T &end)
Set the end of the span.
D size() const
Return the size (end - begin).
default representation (via getSerializeMode())
void remove(FwdIt &begin, const FwdIt &end, bool cmp=false, const Predicate *pred=nullptr, bool predVal=false)
Remove objects from a sequence.
const T & max(const T &v)
Base case for utl::max() variadic template.
Span of object-derived objects.
Mix-in to provide 64-bits for space-efficient storage of up to 64 boolean flags.
Span< T, D > & clipEnd(const T &t)
Clip the end against the given value.
bool contains(const T &v) const
Determine whether self contains the given value.
void copy(T *dest, const T *src, size_t len)
Copy one array of objects to another.
virtual int compare(const Object &rhs) const
Compare with another object.
char * takeString()
Convert to a string.
ObjectSpan(Span< T, D > span)
Constructor.
const T & end() const
Get the end of the span.
bool isRelaxed() const
Get the relaxed flag.
Span< T, D > & clipBegin(const T &t)
Clip the beginning against the given value.
bool contains(const Span< T, D > &span) const
Determine whether self contains the given span.
void setRelaxed(bool relaxed)
Set the relaxed flag.
void setNil()
Set the span to nil.
unsigned int uint_t
Unsigned integer.
void setBegin(const T &begin)
Set the beginning of the span.
#define UTL_CLASS_DECL_TPL2(DC, T1, T2, BC)
Declaration of standard UTL++ functionality for a template class with two parameters, where the base class has zero or one template parameters.
#define UTL_CLASS_IMPL_TPL2(className, T1, T2)
Implementation of standard UTL++ functionality for a template class with two parameters.
Span< T, D > operator+(const Span< T, D > &rhs)
Return self merged with the given span.
Span< T, D > overlap(const Span< T, D > &span) const
Return the sub-span that overlaps with the given span.
const Span< T, D > & operator+=(const Span< T, D > &rhs)
Merge with the given span.
const T & min(const T &a, const T &b, const R &... args)
Return the smallest value among two or more provided values of the same type.
virtual int compare(const Object &rhs) const
Compare with another object.
span_op_t
Span relationships.
virtual const Object & getKey() const
Get the key for this object.
span is contained by another
virtual String toString() const
Return a string representation of self.
bool isNil() const
Determine whether the span is nil.
Root of UTL++ class hierarchy.
int compare(bool lhs, bool rhs)
Compare two boolean values.
const T & min(const T &v)
Base case for utl::min() variadic template.
bool isContainedBy(const Span< T, D > &span) const
Determine whether self is contained by the given span.
void init()
Initialize UTL++.
virtual String toString() const
Return a string representation of self.