#pragma once #include "error/instance.h" #include "error/result.h" #include "objects/annotation.h" #include "objects/base/instance.h" #include "objects/base/refstate.h" #include class Workspace; class DataModel; class Service; // The root instance to all objects in the hierarchy class DEF_INST_(abstract) DataModel : public Instance { AUTOGEN_PREAMBLE private: // void DeserializeService(pugi::xml_node node, RefStateDeserialize); static void cloneService(std::shared_ptr target, std::shared_ptr, RefStateClone); public: std::map> services; std::optional currentFile; DataModel(); void Init(bool runMode = false); static inline std::shared_ptr New() { return std::make_shared(); }; result, NoSuchService> GetService(std::string className); result>, NoSuchService> FindService(std::string className); template std::shared_ptr GetService() { auto result = GetService(T::TYPE.className); return std::dynamic_pointer_cast(result.expect("GetService() was called with a non-service instance type")); } template std::optional> FindService() { auto result = FindService(T::TYPE.className).expect("FindService() was called with a non-service instance type"); if (!result) return std::nullopt; return std::dynamic_pointer_cast(result.value()); } // Saving/loading inline bool HasFile() { return this->currentFile.has_value(); } void SaveToFile(std::optional path = std::nullopt); static std::shared_ptr LoadFromFile(std::string path); std::shared_ptr CloneModel(); };