[vlc-devel] commit: Skins2: Add ptrmap<> to possibly prevent some more empty nodes. ( JP Dinger )

git version control git at videolan.org
Sat Dec 5 22:35:10 CET 2009


vlc | branch: master | JP Dinger <jpd at videolan.org> | Sat Nov 21 15:57:02 2009 +0100| [316c9f43f173e057d0cee3c12493e9b8311e3d4e] | committer: JP Dinger 

Skins2: Add ptrmap<> to possibly prevent some more empty nodes.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=316c9f43f173e057d0cee3c12493e9b8311e3d4e
---

 modules/gui/skins2/x11/x11_factory.hpp |   30 ++++++++++++++++++++++++++----
 1 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/modules/gui/skins2/x11/x11_factory.hpp b/modules/gui/skins2/x11/x11_factory.hpp
index be1c0f9..df8986a 100644
--- a/modules/gui/skins2/x11/x11_factory.hpp
+++ b/modules/gui/skins2/x11/x11_factory.hpp
@@ -38,11 +38,33 @@ class X11TimerLoop;
 /// Class used to instanciate X11 specific objects
 class X11Factory: public OSFactory
 {
+private:
+    /** ptrmap is an associative container (like std::map, in fact it builds
+      * on std::map) that provides only operator[] in non-const and const
+      * variants, and has the property that a (const) lookup of a non-existent
+      * key does not cause an empty node to be inserted. Instead it returns
+      * NULL if there was no entry; so it only stores pointers. */
+    template<class K, class V> class ptrmap {
+    private:
+        typedef V *value_type;
+        typedef std::map<K,value_type> map_t;
+        map_t m_map;
+        ptrmap &operator=(const ptrmap &);
+        ptrmap(const ptrmap &);
+    public:
+        ptrmap() { }
+        value_type &operator[](K k) { return m_map.operator[](k); }
+        value_type  operator[](K k) const
+        {
+            typename map_t::const_iterator i=m_map.find(k);
+            return i!=m_map.end() ? i->second : NULL;
+        }
+    };
 public:
-    /// Map to find the GenericWindow associated to a X11Window
-    map<Window, GenericWindow*> m_windowMap;
-    /// Map to find the Dnd object associated to a X11Window
-    map<Window, X11DragDrop*> m_dndMap;
+    /// Map to find the GenericWindow* associated to a X11Window
+    ptrmap<Window, GenericWindow> m_windowMap;
+    /// Map to find the Dnd object (X11DragDrop*) associated to a X11Window
+    ptrmap<Window, X11DragDrop> m_dndMap;
 
     X11Factory( intf_thread_t *pIntf );
     virtual ~X11Factory();




More information about the vlc-devel mailing list