From 9985b5de0fc41bc9c41adfadc363ec66c7611e03 Mon Sep 17 00:00:00 2001 From: Warmist Date: Thu, 4 Aug 2011 22:00:21 +0300 Subject: [PATCH] DFHack::Core modification: added a way to share void* between plugins and/or plugin unloads. --- library/Core.cpp | 13 +++++++++++++ library/include/dfhack/Core.h | 7 +++++++ 2 files changed, 20 insertions(+) diff --git a/library/Core.cpp b/library/Core.cpp index e3f0263a7..bf9b9fa2f 100644 --- a/library/Core.cpp +++ b/library/Core.cpp @@ -469,6 +469,19 @@ std::string Core::getHotkeyCmd( void ) return returner; } +void Core::RegisterData(void *p,std::string key) +{ + misc_data_map[key]=p; +} + +void *Core::GetData(std::string key) +{ + std::map::iterator it=misc_data_map.find(key); + if (it!=misc_data_map.end()) + return misc_data_map[key]; + else + return 0;// or throw an error. +} void Core::Suspend() { diff --git a/library/include/dfhack/Core.h b/library/include/dfhack/Core.h index 9d5b1fe5a..dab39f858 100644 --- a/library/include/dfhack/Core.h +++ b/library/include/dfhack/Core.h @@ -126,6 +126,11 @@ namespace DFHack /// removes the hotkey command and gives it to the caller thread std::string getHotkeyCmd( void ); + /// adds a named pointer (for later or between plugins) + void RegisterData(void *p,std::string key); + /// returns a named pointer. + void *GetData(std::string key); + DFHack::Process * p; DFHack::VersionInfo * vinfo; DFHack::Console con; @@ -174,5 +179,7 @@ namespace DFHack tthread::condition_variable * HotkeyCond; // Very important! bool started; + + std::map misc_data_map; }; }