diff --git a/src/simplnx/Common/TypesUtility.hpp b/src/simplnx/Common/TypesUtility.hpp index 6713ef5af0..93d196048a 100644 --- a/src/simplnx/Common/TypesUtility.hpp +++ b/src/simplnx/Common/TypesUtility.hpp @@ -4,12 +4,51 @@ #include "simplnx/Common/TypeTraits.hpp" #include "simplnx/Common/Types.hpp" +#if defined(__clang__) && defined(__clang_major__) && defined(__APPLE__) +#if __clang_major__ > 14 +#include +namespace bs = std; +#else +#include "Bit.hpp" +namespace bs = nx::core; +#endif +#else +#include +namespace bs = std; +#endif + #include #include #include namespace nx::core { +/** + * @brief Returns the templated value for the byte pattern 0xAB based on the byte count of the template parameter + * @tparam T + * @return + */ +template +constexpr T GetMudflap() noexcept +{ + if constexpr(sizeof(T) == 1) + { + return bs::bit_cast(static_cast(0xAB)); + } + if constexpr(sizeof(T) == 2) + { + return bs::bit_cast(static_cast(0xABAB)); + } + if constexpr(sizeof(T) == 4) + { + return bs::bit_cast(static_cast(0xABABABAB)); + } + if constexpr(sizeof(T) == 8) + { + return bs::bit_cast(static_cast(0xABABABABABABABAB)); + } +} + /** * @brief Returns the NumericType associated with T. * @tparam T diff --git a/src/simplnx/DataStructure/DataStore.hpp b/src/simplnx/DataStructure/DataStore.hpp index 4aabe5ec44..64dbcaab13 100644 --- a/src/simplnx/DataStructure/DataStore.hpp +++ b/src/simplnx/DataStructure/DataStore.hpp @@ -60,11 +60,12 @@ class DataStore : public AbstractDataStore , m_TupleShape(tupleShape) , m_NumComponents(std::accumulate(m_ComponentShape.cbegin(), m_ComponentShape.cend(), static_cast(1), std::multiplies<>())) , m_NumTuples(std::accumulate(m_TupleShape.cbegin(), m_TupleShape.cend(), static_cast(1), std::multiplies<>())) + , m_InitValue(initValue) { resizeTuples(m_TupleShape); - if(initValue.has_value()) + if(m_InitValue.has_value()) { - std::fill_n(data(), this->getSize(), *initValue); + std::fill_n(data(), this->getSize(), *m_InitValue); } } @@ -82,6 +83,8 @@ class DataStore : public AbstractDataStore , m_NumComponents(std::accumulate(m_ComponentShape.cbegin(), m_ComponentShape.cend(), static_cast(1), std::multiplies<>())) , m_NumTuples(std::accumulate(m_TupleShape.cbegin(), m_TupleShape.cend(), static_cast(1), std::multiplies<>())) { + // Because no init value is passed into the constructor, we will use a "mudflap" style value that is easy to debug. + m_InitValue = GetMudflap(); } /** @@ -94,6 +97,7 @@ class DataStore : public AbstractDataStore , m_TupleShape(other.m_TupleShape) , m_NumComponents(other.m_NumComponents) , m_NumTuples(other.m_NumTuples) + , m_InitValue(other.m_InitValue) { const usize count = other.getSize(); auto* data = new value_type[count]; @@ -112,6 +116,7 @@ class DataStore : public AbstractDataStore , m_Data(std::move(other.m_Data)) , m_NumComponents(std::move(other.m_NumComponents)) , m_NumTuples(std::move(other.m_NumTuples)) + , m_InitValue(other.m_InitValue) { } @@ -244,6 +249,15 @@ class DataStore : public AbstractDataStore { data[i] = m_Data.get()[i]; } + + // If we are sizing to a larger number of tuples, initialize the leftover array with the init + // value that was passed in during construction. + T initValue = m_InitValue.has_value() ? *m_InitValue : GetMudflap(); + for(usize i = oldSize; i < newSize; i++) + { + data[i] = initValue; + } + m_Data.reset(data); } @@ -364,6 +378,7 @@ class DataStore : public AbstractDataStore std::unique_ptr m_Data = nullptr; size_t m_NumComponents = {0}; size_t m_NumTuples = {0}; + std::optional m_InitValue; }; // Declare aliases diff --git a/src/simplnx/Utilities/FilterUtilities.hpp b/src/simplnx/Utilities/FilterUtilities.hpp index b99110de1d..f34e0d0c0f 100644 --- a/src/simplnx/Utilities/FilterUtilities.hpp +++ b/src/simplnx/Utilities/FilterUtilities.hpp @@ -2,7 +2,9 @@ #include "ParallelAlgorithmUtilities.hpp" #include "simplnx/Common/Result.hpp" +#include "simplnx/Common/TypeTraits.hpp" #include "simplnx/Common/Types.hpp" +#include "simplnx/Common/TypesUtility.hpp" #include "simplnx/Filter/IFilter.hpp" #include "simplnx/Filter/Output.hpp" #include "simplnx/simplnx_export.hpp" @@ -94,6 +96,7 @@ auto RunTemplateClass(DataType dataType, ArgsT&&... args) return ClassT(std::forward(args)...)(); } } + throw std::runtime_error(fmt::format("FilterUtilities::RunTemplateClass<> Error: dataType did not match any known type. DataType was {}", DataTypeToString(dataType))); } template