cleaned up GetExtElements and make available outside the addon manager
authorJonathan Marshall <jmarshall@never.you.mind>
Sat, 19 Feb 2011 06:14:06 +0000 (19:14 +1300)
committerJonathan Marshall <jmarshall@never.you.mind>
Sun, 1 May 2011 07:18:01 +0000 (19:18 +1200)
xbmc/addons/AddonManager.cpp
xbmc/addons/AddonManager.h

index fe3f491..61e1e6b 100644 (file)
@@ -55,7 +55,6 @@ namespace ADDON
 cp_log_severity_t clog_to_cp(int lvl);
 void cp_fatalErrorHandler(const char *msg);
 void cp_logger(cp_log_severity_t level, const char *msg, const char *apid, void *user_data);
-bool GetExtElementDeque(DEQUEELEMENTS &elements, cp_cfg_element_t *base, const char *path);
 
 /**********************************************************
  * CAddonMgr
@@ -149,12 +148,11 @@ bool CAddonMgr::CheckUserDirs(const cp_cfg_element_t *settings)
   if (!userdirs)
     return false;
 
-  DEQUEELEMENTS elements;
-  bool status = GetExtElementDeque(elements, (cp_cfg_element_t *)userdirs, "userdir");
-  if (!status)
+  ELEMENTS elements;
+  if (!GetExtElements((cp_cfg_element_t *)userdirs, "userdir", elements))
     return false;
 
-  IDEQUEELEMENTS itr = elements.begin();
+  ELEMENTS::iterator itr = elements.begin();
   while (itr != elements.end())
   {
     CStdString path = GetExtValue(*itr++, "@path");
@@ -550,25 +548,19 @@ const cp_cfg_element_t *CAddonMgr::GetExtElement(cp_cfg_element_t *base, const c
   return element;
 }
 
-/* Returns all duplicate elements from a base element */
-bool GetExtElementDeque(DEQUEELEMENTS &elements, cp_cfg_element_t *base, const char *path)
+bool CAddonMgr::GetExtElements(cp_cfg_element_t *base, const char *path, ELEMENTS &elements)
 {
-  if (!base)
+  if (!base || !path)
     return false;
 
-  unsigned int i = 0;
-  while (true)
+  for (unsigned int i = 0; i < base->num_children; i++)
   {
-    if (i >= base->num_children)
-      break;
-    CStdString temp = (base->children+i)->name;
+    CStdString temp = base->children[i].name;
     if (!temp.compare(path))
-      elements.push_back(base->children+i);
-    i++;
+      elements.push_back(&base->children[i]);
   }
 
-  if (elements.empty()) return false;
-  return true;
+  return !elements.empty();
 }
 
 const cp_extension_t *CAddonMgr::GetExtension(const cp_plugin_info_t *props, const char *extension) const
index 09a3c23..185b4ca 100644 (file)
@@ -37,8 +37,7 @@ namespace ADDON
 {
   typedef std::map<TYPE, VECADDONS> MAPADDONS;
   typedef std::map<TYPE, VECADDONS>::iterator IMAPADDONS;
-  typedef std::deque<cp_cfg_element_t*> DEQUEELEMENTS;
-  typedef std::deque<cp_cfg_element_t*>::iterator IDEQUEELEMENTS;
+  typedef std::vector<cp_cfg_element_t*> ELEMENTS;
 
   const CStdString ADDON_METAFILE             = "description.xml";
   const CStdString ADDON_VIS_EXT              = "*.vis";
@@ -114,6 +113,14 @@ namespace ADDON
     /* libcpluff */
     CStdString GetExtValue(cp_cfg_element_t *base, const char *path);
 
+    /*! \brief Retrieve a vector of repeated elements from a given configuration element
+     \param base the base configuration element.
+     \param path the path to the configuration element from the base element.
+     \param result [out] returned list of elements.
+     \return true if the configuration element is present and the list of elements is non-empty
+     */
+    bool GetExtElements(cp_cfg_element_t *base, const char *path, ELEMENTS &result);
+
     /*! \brief Retrieve a list of strings from a given configuration element
      Assumes the configuration element or attribute contains a whitespace separated list of values (eg xs:list schema).
      \param base the base configuration element.