mirror of
https://github.com/TomHarte/CLK.git
synced 2025-11-06 14:17:27 +00:00
Further extend. This is becoming more of a SizedInt.
This commit is contained in:
@@ -28,20 +28,35 @@ struct SizedCounter {
|
|||||||
return counter_;
|
return counter_;
|
||||||
}
|
}
|
||||||
|
|
||||||
SizedCounter operator +(const SizedCounter offset) const {
|
SizedCounter operator +(const SizedCounter offset) const { return SizedCounter<bits>(counter_ + offset.counter_); }
|
||||||
return SizedCounter<bits>(counter_ + offset.counter_);
|
SizedCounter operator -(const SizedCounter offset) const { return SizedCounter<bits>(counter_ - offset.counter_); }
|
||||||
|
SizedCounter operator &(const SizedCounter offset) const { return SizedCounter<bits>(counter_ & offset.counter_); }
|
||||||
|
SizedCounter operator |(const SizedCounter offset) const { return SizedCounter<bits>(counter_ | offset.counter_); }
|
||||||
|
SizedCounter operator ^(const SizedCounter offset) const { return SizedCounter<bits>(counter_ ^ offset.counter_); }
|
||||||
|
SizedCounter operator >>(const int shift) const { return SizedCounter<bits>(counter_ >> shift); }
|
||||||
|
SizedCounter operator <<(const int shift) const { return SizedCounter<bits>(counter_ << shift); }
|
||||||
|
|
||||||
|
SizedCounter &operator &=(const SizedCounter offset) {
|
||||||
|
counter_ &= offset.counter_;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
SizedCounter &operator |=(const SizedCounter offset) {
|
||||||
|
counter_ |= offset.counter_;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
SizedCounter &operator ^=(const SizedCounter offset) {
|
||||||
|
counter_ ^= offset.counter_;
|
||||||
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
SizedCounter operator &(const SizedCounter offset) const {
|
SizedCounter &operator <<=(const int shift) {
|
||||||
return SizedCounter<bits>(counter_ & offset.counter_);
|
counter_ = (counter_ << shift) & Mask;
|
||||||
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
SizedCounter operator >>(const int shift) const {
|
SizedCounter &operator >>=(const int shift) {
|
||||||
return SizedCounter<bits>(counter_ >> shift);
|
counter_ >>= shift;
|
||||||
}
|
return *this;
|
||||||
|
|
||||||
SizedCounter operator <<(const int shift) const {
|
|
||||||
return SizedCounter<bits>(counter_ << shift);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SizedCounter &operator ++(int) {
|
SizedCounter &operator ++(int) {
|
||||||
@@ -78,6 +93,12 @@ struct SizedCounter {
|
|||||||
load<begin, begin + sizeof(IntT)*8>(value);
|
load<begin, begin + sizeof(IntT)*8>(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <int index>
|
||||||
|
requires (index < bits)
|
||||||
|
bool bit() {
|
||||||
|
return counter_ & (1 << index);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
IntT counter_{};
|
IntT counter_{};
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user