diff --git a/common/file_base.hh b/common/file_base.hh index fd16a86..56bbb9b 100644 --- a/common/file_base.hh +++ b/common/file_base.hh @@ -1,5 +1,6 @@ #pragma once +#include #include #include @@ -12,24 +13,22 @@ class FileBase : public nf7::File { public: class Feature { public: - Feature() = default; + Feature() = delete; + Feature(nf7::FileBase& f) noexcept { + f.feats_.push_back(this); + } virtual ~Feature() = default; Feature(const Feature&) = delete; Feature(Feature&&) = delete; Feature& operator=(const Feature&) = delete; Feature& operator=(Feature&&) = delete; - // Feature* is just for avoiding multi inheritance issues with Env::Watcher virtual nf7::File* Find(std::string_view) const noexcept { return nullptr; } virtual void Handle(const nf7::File::Event&) noexcept { } virtual void Update() noexcept { } }; - FileBase(const nf7::File::TypeInfo& t, - nf7::Env& env, - std::vector&& feats = {}) noexcept : - nf7::File(t, env), feats_(std::move(feats)) { - } + using nf7::File::File; nf7::File* Find(std::string_view name) const noexcept override { for (auto feat : feats_) { @@ -50,11 +49,6 @@ class FileBase : public nf7::File { } } - protected: - void Install(Feature& f) noexcept { - feats_.push_back(&f); - } - private: std::vector feats_; }; diff --git a/common/file_holder.hh b/common/file_holder.hh index bb166cd..6118c3e 100644 --- a/common/file_holder.hh +++ b/common/file_holder.hh @@ -35,11 +35,12 @@ class FileHolder : public nf7::FileBase::Feature { using Entity = std::variant< std::monostate, nf7::File::Path, std::shared_ptr>; - FileHolder(nf7::File& owner, std::string_view id, + FileHolder(nf7::FileBase& owner, std::string_view id, nf7::MutableMemento* mem = nullptr) noexcept : + nf7::FileBase::Feature(owner), owner_(&owner), mem_(mem), id_(id) { } - FileHolder(nf7::File& owner, std::string_view id, + FileHolder(nf7::FileBase& owner, std::string_view id, nf7::MutableMemento& mem) noexcept : FileHolder(owner, id, &mem) { } diff --git a/common/gui_file.hh b/common/gui_file.hh index 6b5d169..1b92312 100644 --- a/common/gui_file.hh +++ b/common/gui_file.hh @@ -55,7 +55,8 @@ class FileHolderEditor final : public nf7::FileBase::Feature { kRef, }; - FileHolderEditor(nf7::FileHolder& h, FileFactory::Filter&& filter) noexcept : + FileHolderEditor(nf7::FileBase& f, nf7::FileHolder& h, FileFactory::Filter&& filter) noexcept : + nf7::FileBase::Feature(f), holder_(&h), factory_(h.owner(), std::move(filter)) { } FileHolderEditor(const FileHolderEditor&) = delete; diff --git a/common/logger_ref.hh b/common/logger_ref.hh index 4cc71cb..f677e8a 100644 --- a/common/logger_ref.hh +++ b/common/logger_ref.hh @@ -18,8 +18,8 @@ namespace nf7 { class LoggerRef final : public nf7::FileBase::Feature { public: - LoggerRef(nf7::File& f, nf7::File::Path&& p = {"_logger"}) noexcept : - file_(&f), path_(std::move(p)) { + LoggerRef(nf7::FileBase& f, nf7::File::Path&& p = {"_logger"}) noexcept : + nf7::FileBase::Feature(f), file_(&f), path_(std::move(p)) { } LoggerRef(const LoggerRef&) = default; LoggerRef(LoggerRef&&) = default; diff --git a/common/nfile_watcher.hh b/common/nfile_watcher.hh index 11ed453..1a5243a 100644 --- a/common/nfile_watcher.hh +++ b/common/nfile_watcher.hh @@ -12,7 +12,9 @@ namespace nf7 { class NFileWatcher final : public nf7::FileBase::Feature { public: - NFileWatcher() = default; + NFileWatcher() = delete; + NFileWatcher(nf7::FileBase& f) noexcept : nf7::FileBase::Feature(f) { + } NFileWatcher(const NFileWatcher&) = delete; NFileWatcher(NFileWatcher&&) = delete; NFileWatcher& operator=(const NFileWatcher&) = delete; diff --git a/file/audio_device.cc b/file/audio_device.cc index 52ba117..8b57f9c 100644 --- a/file/audio_device.cc +++ b/file/audio_device.cc @@ -100,7 +100,7 @@ class Device final : public nf7::FileBase, public nf7::DirItem, public nf7::Node }; Device(nf7::Env& env, Data&& data = {}) noexcept : - nf7::FileBase(kType, env, {&log_}), + nf7::FileBase(kType, env), nf7::DirItem(nf7::DirItem::kMenu | nf7::DirItem::kTooltip), nf7::Node(nf7::Node::kNone), life_(*this), log_(*this), mem_(std::move(data), *this) { diff --git a/file/font_face.cc b/file/font_face.cc index 852b104..539d385 100644 --- a/file/font_face.cc +++ b/file/font_face.cc @@ -69,14 +69,14 @@ class FontFace final : public nf7::FileBase, }; FontFace(nf7::Env& env, Data&& d = {}) noexcept : - nf7::FileBase(kType, env, {&nwatch_}), + nf7::FileBase(kType, env), nf7::DirItem(nf7::DirItem::kMenu | nf7::DirItem::kTooltip), nf7::Node(nf7::Node::kNone), life_(*this), + nwatch_(*this), log_(std::make_shared(*this)), mem_(std::move(d), *this) { - nf7::FileBase::Install(*log_); mem_.onCommit = mem_.onRestore = nwatch_.onMod = [this]() { cache_ = std::nullopt; }; diff --git a/file/gl_obj.cc b/file/gl_obj.cc index bde5ed6..e6555cb 100644 --- a/file/gl_obj.cc +++ b/file/gl_obj.cc @@ -95,17 +95,14 @@ class ObjBase : public nf7::FileBase, } ObjBase(nf7::Env& env, T&& data = {}) noexcept : - nf7::FileBase(TypeInfo::kType, env, {}), + nf7::FileBase(TypeInfo::kType, env), nf7::DirItem(nf7::DirItem::kMenu | nf7::DirItem::kTooltip), nf7::Node(nf7::Node::kNone), life_(*this), log_(std::make_shared(*this)), - nwatch_(std::make_shared()), + nwatch_(std::make_shared(*this)), mem_(std::move(data), *this) { - nf7::FileBase::Install(*log_); - nf7::FileBase::Install(*nwatch_); - nwatch_->onMod = mem_.onRestore = mem_.onCommit = [this]() { Drop(); }; diff --git a/file/luajit_node.cc b/file/luajit_node.cc index ba0610c..3a17138 100644 --- a/file/luajit_node.cc +++ b/file/luajit_node.cc @@ -62,15 +62,13 @@ class Node final : public nf7::FileBase, public nf7::DirItem, public nf7::Node { }; Node(nf7::Env& env, Data&& data = {}) noexcept : - nf7::FileBase(kType, env, {}), + nf7::FileBase(kType, env), nf7::DirItem(nf7::DirItem::kMenu | nf7::DirItem::kWidget), nf7::Node(nf7::Node::kCustomNode), life_(*this), log_(std::make_shared(*this)), mem_(std::move(data), *this), importer_(std::make_shared(env.npath())) { - nf7::FileBase::Install(*log_); - mem_.onCommit = mem_.onRestore = [this]() { cache_ = std::nullopt; }; diff --git a/file/node_ref.cc b/file/node_ref.cc index eb1bac1..17235bc 100644 --- a/file/node_ref.cc +++ b/file/node_ref.cc @@ -62,8 +62,6 @@ class Ref final : public nf7::FileBase, public nf7::Node { life_(*this), log_(std::make_shared(*this)), mem_(std::move(data), *this) { - nf7::FileBase::Install(*log_); - mem_.onRestore = mem_.onCommit = [this]() { SetUpWatcher(); }; } diff --git a/file/sequencer_adaptor.cc b/file/sequencer_adaptor.cc index 1448f6c..9e27952 100644 --- a/file/sequencer_adaptor.cc +++ b/file/sequencer_adaptor.cc @@ -63,13 +63,13 @@ class Adaptor final : public nf7::FileBase, public nf7::Sequencer { }; Adaptor(nf7::Env& env, Data&& data = {}) noexcept : - nf7::FileBase(kType, env, {&target_, &target_editor_}), + nf7::FileBase(kType, env), Sequencer(Sequencer::kCustomItem | Sequencer::kTooltip | Sequencer::kParamPanel), life_(*this), target_(*this, "target", mem_), - target_editor_(target_, + target_editor_(*this, target_, [](auto& t) { return t.flags().contains("nf7::Sequencer"); }), mem_(std::move(data), *this) { mem_.data().target.SetTarget(target_); diff --git a/file/sequencer_call.cc b/file/sequencer_call.cc index f9290d7..ffa6913 100644 --- a/file/sequencer_call.cc +++ b/file/sequencer_call.cc @@ -48,13 +48,13 @@ class Call final : public nf7::FileBase, public nf7::Sequencer { }; Call(nf7::Env& env, Data&& data = {}) noexcept : - FileBase(kType, env, {&callee_, &callee_editor_}), + nf7::FileBase(kType, env), Sequencer(Sequencer::kCustomItem | Sequencer::kTooltip | Sequencer::kParamPanel), life_(*this), callee_(*this, "callee", mem_), - callee_editor_(callee_, + callee_editor_(*this, callee_, [](auto& t) { return t.flags().contains("nf7::Node"); }), mem_(std::move(data), *this) { mem_.data().callee.SetTarget(callee_); diff --git a/file/sequencer_timeline.cc b/file/sequencer_timeline.cc index a7d0c48..698f08c 100644 --- a/file/sequencer_timeline.cc +++ b/file/sequencer_timeline.cc @@ -69,7 +69,7 @@ class TL final : public nf7::FileBase, public nf7::DirItem, public nf7::Node { std::vector>&& layers = {}, ItemId next = 1, const nf7::gui::Window* win = nullptr) noexcept : - nf7::FileBase(kType, env, {&log_}), + nf7::FileBase(kType, env), nf7::DirItem(nf7::DirItem::kMenu | nf7::DirItem::kWidget), nf7::Node(nf7::Node::kMenu_DirItem), life_(*this), log_(*this), diff --git a/file/system_event.cc b/file/system_event.cc index a84c114..1d354d1 100644 --- a/file/system_event.cc +++ b/file/system_event.cc @@ -44,12 +44,12 @@ class Event final : public nf7::FileBase, public nf7::DirItem, public nf7::Node }; Event(nf7::Env& env, Data&& data = {}) noexcept : - nf7::FileBase(kType, env, {&logger_, &handler_, &handler_editor_}), + nf7::FileBase(kType, env), nf7::DirItem(nf7::DirItem::kMenu | nf7::DirItem::kWidget), nf7::Node(nf7::Node::kMenu_DirItem), life_(*this), logger_(*this), handler_(*this, "handler", mem_), - handler_editor_(handler_, + handler_editor_(*this, handler_, [](auto& t) { return t.flags().contains("nf7::Node"); }), la_root_(std::make_shared(*this)), mem_(std::move(data)) { diff --git a/file/system_logger.cc b/file/system_logger.cc index a4e991f..34e4d7e 100644 --- a/file/system_logger.cc +++ b/file/system_logger.cc @@ -17,7 +17,6 @@ #include "nf7.hh" #include "common/dir_item.hh" -#include "common/file_base.hh" #include "common/generic_context.hh" #include "common/generic_memento.hh" #include "common/generic_type_info.hh" @@ -111,7 +110,7 @@ class Logger final : public nf7::File, }; Logger(nf7::Env& env, Data&& d = {}) noexcept : - File(kType, env), DirItem(DirItem::kMenu), + nf7::File(kType, env), DirItem(DirItem::kMenu), mem_(std::move(d), *this), win_(*this, "Log View") { win_.shown() = true; diff --git a/file/system_nfile.cc b/file/system_nfile.cc index 175a930..3fd00bd 100644 --- a/file/system_nfile.cc +++ b/file/system_nfile.cc @@ -112,16 +112,14 @@ class NFile final : public nf7::FileBase, }; NFile(nf7::Env& env, Data&& data = {}) noexcept : - nf7::FileBase(kType, env, {&nwatch_}), + nf7::FileBase(kType, env), nf7::DirItem(nf7::DirItem::kMenu | nf7::DirItem::kTooltip), nf7::Node(nf7::Node::kMenu_DirItem), - life_(*this), + life_(*this), nwatch_(*this), shared_(std::make_shared(*this)), th_(std::make_shared(*this, Runner {shared_})), mem_(std::move(data), *this) { - nf7::FileBase::Install(shared_->log); - mtx_.onLock = [this]() { SetUp(); }; mtx_.onUnlock = [this]() { shared_->nfile.reset(); }; diff --git a/file/value_plot.cc b/file/value_plot.cc index e271211..7624e39 100644 --- a/file/value_plot.cc +++ b/file/value_plot.cc @@ -110,7 +110,7 @@ class Plot final : public nf7::FileBase, }; Plot(nf7::Env& env, const nf7::gui::Window* win = nullptr, Data&& data = {}) noexcept : - nf7::FileBase(kType, env, {&log_}), + nf7::FileBase(kType, env), nf7::DirItem(nf7::DirItem::kMenu | nf7::DirItem::kWidget), nf7::Node(nf7::Node::kNone), life_(*this), log_(*this), win_(*this, "Plot", win), mem_(std::move(data)) {