Changeset View
Changeset View
Standalone View
Standalone View
source/blender/depsgraph/intern/builder/deg_builder_stack.h
- This file was added.
| /* SPDX-License-Identifier: GPL-2.0-or-later | |||||
| * Copyright 2016 Blender Foundation. All rights reserved. */ | |||||
sybren: year! | |||||
| /** \file | |||||
| * \ingroup depsgraph | |||||
| */ | |||||
| #pragma once | |||||
| #include "BLI_utildefines.h" | |||||
| #include "BLI_vector.hh" | |||||
| struct ID; | |||||
| struct bConstraint; | |||||
| struct bPoseChannel; | |||||
| struct ModifierData; | |||||
| namespace blender::deg { | |||||
| class BuilderStack { | |||||
sybrenUnsubmitted Not Done Inline ActionsMight be nice to have a docstring. sybren: Might be nice to have a docstring. | |||||
| public: | |||||
| class Entry { | |||||
| public: | |||||
| explicit Entry(const ID &id) : id_(&id) | |||||
| { | |||||
| } | |||||
| explicit Entry(const bConstraint &constraint) : constraint_(&constraint) | |||||
| { | |||||
| } | |||||
| explicit Entry(const bPoseChannel &pchan) : pchan_(&pchan) | |||||
| { | |||||
| } | |||||
| explicit Entry(const ModifierData &modifier_data) : modifier_data_(&modifier_data) | |||||
| { | |||||
| } | |||||
| private: | |||||
| friend class BuilderStack; | |||||
| const ID *id_ = nullptr; | |||||
| const bConstraint *constraint_ = nullptr; | |||||
| const ModifierData *modifier_data_ = nullptr; | |||||
| const bPoseChannel *pchan_ = nullptr; | |||||
| }; | |||||
| using Stack = Vector<Entry>; | |||||
| class ScopedEntry { | |||||
sybrenUnsubmitted Not Done Inline ActionsAlso needs a docstring, no idea what a "scoped entry" is. sybren: Also needs a docstring, no idea what a "scoped entry" is. | |||||
| public: | |||||
| /* Delete copy constructor and operator: scoped entries are only supposed to be constructed | |||||
| * once and never copied. */ | |||||
| ScopedEntry(const ScopedEntry &other) = delete; | |||||
| ScopedEntry &operator=(const ScopedEntry &other) = delete; | |||||
| /* Move semantic. */ | |||||
| ScopedEntry(ScopedEntry &&other) noexcept : stack_(other.stack_) | |||||
| { | |||||
| other.stack_ = nullptr; | |||||
| } | |||||
| ScopedEntry &operator=(ScopedEntry &&other) | |||||
| { | |||||
| if (this == &other) { | |||||
| return *this; | |||||
| } | |||||
| stack_ = other.stack_; | |||||
| other.stack_ = nullptr; | |||||
| return *this; | |||||
| } | |||||
| ~ScopedEntry() | |||||
| { | |||||
| /* Stack will become nullptr when the entr was moved somewhere else. */ | |||||
sybrenUnsubmitted Not Done Inline Actionstypo sybren: typo | |||||
| if (stack_ != nullptr) { | |||||
| BLI_assert(!stack_->is_empty()); | |||||
| stack_->pop_last(); | |||||
| } | |||||
| } | |||||
| private: | |||||
| friend BuilderStack; | |||||
| explicit ScopedEntry(Stack &stack) : stack_(&stack) | |||||
| { | |||||
| } | |||||
| Stack *stack_; | |||||
| }; | |||||
| BuilderStack() = default; | |||||
| ~BuilderStack() = default; | |||||
| bool is_empty() const | |||||
| { | |||||
| return stack_.is_empty(); | |||||
| } | |||||
| void print_backtrace(std::ostream &stream); | |||||
| template<class... Args> ScopedEntry trace(const Args &...args) | |||||
| { | |||||
| stack_.append_as(args...); | |||||
| return ScopedEntry(stack_); | |||||
| } | |||||
| private: | |||||
| Stack stack_; | |||||
| }; | |||||
| } // namespace blender::deg | |||||
year!