OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::anonymous_namespace{PluginHostUi.cpp}::UiRegistry Class Reference
Collaboration diagram for Slic3r::anonymous_namespace{PluginHostUi.cpp}::UiRegistry:

Public Member Functions

int reserve_id ()
void bind (int id, wxWindow *window, const std::string &plugin_key)
void remove (int id)
template<typename T>
T * get_as (int id)
bool is_open (int id)
std::vector< wxWindow * > take_for_plugin (const std::string &plugin_key)
void bind_callback (const CallablePtr &callback, const std::string &plugin_key)
std::vector< CallablePtr > take_callbacks_for_plugin (const std::string &plugin_key)

Static Public Member Functions

static UiRegistry & instance ()

Private Attributes

std::mutex m_mtx
std::unordered_map< int, wxWindow * > m_resources
std::unordered_map< int, std::string > m_owners
std::unordered_map< std::string, std::vector< std::weak_ptr< GilSafeCallable > > > m_callbacks
int m_next_id {1}

Detailed Description

Member Function Documentation

◆ bind()

void Slic3r::anonymous_namespace{PluginHostUi.cpp}::UiRegistry::bind ( int id,
wxWindow * window,
const std::string & plugin_key )
inline
166 {
167 std::lock_guard<std::mutex> lk(m_mtx);
168 m_resources[id] = window;
169 m_owners[id] = plugin_key;
170 }
std::mutex m_mtx
Definition PluginHostUi.cpp:234
std::unordered_map< int, std::string > m_owners
Definition PluginHostUi.cpp:236
std::unordered_map< int, wxWindow * > m_resources
Definition PluginHostUi.cpp:235

References m_mtx, m_owners, and m_resources.

◆ bind_callback()

void Slic3r::anonymous_namespace{PluginHostUi.cpp}::UiRegistry::bind_callback ( const CallablePtr & callback,
const std::string & plugin_key )
inline
211 {
212 if (!callback)
213 return;
214 std::lock_guard<std::mutex> lk(m_mtx);
215 m_callbacks[plugin_key].push_back(callback);
216 }
std::unordered_map< std::string, std::vector< std::weak_ptr< GilSafeCallable > > > m_callbacks
Definition PluginHostUi.cpp:237

References m_callbacks, and m_mtx.

◆ get_as()

template<typename T>
T * Slic3r::anonymous_namespace{PluginHostUi.cpp}::UiRegistry::get_as ( int id)
inline
180 {
181 std::lock_guard<std::mutex> lk(m_mtx);
182 auto it = m_resources.find(id);
183 if (it == m_resources.end())
184 return nullptr;
185 return dynamic_cast<T*>(it->second);
186 }

References m_mtx, and m_resources.

◆ instance()

◆ is_open()

bool Slic3r::anonymous_namespace{PluginHostUi.cpp}::UiRegistry::is_open ( int id)
inline
188 {
189 std::lock_guard<std::mutex> lk(m_mtx);
190 return m_resources.count(id) > 0; // presence only; no pointer deref -> thread-safe
191 }

References m_mtx, and m_resources.

◆ remove()

void Slic3r::anonymous_namespace{PluginHostUi.cpp}::UiRegistry::remove ( int id)
inline
172 {
173 std::lock_guard<std::mutex> lk(m_mtx);
174 m_resources.erase(id);
175 m_owners.erase(id);
176 }

References m_mtx, m_owners, and m_resources.

◆ reserve_id()

int Slic3r::anonymous_namespace{PluginHostUi.cpp}::UiRegistry::reserve_id ( )
inline
161 {
162 std::lock_guard<std::mutex> lk(m_mtx);
163 return m_next_id++;
164 }

References m_mtx, and m_next_id.

◆ take_callbacks_for_plugin()

std::vector< CallablePtr > Slic3r::anonymous_namespace{PluginHostUi.cpp}::UiRegistry::take_callbacks_for_plugin ( const std::string & plugin_key)
inline
218 {
219 std::lock_guard<std::mutex> lk(m_mtx);
220 auto it = m_callbacks.find(plugin_key);
221 if (it == m_callbacks.end())
222 return {};
223 std::vector<CallablePtr> callbacks;
224 callbacks.reserve(it->second.size());
225 for (const std::weak_ptr<GilSafeCallable>& weak_callback : it->second) {
226 if (auto callback = weak_callback.lock())
227 callbacks.push_back(std::move(callback));
228 }
229 m_callbacks.erase(it);
230 return callbacks;
231 }

References m_callbacks, and m_mtx.

◆ take_for_plugin()

std::vector< wxWindow * > Slic3r::anonymous_namespace{PluginHostUi.cpp}::UiRegistry::take_for_plugin ( const std::string & plugin_key)
inline
193 {
194 std::lock_guard<std::mutex> lk(m_mtx);
195 std::vector<wxWindow*> out;
196 for (auto it = m_owners.begin(); it != m_owners.end();) {
197 if (it->second == plugin_key) {
198 auto rit = m_resources.find(it->first);
199 if (rit != m_resources.end()) {
200 out.push_back(rit->second);
201 m_resources.erase(rit);
202 }
203 it = m_owners.erase(it);
204 } else {
205 ++it;
206 }
207 }
208 return out;
209 }

References m_mtx, m_owners, and m_resources.

Member Data Documentation

◆ m_callbacks

std::unordered_map<std::string, std::vector<std::weak_ptr<GilSafeCallable> > > Slic3r::anonymous_namespace{PluginHostUi.cpp}::UiRegistry::m_callbacks
private

◆ m_mtx

std::mutex Slic3r::anonymous_namespace{PluginHostUi.cpp}::UiRegistry::m_mtx
private

◆ m_next_id

int Slic3r::anonymous_namespace{PluginHostUi.cpp}::UiRegistry::m_next_id {1}
private
238{1};

Referenced by reserve_id().

◆ m_owners

std::unordered_map<int, std::string> Slic3r::anonymous_namespace{PluginHostUi.cpp}::UiRegistry::m_owners
private

Referenced by bind(), remove(), and take_for_plugin().

◆ m_resources

std::unordered_map<int, wxWindow*> Slic3r::anonymous_namespace{PluginHostUi.cpp}::UiRegistry::m_resources
private

The documentation for this class was generated from the following file:
  • /home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/plugin/host/PluginHostUi.cpp