mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 17:42:43 +00:00 
			
		
		
		
	 7d11edbe17
			
		
	
	
		7d11edbe17
		
	
	
	
	
		
			
			In order to avoid having multiple instances, we were keeping a pointer
to these singleton objects and only allocating them when it was null.
We have `__cxa_guard_{acquire,release}` in the userland, so there's no
need to do this dance, as the compiler will ensure that the constructors
are only called once.
		
	
			
		
			
				
	
	
		
			49 lines
		
	
	
	
		
			1.1 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			49 lines
		
	
	
	
		
			1.1 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| /*
 | |
|  * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
 | |
|  *
 | |
|  * SPDX-License-Identifier: BSD-2-Clause
 | |
|  */
 | |
| 
 | |
| #include "WindowList.h"
 | |
| 
 | |
| WindowList& WindowList::the()
 | |
| {
 | |
|     static WindowList s_the;
 | |
|     return s_the;
 | |
| }
 | |
| 
 | |
| Window* WindowList::find_parent(const Window& window)
 | |
| {
 | |
|     if (!window.parent_identifier().is_valid())
 | |
|         return nullptr;
 | |
|     for (auto& it : m_windows) {
 | |
|         auto& w = *it.value;
 | |
|         if (w.identifier() == window.parent_identifier())
 | |
|             return &w;
 | |
|     }
 | |
|     return nullptr;
 | |
| }
 | |
| 
 | |
| Window* WindowList::window(const WindowIdentifier& identifier)
 | |
| {
 | |
|     auto it = m_windows.find(identifier);
 | |
|     if (it != m_windows.end())
 | |
|         return it->value;
 | |
|     return nullptr;
 | |
| }
 | |
| 
 | |
| Window& WindowList::ensure_window(const WindowIdentifier& identifier)
 | |
| {
 | |
|     auto it = m_windows.find(identifier);
 | |
|     if (it != m_windows.end())
 | |
|         return *it->value;
 | |
|     auto window = make<Window>(identifier);
 | |
|     auto& window_ref = *window;
 | |
|     m_windows.set(identifier, move(window));
 | |
|     return window_ref;
 | |
| }
 | |
| 
 | |
| void WindowList::remove_window(const WindowIdentifier& identifier)
 | |
| {
 | |
|     m_windows.remove(identifier);
 | |
| }
 |