]> git.saurik.com Git - wxWidgets.git/commitdiff
use typed containers in wxHtmlParser instead of type-unsafe wxList/wxHashTable
authorVáclav Slavík <vslavik@fastmail.fm>
Fri, 5 Oct 2007 22:56:55 +0000 (22:56 +0000)
committerVáclav Slavík <vslavik@fastmail.fm>
Fri, 5 Oct 2007 22:56:55 +0000 (22:56 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@49057 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/html/helpwnd.h
include/wx/html/htmlpars.h
src/html/htmlpars.cpp

index cfe0bad1a627b00da8b05efd8c29a6b9788ee78d..fe5d3aa6ddd0b416072f5593926886d6d9d5355a 100644 (file)
@@ -28,6 +28,7 @@
 #include "wx/combobox.h"
 #include "wx/checkbox.h"
 #include "wx/stattext.h"
+#include "wx/hash.h"
 #include "wx/html/htmlwin.h"
 #include "wx/html/htmprint.h"
 
index 6fe3d7f78022d20c48ba84ec65d9685495c8fa97..92dc1be5756bc6e8b79846a2a7b06f356c5bcfc0 100644 (file)
@@ -15,7 +15,9 @@
 
 #include "wx/html/htmltag.h"
 #include "wx/filesys.h"
-#include "wx/hash.h"
+#include "wx/hashmap.h"
+#include "wx/hashset.h"
+#include "wx/vector.h"
 #include "wx/fontenc.h"
 
 class WXDLLIMPEXP_FWD_BASE wxMBConv;
@@ -26,6 +28,14 @@ class WXDLLIMPEXP_FWD_HTML wxHtmlEntitiesParser;
 class wxHtmlTextPieces;
 class wxHtmlParserState;
 
+WX_DECLARE_HASH_SET_WITH_DECL(wxHtmlTagHandler*,
+                              wxPointerHash, wxPointerEqual,
+                              wxHtmlTagHandlersSet,
+                              class WXDLLIMPEXP_HTML);
+WX_DECLARE_STRING_HASH_MAP_WITH_DECL(wxHtmlTagHandler*,
+                                     wxHtmlTagHandlersHash,
+                                     class WXDLLIMPEXP_HTML);
+
 
 enum wxHtmlURLType
 {
@@ -178,15 +188,15 @@ protected:
     //      it may (and often does) contain more references to one object
     // m_HandlersList is list of all handlers and it is guaranteed to contain
     //      only one reference to each handler instance.
-    wxList m_HandlersList;
-    wxHashTable m_HandlersHash;
+    wxHtmlTagHandlersSet m_HandlersSet;
+    wxHtmlTagHandlersHash m_HandlersHash;
 
     DECLARE_NO_COPY_CLASS(wxHtmlParser)
 
     // class for opening files (file system)
     wxFileSystem *m_FS;
     // handlers stack used by PushTagHandler and PopTagHandler
-    wxList *m_HandlersStack;
+    wxVector<wxHtmlTagHandlersHash*> m_HandlersStack;
 
     // entity parse
     wxHtmlEntitiesParser *m_entitiesParser;
index 201aeecef4fdada002b384928ae89df6ff297307..f89b6f579f561a08ac4d2449f5b71b550299e065 100644 (file)
@@ -77,8 +77,8 @@ public:
 IMPLEMENT_ABSTRACT_CLASS(wxHtmlParser,wxObject)
 
 wxHtmlParser::wxHtmlParser()
-    : wxObject(), m_HandlersHash(wxKEY_STRING),
-      m_FS(NULL), m_HandlersStack(NULL)
+    : wxObject(),
+      m_FS(NULL)
 {
     m_Source = NULL;
     m_entitiesParser = new wxHtmlEntitiesParser;
@@ -94,17 +94,8 @@ wxHtmlParser::~wxHtmlParser()
     while (RestoreState()) {}
     DestroyDOMTree();
 
-    if (m_HandlersStack)
-    {
-        wxList& tmp = *m_HandlersStack;
-        wxList::iterator it, en;
-        for( it = tmp.begin(), en = tmp.end(); it != en; ++it )
-            delete (wxHashTable*)*it;
-        tmp.clear();
-    }
-    delete m_HandlersStack;
-    m_HandlersHash.Clear();
-    WX_CLEAR_LIST(wxList, m_HandlersList);
+    WX_CLEAR_ARRAY(m_HandlersStack);
+    WX_CLEAR_HASH_SET(wxHtmlTagHandlersSet, m_HandlersSet);
     delete m_entitiesParser;
     delete m_Source;
 }
@@ -318,13 +309,12 @@ void wxHtmlParser::DoParsing(const wxString::const_iterator& begin_pos_,
 
 void wxHtmlParser::AddTag(const wxHtmlTag& tag)
 {
-    wxHtmlTagHandler *h;
     bool inner = false;
 
-    h = (wxHtmlTagHandler*) m_HandlersHash.Get(tag.GetName());
-    if (h)
+    wxHtmlTagHandlersHash::const_iterator h = m_HandlersHash.find(tag.GetName());
+    if (h != m_HandlersHash.end())
     {
-        inner = h->HandleTag(tag);
+        inner = h->second->HandleTag(tag);
         if (m_stopParsing)
             return;
     }
@@ -341,10 +331,9 @@ void wxHtmlParser::AddTagHandler(wxHtmlTagHandler *handler)
     wxStringTokenizer tokenizer(s, wxT(", "));
 
     while (tokenizer.HasMoreTokens())
-        m_HandlersHash.Put(tokenizer.GetNextToken(), handler);
+        m_HandlersHash[tokenizer.GetNextToken()] = handler;
 
-    if (m_HandlersList.IndexOf(handler) == wxNOT_FOUND)
-        m_HandlersList.Append(handler);
+    m_HandlersSet.insert(handler);
 
     handler->SetParser(this);
 }
@@ -354,39 +343,24 @@ void wxHtmlParser::PushTagHandler(wxHtmlTagHandler *handler, const wxString& tag
     wxStringTokenizer tokenizer(tags, wxT(", "));
     wxString key;
 
-    if (m_HandlersStack == NULL)
-    {
-        m_HandlersStack = new wxList;
-    }
-
-    m_HandlersStack->Insert((wxObject*)new wxHashTable(m_HandlersHash));
+    m_HandlersStack.push_back(new wxHtmlTagHandlersHash(m_HandlersHash));
 
     while (tokenizer.HasMoreTokens())
     {
         key = tokenizer.GetNextToken();
-        m_HandlersHash.Delete(key);
-        m_HandlersHash.Put(key, handler);
+        m_HandlersHash[key] = handler;
     }
 }
 
 void wxHtmlParser::PopTagHandler()
 {
-    wxList::compatibility_iterator first;
-
-    if ( !m_HandlersStack ||
-#if wxUSE_STL
-         !(first = m_HandlersStack->GetFirst())
-#else // !wxUSE_STL
-         ((first = m_HandlersStack->GetFirst()) == NULL)
-#endif // wxUSE_STL/!wxUSE_STL
-        )
-    {
-        wxLogWarning(_("Warning: attempt to remove HTML tag handler from empty stack."));
-        return;
-    }
-    m_HandlersHash = *((wxHashTable*) first->GetData());
-    delete (wxHashTable*) first->GetData();
-    m_HandlersStack->Erase(first);
+    wxCHECK_RET( !m_HandlersStack.empty(),
+                 "attempt to remove HTML tag handler from empty stack" );
+
+    wxHtmlTagHandlersHash *prev = m_HandlersStack.back();
+    m_HandlersStack.pop_back();
+    m_HandlersHash = *prev;
+    delete prev;
 }
 
 void wxHtmlParser::SetSourceAndSaveState(const wxString& src)