Scanframe Modular Application 0.1.0
Loading...
Searching...
No Matches
Range.h
Go to the documentation of this file.
1#pragma once
2#include <iostream>
3#include <limits>
4#include <misc/gen/TVector.h>
5#include <misc/global.h>
6
7namespace sf
8{
9
15
16// Packed structure for binary storage.
17#pragma pack(push, 1)
18
22struct RANGE
23{
27 typedef uint64_t size_type;
31 typedef int64_t id_type;
44};
45
46// Restore the pack option.
47#pragma pack(pop)
48
52class _MISC_CLASS Range : private RANGE
53{
54 public:
63
67 class _MISC_CLASS Vector : public TVector<Range>
68 {
69 public:
75
80 [[nodiscard]] Vector sort() const;
81
86
94 Vector exclude(const Vector& rel) const;
95
100 Vector& exclude(const Vector& rl_ex);
101
109 Vector extract(const Vector& rl, Vector& rl_ex) const;
110
115 Vector& merge(const Vector& rl_add);
116 };
117
122
126 inline Range();
127
131 Range& operator=(Range&&) = default;
132
137 inline Range(const Range& r);
138
142 explicit inline Range(const RANGE& r);
143
150 inline Range(size_type start, size_type stop, id_type id = 0);
151
155 void normalize();
156
164 Range& assign(size_type start, size_type stop, id_type id = 0);
165
169 inline Range& assign(const Range& r);
170
174 Range& set(const RANGE& r);
175
179 inline const Range& copyTo(RANGE& dst) const;
180
184 [[nodiscard]] inline size_type getStart() const;
185
189 [[nodiscard]] inline size_type getStop() const;
190
194 inline void clear();
195
199 [[nodiscard]] inline size_type getSize() const;
200
204 [[nodiscard]] inline bool isEmpty() const;
205
209 [[nodiscard]] bool isOverlapped(const Range& r) const;
210
214 [[nodiscard]] bool isWithinOther(const Range& r) const;
215
219 [[nodiscard]] bool isWithinSelf(const Range& r) const;
220
224 [[nodiscard]] bool isExtension(const Range& r) const;
225
229 [[nodiscard]] bool isMergeable(const Range& r) const;
230
239 inline size_type split(size_type seg_sz, Vector& rl_dst) const;
240
250 static size_type split(size_type seg_sz, const Range& req, Vector& rl_dst);
251
260 static size_type split(size_type seg_sz, const Vector& req, Vector& rl);
261
265 [[nodiscard]] inline bool isInRange(size_type idx) const;
266
270 const RANGE& getBase() const;
271
275 explicit inline operator bool() const;
276
283 enum ECompare : int
284 {
288 cmpError = std::numeric_limits<int>::max(),
296 cmpSame = 0,
304 cmpWithinSelf = 1,
312 cmpWithinOther = -1,
320 cmpOverlapsOther = 2,
328 cmpOverlapsSelf = -2,
336 cmpExtendsOther = 3,
344 cmpExtendsSelf = -3,
352 cmpBeforeSelf = 4,
360 cmpAfterSelf = -4,
368 cmpSelfEmpty = 5,
375 cmpOtherEmpty = -5,
376 };
377
381 [[nodiscard]] ECompare compare(const Range& other) const;
382
386 [[nodiscard]] inline id_type getId() const;
387
391 inline Range& setId(id_type id);
392
396 inline Range& operator=(const Range& r);
397
401 inline Range& operator=(const RANGE& r);
402
406 inline bool operator==(const Range& r) const;
407
411 inline bool operator!=(const Range& r) const;
412
419 inline bool operator<(const Range& r) const;
420
424 Range operator&(const Range& r) const;
425
429 inline Range& operator&=(const Range& r);
430
436 Range operator+(const Range& r) const;
437
443 inline Range& operator+=(const Range& r);
444
454 int exclude(const Range& r, Range& rest, Range::ECompare* cmp = nullptr);
455
463
469 [[nodiscard]] inline Range offset(size_type ofs) const;
470
474 bool operator>(const Range& r) const = delete;
475
479 bool operator>(const Range& r) = delete;
480
484 bool operator<=(const Range& r) const = delete;
485
489 bool operator<=(const Range& r) = delete;
490
494 bool operator>=(const Range& r) const = delete;
495
499 bool operator>=(const Range& r) = delete;
500
501 private:
502 friend std::ostream& operator<<(std::ostream& os, const Range& r);
503 friend std::istream& operator>>(std::istream& is, Range& r);
504};
505
509_MISC_FUNC std::ostream& operator<<(std::ostream& os, const Range& r);
510
514_MISC_FUNC std::istream& operator>>(std::istream& is, Range& r);
515
519_MISC_FUNC std::ostream& operator<<(std::ostream& os, const Range::Vector& rl);
520
524_MISC_FUNC std::istream& operator>>(std::istream& is, Range::Vector& rl);
525
526}// namespace sf
527
528// Include all inlined functions and template implementations.
529#include <misc/gen/Range.hpp>
Type to contain and manipulate range lists.
Definition Range.h:68
Vector sort() const
Sorts the vector according the Range operator '<'.
Vector & rearrange()
Rearranges vector of ranges which means the vector is sorted and ranges are merged if possible.
Vector extract(const Vector &rl, Vector &rl_ex) const
Extracts the covered ranges in the vector using the 'rl' vector and puts them in the 'rl_ex' vector.
Vector & sort()
Sorts the vector according the Range operator '<'.
Vector & merge(const Vector &rl_add)
Adds the passed list to this vector and rearranges it.
Class to manage 64-bit integer ranges.
Definition Range.h:53
ECompare compare(const Range &other) const
Base function for comparing ranges.
size_type getSize() const
Returns the size of the range minimum is 1.
bool operator>=(const Range &r)=delete
Not allowed operator.
Range & assign(const Range &r)
InitializeBase instance with other instance.
Range(const RANGE &r)
Base class constructor.
RANGE::size_type size_type
Integer type used for start and stop.
Definition Range.h:58
Range & set(const RANGE &r)
InitializeBase instance with other instance.
const Range & copyTo(RANGE &dst) const
bool isOverlapped(const Range &r) const
Returns if the passed range have some overlap.
void clear()
Clears the range to an empty state.
Range operator+(const Range &r) const
Returns a new range which is a super Set of the two ranges.
static size_type split(size_type seg_sz, const Range &req, Vector &rl_dst)
Splits a range into segments bounded ranges according to the passed segment size.
bool operator>(const Range &r)=delete
Not allowed operator.
id_type getId() const
Returns the owner id of this range.
friend std::istream & operator>>(std::istream &is, Range &r)
Input stream operator for a range.
Range & assign(size_type start, size_type stop, id_type id=0)
Assigns the data members.
Range & setId(id_type id)
Set the owner id of this range.
bool operator>=(const Range &r) const =delete
Not allowed operator.
const RANGE & getBase() const
Gets the underlying base structure.
Range & operator=(Range &&)=default
Move assignment operator is default.
Range(const Range &r)
Copy constructor.
Range(size_type start, size_type stop, id_type id=0)
Initializing constructor.
RANGE::id_type id_type
Integer type used for the ID.
Definition Range.h:62
void normalize()
Swaps start and stop if the order is wrong.
Range & operator=(const RANGE &r)
Assignment operator allow derived classes to copy their data members.
bool operator==(const Range &r) const
Tests if the range start and stop members are the same.
Range operator&(const Range &r) const
And operator which is a subset of both range where elements of the one also exist in the other range.
bool operator<=(const Range &r) const =delete
Not allowed operator.
bool operator>(const Range &r) const =delete
Not allowed operator.
static size_type split(size_type seg_sz, const Vector &req, Vector &rl)
Same as split but now for a complete vector of ranges.
Vector::iter_type Iterator
Iteration type for lists of ranges.
Definition Range.h:121
bool operator<=(const Range &r)=delete
Not allowed operator.
bool operator<(const Range &r) const
Operator used for sorting. Depends only on the start position first and then the stop position....
bool isInRange(size_type idx) const
Check if idx is within this range.
size_type getStop() const
Const function to access the stop of the range.
friend std::ostream & operator<<(std::ostream &os, const Range &r)
Output stream operator for a range.
bool isWithinOther(const Range &r) const
Returns true if the passed range is part of this range.
ECompare
All possible comparison results.
Definition Range.h:284
Range()
Default constructor.
Range & operator+=(const Range &r)
Returns a new range which is a super Set of the two ranges.
Range & operator=(const Range &r)
Assignment operator allow derived classes to copy their data members.
bool isWithinSelf(const Range &r) const
Returns true if this range is part of the passed range.
bool isEmpty() const
Return true if the range is empty.
size_type getStart() const
Const function to access the start of the range.
Range offset(size_type ofs) const
Shifts the range using the passed offset.
int exclude(const Range &r, Range &rest, Range::ECompare *cmp=nullptr)
Exclude the range in the other which could result in an single range (0), an additional second range ...
bool operator!=(const Range &r) const
Tests if the range start and stop members are not the same.
size_type split(size_type seg_sz, Vector &rl_dst) const
Splits this range into segments bounded ranges according to the passed segment size.
Range & offsetBy(size_type ofs)
Shifts this range using the passed offset.
Range & operator&=(const Range &r)
And operator which is a subset of both range where elements of the one also exist in the other range.
bool isExtension(const Range &r) const
Returns if the passed range an extension of this one.
bool isMergeable(const Range &r) const
Returns true if the passed range can be combined to this range without having to bridge a gap.
Counted vector having additional methods and operators for ease of usage. This template class extends...
Definition TVector.h:20
TIterator< value_type > iter_type
Iteration type of the template.
Definition TVector.h:37
#define _MISC_FUNC
Definition misc/global.h:39
#define _MISC_CLASS
Definition misc/global.h:40
#define _MISC_DATA
Definition misc/global.h:38
Definition Application.h:10
_GII_FUNC std::istream & operator>>(std::istream &is, ResultData &)
Stream operator for setting up this instance with a setup std::string.
_MISC_DATA bool RangeCompareExact
_GII_FUNC std::ostream & operator<<(std::ostream &os, const ResultData &)
Stream operator for the setup std::string.
Definition Range.h:23
uint64_t size_type
Integer type used for start and stop.
Definition Range.h:27
id_type _id
Identifier of this range.
Definition Range.h:43
int64_t id_type
Integer type used for the ID.
Definition Range.h:31
size_type _start
Start position of the range or interval.
Definition Range.h:35
size_type _stop
Stop position of the range or interval.
Definition Range.h:39