Skip to content

Commit

Permalink
NonParamState tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
jatinchowdhury18 committed Nov 22, 2024
1 parent bd9001a commit 24b539b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <__filesystem/directory_iterator.h>
namespace chowdsp
{
inline void NonParamState::addStateValues (const std::initializer_list<StateValueBase*>& newStateValues)
Expand All @@ -14,8 +15,17 @@ inline void NonParamState::addStateValues (nonstd::span<StateValue<T>> newStateV
validateStateValues();
}

template <typename ContainerType>
inline void NonParamState::addStateValues (ContainerType& container)
{
for (auto& val : container)
values.push_back (&val);
validateStateValues();
}

inline void NonParamState::validateStateValues() const
{
#if JUCE_DEBUG
std::vector<std::string_view> stateValueNames;
for (const auto& value : values)
{
Expand All @@ -29,6 +39,7 @@ inline void NonParamState::validateStateValues() const
}

jassert (stateValueNames.size() == values.size()); // something has gone horrible wrong!
#endif
}

template <typename Serializer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ class NonParamState
template <typename T>
void addStateValues (nonstd::span<StateValue<T>> newStateValues);

/** Adds more state values to this state. */
template <typename ContainerType>
void addStateValues (ContainerType& container);

/** Custom serializer */
template <typename Serializer>
static typename Serializer::SerializedType serialize (const NonParamState& state);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ std::enable_if_t<TypeTraits::IsIterable<ParamContainerType>, void>

inline void ParamHolder::clear()
{
jassertfalse; // for now!

// It's generally not safe to clear the parameters if this is an owning ParamHolder
// since we're almost certainly leaving some dangling references lying around!
jassert (! isOwning);
Expand Down

0 comments on commit 24b539b

Please sign in to comment.