[vlc-devel] commit: Skins2: Reduce another macro to bare minimum and helper fuction. ( JP Dinger )

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


vlc | branch: master | JP Dinger <jpd at videolan.org> | Sun Nov 22 13:41:51 2009 +0100| [0fb4941ed0764730d43d3078e05ae883d6c09fe0] | committer: JP Dinger 

Skins2: Reduce another macro to bare minimum and helper fuction.

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

 modules/gui/skins2/parser/builder.cpp |   27 ++++++++++++++-------------
 modules/gui/skins2/parser/builder.hpp |    4 ++++
 2 files changed, 18 insertions(+), 13 deletions(-)

diff --git a/modules/gui/skins2/parser/builder.cpp b/modules/gui/skins2/parser/builder.cpp
index 3606f2a..b3f6ff4 100644
--- a/modules/gui/skins2/parser/builder.cpp
+++ b/modules/gui/skins2/parser/builder.cpp
@@ -75,24 +75,23 @@ CmdGeneric *Builder::parseAction( const string &rAction )
     return Interpreter::instance( getIntf() )->parseAction( rAction, m_pTheme );
 }
 
-
-// Useful macro
-#define ADD_OBJECTS( type ) \
-    list<BuilderData::type>::const_iterator it##type; \
-    for( it##type = m_rData.m_list##type.begin(); \
-         it##type != m_rData.m_list##type.end(); it##type++ ) \
-    { \
-        add##type( *it##type ); \
-    }
-
+template<class T> inline
+void Builder::add_objects(const std::list<T> &list,
+                          void (Builder::*addfn)(const T &))
+{
+    typename std::list<T>::const_iterator i;
+    for( i = list.begin(); i != list.end(); ++i )
+        (this->*addfn)( *i );
+}
 
 Theme *Builder::build()
 {
-    m_pTheme = new Theme( getIntf() );
+#define ADD_OBJECTS( type ) \
+    add_objects(m_rData.m_list##type,&Builder::add##type)
+
+    m_pTheme = new (std::nothrow) Theme( getIntf() );
     if( m_pTheme == NULL )
-    {
         return NULL;
-    }
 
     // Create everything from the data in the XML
     ADD_OBJECTS( Theme );
@@ -123,6 +122,8 @@ Theme *Builder::build()
     ADD_OBJECTS( MenuSeparator );
 
     return m_pTheme;
+
+#undef  ADD_OBJECTS
 }
 
 
diff --git a/modules/gui/skins2/parser/builder.hpp b/modules/gui/skins2/parser/builder.hpp
index c7e4b33..09dfd15 100644
--- a/modules/gui/skins2/parser/builder.hpp
+++ b/modules/gui/skins2/parser/builder.hpp
@@ -91,6 +91,10 @@ private:
     void addTree( const BuilderData::Tree &rData );
     void addVideo( const BuilderData::Video &rData );
 
+    /// Helper for build(); gluing BuilderData::list<T>s to addType(T&)
+    template<class T> void add_objects(const std::list<T> &list,
+                                       void (Builder::*addfn)(const T &));
+
     /// Compute the position of a control
     const Position makePosition( const string &rLeftTop,
                                  const string &rRightBottom,




More information about the vlc-devel mailing list