< Summary

Class:GDX.DataTables.CellValues.IntCellValue
Assembly:GDX
File(s):./Packages/com.dotbunny.gdx/GDX/DataTables/CellValues/IntCellValue.cs
Covered lines:0
Uncovered lines:32
Coverable lines:32
Total lines:125
Line coverage:0% (0 of 32)
Covered branches:0
Total branches:0
Covered methods:0
Total methods:6
Method coverage:0% (0 of 6)

Coverage History

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
IntCellValue(...)0%2100%
Get()0%6200%
GetDataVersion()0%2100%
GetUnsafe()0%2100%
Set(...)0%6200%
GetSupportedType()0%2100%

File(s)

./Packages/com.dotbunny.gdx/GDX/DataTables/CellValues/IntCellValue.cs

#LineLine coverage
 1// Copyright (c) 2020-2024 dotBunny Inc.
 2// dotBunny licenses this file to you under the BSL-1.0 license.
 3// See the LICENSE file in the project root for more information.
 4
 5using System;
 6
 7namespace GDX.DataTables.CellValues
 8{
 9    /// <summary>
 10    ///     A <see cref="DataTableBase" /> <see cref="int" /> cell reference.
 11    /// </summary>
 12    [Serializable]
 13    public struct IntCellValue
 14    {
 15        /// <summary>
 16        ///     The cached value of the referenced <see cref="DataTable" /> cell.
 17        /// </summary>
 18        int m_CachedValue;
 19
 20        /// <summary>
 21        ///     The cached <see cref="DataTable" /> version found when last updating <see cref="m_CachedValue" />.
 22        /// </summary>
 23        ulong m_TableVersion;
 24#pragma warning disable IDE1006
 25        // ReSharper disable InconsistentNaming
 26        /// <summary>
 27        ///     The <see cref="DataTableBase" /> polled for cell data.
 28        /// </summary>
 29        public DataTableBase DataTable;
 30
 31        /// <summary>
 32        ///     The unique column identifier used when accessing the <see cref="DataTable" />.
 33        /// </summary>
 34        public int ColumnIdentifier;
 35
 36        /// <summary>
 37        ///     The unique row identifier used when accessing the <see cref="DataTable" />.
 38        /// </summary>
 39        public int RowIdentifier;
 40        // ReSharper enable InconsistentNaming
 41#pragma warning restore IDE1006
 42
 43        /// <summary>
 44        ///     Creates an <see cref="IntCellValue" />.
 45        /// </summary>
 46        /// <param name="dataTable">The referenced <see cref="DataTableBase" />.</param>
 47        /// <param name="rowIdentifier">The unique row identifier to use when polling the <paramref name="dataTable" />.
 48        /// <param name="columnIdentifier">The unique column identifier to use when polling the <paramref name="dataTabl
 49        public IntCellValue(DataTableBase dataTable, int rowIdentifier, int columnIdentifier)
 050        {
 051            DataTable = dataTable;
 052            RowIdentifier = rowIdentifier;
 053            ColumnIdentifier = columnIdentifier;
 054            m_TableVersion = 0;
 055            m_CachedValue = default;
 056            Get();
 057        }
 58
 59        /// <summary>
 60        ///     Get the <see cref="int" /> value referenced from the <see cref="DataTableBase" />.
 61        /// </summary>
 62        /// <remarks>
 63        ///     This will evaluate if the version of the table matches the internally cached version, and will update
 64        ///     the cached reference if necessary.
 65        /// </remarks>
 66        /// <returns>An <see cref="int" /> value.</returns>
 67        public int Get()
 068        {
 069            if (m_TableVersion == DataTable.GetDataVersion())
 070            {
 071                return m_CachedValue;
 72            }
 73
 074            m_CachedValue = DataTable.GetInt(RowIdentifier, ColumnIdentifier);
 075            m_TableVersion = DataTable.GetDataVersion();
 076            return m_CachedValue;
 077        }
 78
 79        /// <summary>
 80        ///     Get the internally cached version of the <see cref="DataTableBase" />'s data version.
 81        /// </summary>
 82        /// <returns>A version number.</returns>
 83        public ulong GetDataVersion()
 084        {
 085            return m_TableVersion;
 086        }
 87
 88        /// <summary>
 89        ///     Get the cached value without a version check.
 90        /// </summary>
 91        /// <remarks>
 92        ///     This can respond with a default value if a <see cref="Get" /> call has not been made yet to populate the
 93        ///     internally cached value.
 94        /// </remarks>
 95        /// <returns>An <see cref="int" /> value.</returns>
 96        public int GetUnsafe()
 097        {
 098            return m_CachedValue;
 099        }
 100
 101        /// <summary>
 102        ///     Sets the cached value of the struct and by default, updates the associated <see cref="DataTableBase" />.
 103        /// </summary>
 104        /// <remarks>Updating the <see cref="DataTableBase" /> will update the cached table version.</remarks>
 105        /// <param name="newValue">An <see cref="int" /> value.</param>
 106        /// <param name="updateTable">Should the value be pushed back to the referenced <see cref="DataTableBase" /> cel
 107        public void Set(int newValue, bool updateTable = true)
 0108        {
 0109            m_CachedValue = newValue;
 0110            if (updateTable)
 0111            {
 0112                m_TableVersion = DataTable.SetInt(RowIdentifier, ColumnIdentifier, newValue);
 0113            }
 0114        }
 115
 116        /// <summary>
 117        ///     Get the <see cref="Serializable.SerializableTypes" /> which this struct supports.
 118        /// </summary>
 119        /// <returns>A <see cref="Serializable.SerializableTypes" />.</returns>
 120        public static Serializable.SerializableTypes GetSupportedType()
 0121        {
 0122            return Serializable.SerializableTypes.Int;
 0123        }
 124    }
 125}