LCOV - code coverage report
Current view: top level - src/engraving/infrastructure - eid.h Coverage Total Hit
Test: filtered_coverage.info Lines: 100.0 % 7 7
Test Date: 2026-11-05 04:07:02

            Line data    Source code
       1              : /*
       2              :  * SPDX-License-Identifier: GPL-3.0-only
       3              :  * MuseScore-Studio-CLA-applies
       4              :  *
       5              :  * MuseScore Studio
       6              :  * Music Composition & Notation
       7              :  *
       8              :  * Copyright (C) 2021 MuseScore Limited and others
       9              :  *
      10              :  * This program is free software: you can redistribute it and/or modify
      11              :  * it under the terms of the GNU General Public License version 3 as
      12              :  * published by the Free Software Foundation.
      13              :  *
      14              :  * This program is distributed in the hope that it will be useful,
      15              :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      16              :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      17              :  * GNU General Public License for more details.
      18              :  *
      19              :  * You should have received a copy of the GNU General Public License
      20              :  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
      21              :  */
      22              : #pragma once
      23              : 
      24              : #include <cstdint>
      25              : #include <string>
      26              : #include <string_view>
      27              : 
      28              : #include "global/logstream.h"
      29              : 
      30              : namespace mu::engraving {
      31              : class EID
      32              : {
      33              : public:
      34              :     // max size of base64 string of 64-bit int is ceil(log(2^64) / log(64)) = 11
      35              :     static constexpr size_t MAX_UINT64_BASE64_SIZE = 11;
      36              :     // 2 * uint64_t as base64 + separator
      37              :     static constexpr size_t MAX_STR_SIZE = 2 * MAX_UINT64_BASE64_SIZE + 1;
      38              : 
      39       249419 :     bool isValid() const { return m_first != INVALID || m_second != INVALID; }
      40              : 
      41        15404 :     inline bool operator ==(const EID& other) const { return m_first == other.m_first && m_second == other.m_second; }
      42              :     inline bool operator !=(const EID& other) const { return m_first != other.m_first || m_second != other.m_second; }
      43              : 
      44              :     char* toChars(char* first, char* last) const;
      45              :     std::string toStdString() const;
      46              :     static EID fromStdString(const std::string& v);
      47              :     static EID fromStdString(const std::string_view& v);
      48              :     static EID newUnique();
      49        70610 :     static EID invalid() { return EID(INVALID, INVALID); }
      50              : 
      51              :     // FOR UNIT TESTING
      52              :     static EID newUniqueTestMode(uint64_t& maxVal);
      53              :     static void updateMaxValTestMode(const EID& curEID, uint64_t& maxVal);
      54              : 
      55              : private:
      56              :     EID() = delete;
      57       178731 :     EID(uint64_t f, uint64_t s)
      58       178731 :         : m_first(f), m_second(s) {}
      59              : 
      60              :     static constexpr uint64_t INVALID = uint64_t(-1);
      61              : 
      62              :     uint64_t m_first = INVALID;
      63              :     uint64_t m_second = INVALID;
      64              : 
      65              :     friend struct std::hash<EID>;
      66              : };
      67              : }
      68              : 
      69              : template<>
      70              : struct std::hash<mu::engraving::EID>
      71              : {
      72       119468 :     size_t operator()(const mu::engraving::EID& eid) const
      73              :     {
      74       119468 :         return std::hash<uint64_t>()(eid.m_first) ^ (std::hash<uint64_t>()(eid.m_second) << 1);
      75              :     }
      76              : };
      77              : 
      78              : inline muse::logger::Stream& operator<<(muse::logger::Stream& s, const mu::engraving::EID& v)
      79              : {
      80              :     s << v.toStdString();
      81              :     return s;
      82              : }
        

Generated by: LCOV version 2.0-1