]> git.saurik.com Git - wxWidgets.git/blob - tests/benchmarks/htmlparser/htmltag.h
Add wxImage::Scale() benchmarks.
[wxWidgets.git] / tests / benchmarks / htmlparser / htmltag.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: htmltag.h
3 // Purpose: wx28HtmlTag class (represents single tag)
4 // Author: Vaclav Slavik
5 // RCS-ID: $Id$
6 // Copyright: (c) 1999 Vaclav Slavik
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9
10 #ifndef _WX_HTMLTAG_H_
11 #define _WX_HTMLTAG_H_
12
13 #include "wx/defs.h"
14
15 #include "wx/object.h"
16 #include "wx/arrstr.h"
17
18 class wxColour;
19 class wx28HtmlEntitiesParser;
20
21 //-----------------------------------------------------------------------------
22 // wx28HtmlTagsCache
23 // - internal wxHTML class, do not use!
24 //-----------------------------------------------------------------------------
25
26 struct wx28HtmlCacheItem;
27
28 class wx28HtmlTagsCache : public wxObject
29 {
30 DECLARE_DYNAMIC_CLASS(wx28HtmlTagsCache)
31
32 private:
33 wx28HtmlCacheItem *m_Cache;
34 int m_CacheSize;
35 int m_CachePos;
36
37 public:
38 wx28HtmlTagsCache() : wxObject() {m_CacheSize = 0; m_Cache = NULL;}
39 wx28HtmlTagsCache(const wxString& source);
40 virtual ~wx28HtmlTagsCache() {free(m_Cache);}
41
42 // Finds parameters for tag starting at at and fills the variables
43 void QueryTag(int at, int* end1, int* end2);
44
45 DECLARE_NO_COPY_CLASS(wx28HtmlTagsCache)
46 };
47
48
49 //--------------------------------------------------------------------------------
50 // wx28HtmlTag
51 // This represents single tag. It is used as internal structure
52 // by wx28HtmlParser.
53 //--------------------------------------------------------------------------------
54
55 class wx28HtmlTag : public wxObject
56 {
57 DECLARE_CLASS(wx28HtmlTag)
58
59 protected:
60 // constructs wx28HtmlTag object based on HTML tag.
61 // The tag begins (with '<' character) at position pos in source
62 // end_pos is position where parsing ends (usually end of document)
63 wx28HtmlTag(wx28HtmlTag *parent,
64 const wxString& source, int pos, int end_pos,
65 wx28HtmlTagsCache *cache,
66 wx28HtmlEntitiesParser *entParser);
67 friend class wx28HtmlParser;
68 public:
69 virtual ~wx28HtmlTag();
70
71 wx28HtmlTag *GetParent() const {return m_Parent;}
72 wx28HtmlTag *GetFirstSibling() const;
73 wx28HtmlTag *GetLastSibling() const;
74 wx28HtmlTag *GetChildren() const { return m_FirstChild; }
75 wx28HtmlTag *GetPreviousSibling() const { return m_Prev; }
76 wx28HtmlTag *GetNextSibling() const {return m_Next; }
77 // Return next tag, as if tree had been flattened
78 wx28HtmlTag *GetNextTag() const;
79
80 // Returns tag's name in uppercase.
81 inline wxString GetName() const {return m_Name;}
82
83 // Returns true if the tag has given parameter. Parameter
84 // should always be in uppercase.
85 // Example : <IMG SRC="test.jpg"> HasParam("SRC") returns true
86 bool HasParam(const wxString& par) const;
87
88 // Returns value of the param. Value is in uppercase unless it is
89 // enclosed with "
90 // Example : <P align=right> GetParam("ALIGN") returns (RIGHT)
91 // <P IMG SRC="WhaT.jpg"> GetParam("SRC") returns (WhaT.jpg)
92 // (or ("WhaT.jpg") if with_commas == true)
93 wxString GetParam(const wxString& par, bool with_commas = false) const;
94
95 // Convenience functions:
96 bool GetParamAsColour(const wxString& par, wxColour *clr) const;
97 bool GetParamAsInt(const wxString& par, int *clr) const;
98
99 // Scans param like scanf() functions family does.
100 // Example : ScanParam("COLOR", "\"#%X\"", &clr);
101 // This is always with with_commas=false
102 // Returns number of scanned values
103 // (like sscanf() does)
104 // NOTE: unlike scanf family, this function only accepts
105 // *one* parameter !
106 int ScanParam(const wxString& par, const wxChar *format, void *param) const;
107
108 // Returns string containing all params.
109 wxString GetAllParams() const;
110
111 // return true if this there is matching ending tag
112 inline bool HasEnding() const {return m_End1 >= 0;}
113
114 // returns beginning position of _internal_ block of text
115 // See explanation (returned value is marked with *):
116 // bla bla bla <MYTAG>* bla bla intenal text</MYTAG> bla bla
117 inline int GetBeginPos() const {return m_Begin;}
118 // returns ending position of _internal_ block of text.
119 // bla bla bla <MYTAG> bla bla intenal text*</MYTAG> bla bla
120 inline int GetEndPos1() const {return m_End1;}
121 // returns end position 2 :
122 // bla bla bla <MYTAG> bla bla internal text</MYTAG>* bla bla
123 inline int GetEndPos2() const {return m_End2;}
124
125 private:
126 wxString m_Name;
127 int m_Begin, m_End1, m_End2;
128 wxArrayString m_ParamNames, m_ParamValues;
129
130 // DOM tree relations:
131 wx28HtmlTag *m_Next;
132 wx28HtmlTag *m_Prev;
133 wx28HtmlTag *m_FirstChild, *m_LastChild;
134 wx28HtmlTag *m_Parent;
135
136 DECLARE_NO_COPY_CLASS(wx28HtmlTag)
137 };
138
139
140
141 #endif // _WX_HTMLTAG_H_
142