|
|
@ -11,16 +11,13 @@ namespace klotski::ffi { |
|
|
|
|
|
|
|
using cases::RangesUnion; |
|
|
|
|
|
|
|
class PyCases { |
|
|
|
class PyCasesIter { |
|
|
|
public: |
|
|
|
PyCases() = delete; |
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------- //
|
|
|
|
/// Construct from RangesUnion reference.
|
|
|
|
explicit PyCasesIter(const RangesUnion &data); |
|
|
|
|
|
|
|
class CommonCodeIter { |
|
|
|
public: |
|
|
|
/// Get the next CommonCode or throw a stop_iteration exception.
|
|
|
|
PyCommonCode next(); |
|
|
|
explicit CommonCodeIter(const RangesUnion &data); |
|
|
|
|
|
|
|
private: |
|
|
|
uint8_t head_ {0}; |
|
|
@ -28,18 +25,13 @@ public: |
|
|
|
const RangesUnion &data_; |
|
|
|
}; |
|
|
|
|
|
|
|
class ShortCodeIter { |
|
|
|
class PyCases { |
|
|
|
public: |
|
|
|
PyShortCode next(); |
|
|
|
explicit ShortCodeIter(CommonCodeIter iter); |
|
|
|
|
|
|
|
private: |
|
|
|
CommonCodeIter iter_; |
|
|
|
}; |
|
|
|
PyCases() = delete; |
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------- //
|
|
|
|
|
|
|
|
/// Constructing from rvalue.
|
|
|
|
/// Constructing from r-value.
|
|
|
|
static PyCases from(RangesUnion &&data) noexcept; |
|
|
|
|
|
|
|
/// Constructing from longer-lived reference.
|
|
|
@ -48,20 +40,23 @@ public: |
|
|
|
// ------------------------------------------------------------------------------------- //
|
|
|
|
|
|
|
|
/// Get the number of cases.
|
|
|
|
[[nodiscard]] size_t size() const; |
|
|
|
|
|
|
|
/// Get ShortCode iterator of cases.
|
|
|
|
[[nodiscard]] ShortCodeIter short_codes() const; |
|
|
|
[[nodiscard]] size_t size() const noexcept; |
|
|
|
|
|
|
|
/// Get CommonCode iterator of cases.
|
|
|
|
[[nodiscard]] CommonCodeIter common_codes() const; |
|
|
|
[[nodiscard]] PyCasesIter codes() const noexcept; |
|
|
|
|
|
|
|
/// Get the CommonCode of the specified index.
|
|
|
|
[[nodiscard]] PyCommonCode operator[](size_t index) const; |
|
|
|
[[nodiscard]] PyCommonCode at(size_t index) const; // TODO: allow `-1` index
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------- //
|
|
|
|
|
|
|
|
// TODO: add len / repr
|
|
|
|
/// Wrapper of `__repr__` method in Python.
|
|
|
|
static std::string repr(const PyCases &cases) noexcept; |
|
|
|
|
|
|
|
/// Compare the cases contents of two PyCases.
|
|
|
|
friend constexpr auto operator==(const PyCases &lhs, const PyCases &rhs); |
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------- //
|
|
|
|
|
|
|
|
private: |
|
|
|
explicit PyCases(RangesUnion &&data); |
|
|
@ -78,6 +73,8 @@ private: |
|
|
|
// ------------------------------------------------------------------------------------- //
|
|
|
|
}; |
|
|
|
|
|
|
|
// TODO: allow compare
|
|
|
|
constexpr auto operator==(const PyCases &lhs, const PyCases &rhs) { |
|
|
|
return lhs.data_ref() == rhs.data_ref(); |
|
|
|
} |
|
|
|
|
|
|
|
} // namespace klotski::ffi
|
|
|
|