diff options
author | Mike Buland <eichlan@xagasoft.com> | 2007-05-11 07:51:40 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2007-05-11 07:51:40 +0000 |
commit | 033c41ed57348abb3a418166b1fb39bfad3312de (patch) | |
tree | 72edbb0b7ff35ef35e4d533bca384b4f7c986942 /src/xmlreader.h | |
parent | ad92dc50b7cdf7cfe086f21d19442d03a90fd05d (diff) | |
download | libbu++-033c41ed57348abb3a418166b1fb39bfad3312de.tar.gz libbu++-033c41ed57348abb3a418166b1fb39bfad3312de.tar.bz2 libbu++-033c41ed57348abb3a418166b1fb39bfad3312de.tar.xz libbu++-033c41ed57348abb3a418166b1fb39bfad3312de.zip |
Added a list template class, seems to work pretty well for now, I may have
forgotten proper cleanup in the deconstructor, but besides that you can do
almost everything you need. I'll make a slist/stack next, probably with the
same basic code, just a different structure (not doubley-linked).
The xml system from old-libbu++ is almost completely converted, I was going to
re-write it, but this seemed easier at first, it may not have been, we'll see.
It almost parses everything again, and almost outputs again, and it does use
streams now.
The FString is partway to doing minimum chunk allocations, so that adding
single-characters will be really fast up to the minimum chunk size. I also
figured out how to add this optimization without any extra variables taking
up space, and it's optional in the template, which is cool. You can specify
the size of the blocks (default 256 bytes), if it's 0 then they'll be like the
old FString, 1 chunk per operation.
The next FString update should be allowing efficient removal from the begining
of the string by faking it, and simply moving a secondary base pointer ahead,
and then optimizing appends after that fact to simply move the existing data
around if you shouldn't have to re-allocate (alla FlexBuf). The final fun
addition that I'm planning is a simple switch in the template (boolean) that
will switch an FString into a thread-safe mode without changing the interface
or anything that you can do with them at all. It may increasing memory usage,
but they should still be better than std::strings, and totally thread-safe.
The best part of that is that if it's done with a boolean template parameter and
if statements that only test that parameter controlling flow, the code that you
don't want (threadsafe/non-threadsafe) won't be included at all
post-optimization.
Diffstat (limited to 'src/xmlreader.h')
-rw-r--r-- | src/xmlreader.h | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/src/xmlreader.h b/src/xmlreader.h index c8f7202..7c85ddb 100644 --- a/src/xmlreader.h +++ b/src/xmlreader.h | |||
@@ -2,10 +2,10 @@ | |||
2 | #define XMLREADER | 2 | #define XMLREADER |
3 | 3 | ||
4 | #include <stdio.h> | 4 | #include <stdio.h> |
5 | #include "xmldocument.h" | 5 | #include "bu/xmldocument.h" |
6 | #include "flexbuf.h" | 6 | #include "bu/hash.h" |
7 | #include "hashtable.h" | 7 | #include "bu/fstring.h" |
8 | #include "staticstring.h" | 8 | #include "bu/stream.h" |
9 | 9 | ||
10 | /** | 10 | /** |
11 | * Takes care of reading in xml formatted data from a file. This could/should | 11 | * Takes care of reading in xml formatted data from a file. This could/should |
@@ -32,7 +32,7 @@ public: | |||
32 | * in content, a-la html. | 32 | * in content, a-la html. |
33 | *@param bStrip Strip out leading and trailing whitespace? | 33 | *@param bStrip Strip out leading and trailing whitespace? |
34 | */ | 34 | */ |
35 | XmlReader( bool bStrip=false ); | 35 | XmlReader( Bu::Stream &sIn, bool bStrip=false ); |
36 | 36 | ||
37 | /** | 37 | /** |
38 | * Destroy this XmlReader. | 38 | * Destroy this XmlReader. |
@@ -54,12 +54,12 @@ private: | |||
54 | *@returns A single character at the requested position, or 0 for end of | 54 | *@returns A single character at the requested position, or 0 for end of |
55 | * stream. | 55 | * stream. |
56 | */ | 56 | */ |
57 | virtual char getChar( int nIndex = 0 ) = 0; | 57 | virtual char getChar( int nIndex = 0 ); |
58 | 58 | ||
59 | /** | 59 | /** |
60 | * Called to increment the current stream position by a single character. | 60 | * Called to increment the current stream position by a single character. |
61 | */ | 61 | */ |
62 | virtual void usedChar( int nAmnt = 1) = 0; | 62 | virtual void usedChar( int nAmnt = 1 ); |
63 | 63 | ||
64 | /** | 64 | /** |
65 | * Automoton function: is whitespace. | 65 | * Automoton function: is whitespace. |
@@ -108,9 +108,9 @@ private: | |||
108 | *@param name The name of the entity | 108 | *@param name The name of the entity |
109 | *@param value The value of the entity | 109 | *@param value The value of the entity |
110 | */ | 110 | */ |
111 | void addEntity( const char *name, const char *value ); | 111 | void addEntity( const Bu::FString &name, const Bu::FString &value ); |
112 | 112 | ||
113 | StaticString *getEscape(); | 113 | Bu::FString getEscape(); |
114 | 114 | ||
115 | /** | 115 | /** |
116 | * Automoton function: paramlist. Processes a list of node params. | 116 | * Automoton function: paramlist. Processes a list of node params. |
@@ -130,12 +130,15 @@ private: | |||
130 | */ | 130 | */ |
131 | bool content(); | 131 | bool content(); |
132 | 132 | ||
133 | FlexBuf fbContent; /**< buffer for the current node's content. */ | 133 | Bu::FString sContent; /**< buffer for the current node's content. */ |
134 | FlexBuf fbParamName; /**< buffer for the current param's name. */ | 134 | Bu::FString sParamName; /**< buffer for the current param's name. */ |
135 | FlexBuf fbParamValue; /**< buffer for the current param's value. */ | 135 | Bu::FString sParamValue; /**< buffer for the current param's value. */ |
136 | bool bStrip; /**< Are we stripping whitespace? */ | 136 | Bu::Stream &sIn; |
137 | bool bStrip; /**< Are we stripping whitespace? */ | ||
137 | 138 | ||
138 | HashTable htEntity; /**< Entity type definitions. */ | 139 | Bu::Hash<Bu::FString,Bu::FString> htEntity; /**< Entity type definitions. */ |
140 | |||
141 | Bu::FString sBuf; | ||
139 | }; | 142 | }; |
140 | 143 | ||
141 | #endif | 144 | #endif |