use typed containers in wxHtmlParser instead of type-unsafe wxList/wxHashTable
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@49057 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -28,6 +28,7 @@
|
|||||||
#include "wx/combobox.h"
|
#include "wx/combobox.h"
|
||||||
#include "wx/checkbox.h"
|
#include "wx/checkbox.h"
|
||||||
#include "wx/stattext.h"
|
#include "wx/stattext.h"
|
||||||
|
#include "wx/hash.h"
|
||||||
#include "wx/html/htmlwin.h"
|
#include "wx/html/htmlwin.h"
|
||||||
#include "wx/html/htmprint.h"
|
#include "wx/html/htmprint.h"
|
||||||
|
|
||||||
|
@@ -15,7 +15,9 @@
|
|||||||
|
|
||||||
#include "wx/html/htmltag.h"
|
#include "wx/html/htmltag.h"
|
||||||
#include "wx/filesys.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"
|
#include "wx/fontenc.h"
|
||||||
|
|
||||||
class WXDLLIMPEXP_FWD_BASE wxMBConv;
|
class WXDLLIMPEXP_FWD_BASE wxMBConv;
|
||||||
@@ -26,6 +28,14 @@ class WXDLLIMPEXP_FWD_HTML wxHtmlEntitiesParser;
|
|||||||
class wxHtmlTextPieces;
|
class wxHtmlTextPieces;
|
||||||
class wxHtmlParserState;
|
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
|
enum wxHtmlURLType
|
||||||
{
|
{
|
||||||
@@ -178,15 +188,15 @@ protected:
|
|||||||
// it may (and often does) contain more references to one object
|
// it may (and often does) contain more references to one object
|
||||||
// m_HandlersList is list of all handlers and it is guaranteed to contain
|
// m_HandlersList is list of all handlers and it is guaranteed to contain
|
||||||
// only one reference to each handler instance.
|
// only one reference to each handler instance.
|
||||||
wxList m_HandlersList;
|
wxHtmlTagHandlersSet m_HandlersSet;
|
||||||
wxHashTable m_HandlersHash;
|
wxHtmlTagHandlersHash m_HandlersHash;
|
||||||
|
|
||||||
DECLARE_NO_COPY_CLASS(wxHtmlParser)
|
DECLARE_NO_COPY_CLASS(wxHtmlParser)
|
||||||
|
|
||||||
// class for opening files (file system)
|
// class for opening files (file system)
|
||||||
wxFileSystem *m_FS;
|
wxFileSystem *m_FS;
|
||||||
// handlers stack used by PushTagHandler and PopTagHandler
|
// handlers stack used by PushTagHandler and PopTagHandler
|
||||||
wxList *m_HandlersStack;
|
wxVector<wxHtmlTagHandlersHash*> m_HandlersStack;
|
||||||
|
|
||||||
// entity parse
|
// entity parse
|
||||||
wxHtmlEntitiesParser *m_entitiesParser;
|
wxHtmlEntitiesParser *m_entitiesParser;
|
||||||
|
@@ -77,8 +77,8 @@ public:
|
|||||||
IMPLEMENT_ABSTRACT_CLASS(wxHtmlParser,wxObject)
|
IMPLEMENT_ABSTRACT_CLASS(wxHtmlParser,wxObject)
|
||||||
|
|
||||||
wxHtmlParser::wxHtmlParser()
|
wxHtmlParser::wxHtmlParser()
|
||||||
: wxObject(), m_HandlersHash(wxKEY_STRING),
|
: wxObject(),
|
||||||
m_FS(NULL), m_HandlersStack(NULL)
|
m_FS(NULL)
|
||||||
{
|
{
|
||||||
m_Source = NULL;
|
m_Source = NULL;
|
||||||
m_entitiesParser = new wxHtmlEntitiesParser;
|
m_entitiesParser = new wxHtmlEntitiesParser;
|
||||||
@@ -94,17 +94,8 @@ wxHtmlParser::~wxHtmlParser()
|
|||||||
while (RestoreState()) {}
|
while (RestoreState()) {}
|
||||||
DestroyDOMTree();
|
DestroyDOMTree();
|
||||||
|
|
||||||
if (m_HandlersStack)
|
WX_CLEAR_ARRAY(m_HandlersStack);
|
||||||
{
|
WX_CLEAR_HASH_SET(wxHtmlTagHandlersSet, m_HandlersSet);
|
||||||
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);
|
|
||||||
delete m_entitiesParser;
|
delete m_entitiesParser;
|
||||||
delete m_Source;
|
delete m_Source;
|
||||||
}
|
}
|
||||||
@@ -318,13 +309,12 @@ void wxHtmlParser::DoParsing(const wxString::const_iterator& begin_pos_,
|
|||||||
|
|
||||||
void wxHtmlParser::AddTag(const wxHtmlTag& tag)
|
void wxHtmlParser::AddTag(const wxHtmlTag& tag)
|
||||||
{
|
{
|
||||||
wxHtmlTagHandler *h;
|
|
||||||
bool inner = false;
|
bool inner = false;
|
||||||
|
|
||||||
h = (wxHtmlTagHandler*) m_HandlersHash.Get(tag.GetName());
|
wxHtmlTagHandlersHash::const_iterator h = m_HandlersHash.find(tag.GetName());
|
||||||
if (h)
|
if (h != m_HandlersHash.end())
|
||||||
{
|
{
|
||||||
inner = h->HandleTag(tag);
|
inner = h->second->HandleTag(tag);
|
||||||
if (m_stopParsing)
|
if (m_stopParsing)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -341,10 +331,9 @@ void wxHtmlParser::AddTagHandler(wxHtmlTagHandler *handler)
|
|||||||
wxStringTokenizer tokenizer(s, wxT(", "));
|
wxStringTokenizer tokenizer(s, wxT(", "));
|
||||||
|
|
||||||
while (tokenizer.HasMoreTokens())
|
while (tokenizer.HasMoreTokens())
|
||||||
m_HandlersHash.Put(tokenizer.GetNextToken(), handler);
|
m_HandlersHash[tokenizer.GetNextToken()] = handler;
|
||||||
|
|
||||||
if (m_HandlersList.IndexOf(handler) == wxNOT_FOUND)
|
m_HandlersSet.insert(handler);
|
||||||
m_HandlersList.Append(handler);
|
|
||||||
|
|
||||||
handler->SetParser(this);
|
handler->SetParser(this);
|
||||||
}
|
}
|
||||||
@@ -354,39 +343,24 @@ void wxHtmlParser::PushTagHandler(wxHtmlTagHandler *handler, const wxString& tag
|
|||||||
wxStringTokenizer tokenizer(tags, wxT(", "));
|
wxStringTokenizer tokenizer(tags, wxT(", "));
|
||||||
wxString key;
|
wxString key;
|
||||||
|
|
||||||
if (m_HandlersStack == NULL)
|
m_HandlersStack.push_back(new wxHtmlTagHandlersHash(m_HandlersHash));
|
||||||
{
|
|
||||||
m_HandlersStack = new wxList;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_HandlersStack->Insert((wxObject*)new wxHashTable(m_HandlersHash));
|
|
||||||
|
|
||||||
while (tokenizer.HasMoreTokens())
|
while (tokenizer.HasMoreTokens())
|
||||||
{
|
{
|
||||||
key = tokenizer.GetNextToken();
|
key = tokenizer.GetNextToken();
|
||||||
m_HandlersHash.Delete(key);
|
m_HandlersHash[key] = handler;
|
||||||
m_HandlersHash.Put(key, handler);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxHtmlParser::PopTagHandler()
|
void wxHtmlParser::PopTagHandler()
|
||||||
{
|
{
|
||||||
wxList::compatibility_iterator first;
|
wxCHECK_RET( !m_HandlersStack.empty(),
|
||||||
|
"attempt to remove HTML tag handler from empty stack" );
|
||||||
|
|
||||||
if ( !m_HandlersStack ||
|
wxHtmlTagHandlersHash *prev = m_HandlersStack.back();
|
||||||
#if wxUSE_STL
|
m_HandlersStack.pop_back();
|
||||||
!(first = m_HandlersStack->GetFirst())
|
m_HandlersHash = *prev;
|
||||||
#else // !wxUSE_STL
|
delete prev;
|
||||||
((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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxHtmlParser::SetSourceAndSaveState(const wxString& src)
|
void wxHtmlParser::SetSourceAndSaveState(const wxString& src)
|
||||||
|
Reference in New Issue
Block a user