Skip to content

Commit

Permalink
Adding arena helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
jatinchowdhury18 committed Jul 7, 2024
1 parent 38f4fa5 commit 17f43a0
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,10 @@ inline juce::String toString (const std::string_view& sv) noexcept
{
return juce::String::fromUTF8 (sv.data(), (int) sv.size());
}

inline std::string_view toStringView (const juce::String& str) noexcept
{
return { str.toRawUTF8(), str.getNumBytesAsUTF8() };
}
#endif
} // namespace chowdsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once

namespace chowdsp::arena
{
template <typename T, typename I, typename Arena>
std::span<T> make_span (Arena& arena, I size, size_t alignment = alignof (T))
{
return { arena.template allocate<T> (size, alignment), static_cast<size_t> (size) };
}

template <typename Arena>
std::string_view alloc_string (Arena& arena, const std::string_view& str)
{
auto* data = arena.template allocate<char> (str.size());
std::copy (str.begin(), str.end(), data);
return std::string_view { data, str.size() }; // NOLINT
};

#if CHOWDSP_USING_JUCE
template <typename Arena>
std::string_view alloc_string (Arena& arena, const juce::String& str)
{
return alloc_string (arena, toStringView (str));
}
#endif
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ BEGIN_JUCE_MODULE_DECLARATION
#include "Allocators/chowdsp_ArenaAllocator.h"
#include "Allocators/chowdsp_ChainedArenaAllocator.h"
#include "Allocators/chowdsp_STLArenaAllocator.h"
#include "Helpers/chowdsp_ArenaHelpers.h"

#include "Structures/chowdsp_BucketArray.h"
#include "Structures/chowdsp_AbstractTree.h"
Expand Down

0 comments on commit 17f43a0

Please sign in to comment.