24 #include <flw/flf/models/base/ITreeNode.h> 25 #include <flw/cmn/Containers.h> 40 template <
class T,
class C = ITreeNode>
44 : mFlagAttachedDetached(
true) {
58 void attach(std::unique_ptr<T>&& node) {
59 if (node.get() ==
this) {
63 node->onAttached(
this);
64 mChildren.push_back(std::move(node));
65 mFlagAttachedDetached =
true;
68 template <
typename TNode,
typename ...TArguments>
69 void attachNew(TArguments ...args) {
70 attach(std::make_unique<TNode>(args...));
73 void detach(T* node) {
74 auto _compare_function = [node](std::unique_ptr<T>
const& e) ->
bool {
75 bool found = (e.get() == node);
81 auto it = std::remove_if(mChildren.begin(), mChildren.end(), _compare_function);
82 if (it != mChildren.end()) {
83 mFlagAttachedDetached =
true;
84 mChildren.erase(it, mChildren.end());
92 virtual void onDetached() {
96 void detachChildren() {
97 std::for_each(mChildren.begin(), mChildren.end(), [](std::unique_ptr<T> &e) {
103 bool isAttachedDetached() {
104 bool result = mFlagAttachedDetached;
105 mFlagAttachedDetached =
false;
106 for (
auto &it : mChildren) {
107 result = it->isAttachedDetached() ?
true : result;
112 bool mFlagAttachedDetached;
115 vec<std::unique_ptr<T>> mChildren;
Basic tree ITreeNode Interface.
Definition: ITreeNode.h:31
Basic tree template class. Enables attaching and detaching nodes.
Definition: TreePtr.h:41