This repository has been archived on 2023-10-09. You can view files and clone it, but cannot push or open issues or pull requests.
Files
blender-archive/source/blender/functions/FN_multi_function_context.hh

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

54 lines
1.2 KiB
C++
Raw Normal View History

/* SPDX-License-Identifier: GPL-2.0-or-later */
#pragma once
/** \file
* \ingroup fn
*
2020-06-25 23:13:02 +10:00
* An #MFContext is passed along with every call to a multi-function. Right now it does nothing,
* but it can be used for the following purposes:
* - Pass debug information up and down the function call stack.
2020-06-25 23:13:02 +10:00
* - Pass reusable memory buffers to sub-functions to increase performance.
* - Pass cached data to called functions.
*/
2020-06-23 12:23:31 +02:00
#include "BLI_utildefines.h"
#include "BLI_map.hh"
2020-07-03 14:25:20 +02:00
namespace blender::fn {
class MFContext;
class MFContextBuilder {
private:
Map<std::string, const void *> global_contexts_;
friend MFContext;
public:
template<typename T> void add_global_context(std::string name, const T *context)
{
global_contexts_.add_new(std::move(name), static_cast<const void *>(context));
}
};
class MFContext {
private:
MFContextBuilder &builder_;
public:
MFContext(MFContextBuilder &builder) : builder_(builder)
{
}
template<typename T> const T *get_global_context(StringRef name) const
{
const void *context = builder_.global_contexts_.lookup_default_as(name, nullptr);
/* TODO: Implement type checking. */
return static_cast<const T *>(context);
}
};
2020-07-03 14:25:20 +02:00
} // namespace blender::fn