AUI Framework  develop
Cross-platform base for C++ UI apps
Loading...
Searching...
No Matches
AListModelIndex.h
    1/*
    2 * AUI Framework - Declarative UI toolkit for modern C++20
    3 * Copyright (C) 2020-2025 Alex2772 and Contributors
    4 *
    5 * SPDX-License-Identifier: MPL-2.0
    6 *
    7 * This Source Code Form is subject to the terms of the Mozilla Public
    8 * License, v. 2.0. If a copy of the MPL was not distributed with this
    9 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
   10 */
   11
   12#pragma once
   13
   14#include <cstddef>
   15#include <cstdint>
   16#include <tuple>
   17#include <ostream>
   18
   19class AListModelIndex
   20{
   21private:
   22    std::size_t mRow = -1;
   23    std::size_t mColumn = -1;
   24
   25public:
   26    AListModelIndex(std::size_t row, std::size_t column)
   27        : mRow(row),
   28          mColumn(column)
   29    {
   30    }
   31
   32    AListModelIndex(std::size_t row)
   33        : mRow(row)
   34    {
   35    }
   36
   37    AListModelIndex() = default;
   38
   39    std::size_t getRow() const
   40    {
   41        return mRow;
   42    }
   43
   44    std::size_t getColumn() const
   45    {
   46        return mColumn;
   47    }
   48
   49    bool operator==(const AListModelIndex& rhs) const {
   50        return std::tie(mRow, mColumn) == std::tie(rhs.mRow, rhs.mColumn);
   51    }
   52
   53    bool operator!=(const AListModelIndex& rhs) const {
   54        return !(rhs == *this);
   55    }
   56
   57    inline bool operator<(const AListModelIndex& other) const {
   58        return hash() < other.hash();
   59    }
   60
   61    [[nodiscard]] inline uint64_t hash() const {
   62        uint64_t hash = uint32_t(mRow);
   63        hash <<= 32u;
   64        hash |= uint32_t(mColumn);
   65        return hash;
   66    }
   67
   68};
   69
   70inline std::ostream& operator<<(std::ostream& o, const AListModelIndex& index) {
   71    o << "{ " << index.getRow();
   72    if (index.getColumn() != -1) {
   73        o << ", " << index.getColumn();
   74    }
   75    o << " }";
   76
   77    return o;
   78}
Definition AListModelIndex.h:20