Skip to content

Commit

Permalink
Update Soup
Browse files Browse the repository at this point in the history
  • Loading branch information
Sainan committed May 24, 2024
1 parent 46f6add commit a4449d6
Show file tree
Hide file tree
Showing 78 changed files with 1,466 additions and 1,079 deletions.
3 changes: 3 additions & 0 deletions Sun/Sun.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@
<ClCompile Include="vendor\Soup\soup\Capture.cpp" />
<ClCompile Include="vendor\Soup\soup\Compiler.cpp" />
<ClCompile Include="vendor\Soup\soup\crc32.cpp" />
<ClCompile Include="vendor\Soup\soup\filesystem.cpp" />
<ClCompile Include="vendor\Soup\soup\joaat.cpp" />
<ClCompile Include="vendor\Soup\soup\Key.cpp" />
<ClCompile Include="vendor\Soup\soup\main.cpp" />
Expand Down Expand Up @@ -207,6 +208,7 @@
<ClInclude Include="vendor\Soup\soup\deleter.hpp" />
<ClInclude Include="vendor\Soup\soup\Endian.hpp" />
<ClInclude Include="vendor\Soup\soup\Exception.hpp" />
<ClInclude Include="vendor\Soup\soup\filesystem.hpp" />
<ClInclude Include="vendor\Soup\soup\format.hpp" />
<ClInclude Include="vendor\Soup\soup\fwd.hpp" />
<ClInclude Include="vendor\Soup\soup\IntStruct.hpp" />
Expand Down Expand Up @@ -238,6 +240,7 @@
<ClInclude Include="vendor\Soup\soup\StringWriter.hpp" />
<ClInclude Include="vendor\Soup\soup\Thread.hpp" />
<ClInclude Include="vendor\Soup\soup\TinyPngOut.hpp" />
<ClInclude Include="vendor\Soup\soup\type.hpp" />
<ClInclude Include="vendor\Soup\soup\type_traits.hpp" />
<ClInclude Include="vendor\Soup\soup\unicode.hpp" />
<ClInclude Include="vendor\Soup\soup\UniquePtr.hpp" />
Expand Down
9 changes: 9 additions & 0 deletions Sun/Sun.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@
<ClCompile Include="vendor\Soup\soup\crc32.cpp">
<Filter>vendor\Soup</Filter>
</ClCompile>
<ClCompile Include="vendor\Soup\soup\filesystem.cpp">
<Filter>vendor\Soup</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<Filter Include="vendor">
Expand Down Expand Up @@ -225,5 +228,11 @@
<ClInclude Include="vendor\Soup\soup\crc32.hpp">
<Filter>vendor\Soup</Filter>
</ClInclude>
<ClInclude Include="vendor\Soup\soup\filesystem.hpp">
<Filter>vendor\Soup</Filter>
</ClInclude>
<ClInclude Include="vendor\Soup\soup\type.hpp">
<Filter>vendor\Soup</Filter>
</ClInclude>
</ItemGroup>
</Project>
4 changes: 3 additions & 1 deletion Sun/vendor/Soup/soup/AllocRaiiLocalBase.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#pragma once

namespace soup
#include "base.hpp"

NAMESPACE_SOUP
{
struct AllocRaiiLocalBase
{
Expand Down
2 changes: 1 addition & 1 deletion Sun/vendor/Soup/soup/AllocRaiiVirtual.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "memProtFlags.hpp"
#include "os.hpp"

namespace soup
NAMESPACE_SOUP
{
struct AllocRaiiVirtual : public AllocRaiiLocalBase
{
Expand Down
5 changes: 2 additions & 3 deletions Sun/vendor/Soup/soup/AtomicStack.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include "PoppedNode.hpp"

namespace soup
NAMESPACE_SOUP
{
template <typename Data>
struct AtomicStack
Expand All @@ -22,14 +22,13 @@ namespace soup

std::atomic<Node*> head = nullptr;

Node* emplace_front(Data&& data)
void emplace_front(Data&& data)
{
Node* node = new Node(std::move(data));
node->next = head.load();
while (!head.compare_exchange_weak(node->next, node))
{
}
return node;
}

PoppedNode<Node, Data> pop_front() noexcept
Expand Down
81 changes: 80 additions & 1 deletion Sun/vendor/Soup/soup/Callback.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include "Capture.hpp"

namespace soup
NAMESPACE_SOUP
{
template <typename CaptureArgT, typename Ret, typename...Args>
struct CallbackBase
Expand Down Expand Up @@ -114,6 +114,85 @@ namespace soup
}
};

template <typename Ret, typename...Args>
struct Callback<Ret(Args...) noexcept>
{
using FuncT = Ret(Args...) noexcept;
using FuncWithCaptureT = Ret(Args..., Capture&&) noexcept;

FuncWithCaptureT* fp;
Capture cap;

Callback() noexcept
: fp(nullptr)
{
}

Callback(const Callback&) = delete;

Callback(Callback&& b) noexcept
: fp(b.fp), cap(std::move(b.cap))
{
}

Callback(FuncT* fp) noexcept
: fp(reinterpret_cast<FuncWithCaptureT*>(fp))
{
}

Callback(FuncWithCaptureT* fp) noexcept
: fp(fp)
{
}

Callback(FuncWithCaptureT* fp, Capture&& cap) noexcept
: fp(fp), cap(std::move(cap))
{
}

void set(FuncWithCaptureT* fp, Capture&& cap = {}) noexcept
{
this->fp = fp;
this->cap = std::move(cap);
}

void operator=(FuncWithCaptureT* fp) noexcept
{
this->fp = fp;
this->cap.reset();
}

void operator=(Callback&& b) noexcept
{
fp = b.fp;
cap = std::move(b.cap);
}

void operator=(const Callback& b) noexcept = delete;

void operator=(FuncT* fp) noexcept
{
this->fp = reinterpret_cast<FuncWithCaptureT*>(fp);
this->cap.reset();
}

[[nodiscard]] constexpr operator bool() const noexcept
{
return fp != nullptr;
}

void reset()
{
fp = nullptr;
cap.reset();
}

Ret operator() (Args&&...args)
{
return fp(std::forward<Args>(args)..., std::move(cap));
}
};

template <typename Func>
struct EventHandler;

Expand Down
Loading

0 comments on commit a4449d6

Please sign in to comment.