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