Files
test/source/blender/functions/FN_user_data.hh
Jacques Lucke 6d9b9dd2c3 Refactor: Functions: extract user data to separate header
Previously, the `UserData` and `LocalUserData` classes were only supposed to be
used by the lazy-function system. However, they are generic enough so that they
can also be used by the multi-function system. Therefore, this patch extracts
them into a separate header that can be used in both evaluation systems.

I'm doing this in preparation for being able to pass the geometry nodes logger
to multi-functions, to be able to report errors from there.

Pull Request: https://projects.blender.org/blender/blender/pulls/138861
2025-05-14 10:54:28 +02:00

39 lines
1018 B
C++

/* SPDX-FileCopyrightText: 2025 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#pragma once
#include "BLI_linear_allocator.hh"
namespace blender::fn {
/**
* Extension of #UserData that is thread-local. This avoids accessing e.g.
* `EnumerableThreadSpecific.local()` in every nested lazy-function because the thread local
* data is passed in by the caller.
*/
class LocalUserData {
public:
virtual ~LocalUserData() = default;
};
/**
* This allows passing arbitrary data into a function. For that, #UserData has to be subclassed.
* This mainly exists because it's more type safe than passing a `void *` with no type information
* attached.
*
* Some lazy-functions may expect to find a certain type of user data when executed.
*/
class UserData {
public:
virtual ~UserData() = default;
/**
* Get thread local data for this user-data and the current thread.
*/
virtual destruct_ptr<LocalUserData> get_local(LinearAllocator<> &allocator);
};
} // namespace blender::fn