00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef _terimber_storexml_h_
00029 #define _terimber_storexml_h_
00030
00031 #include "xml/declxml.h"
00032 #include "base/vector.h"
00033 #include "base/common.h"
00034
00035 BEGIN_TERIMBER_NAMESPACE
00036 #pragma pack(4)
00037
00040 typedef _list< ub1_t* > store_list_t;
00041
00045 class byte_source
00046 {
00047 public:
00049 byte_source( mem_pool_t& small_pool,
00050 mem_pool_t& big_pool,
00051 size_t xml_size,
00052 const char* url,
00053 bool subset
00054 );
00055
00057 virtual
00058 ~byte_source();
00060 xml_forceinline
00061 ub1_t
00062 pick();
00064 xml_forceinline
00065 ub1_t
00066 pop();
00068 xml_forceinline
00069 ub1_t
00070 pip();
00073 xml_forceinline
00074 void
00075 skip_white_space(bool mustPresent = false,
00076 const char* message = 0
00077 );
00079 void
00080 throw_exception(const char* msg_text
00081 );
00084 void
00085 skip_string( const char* x,
00086 const char* message
00087 );
00088
00091 void
00092 skip_sign( ub1_t symbol,
00093 bool skip_before,
00094 bool skip_after,
00095 const char* message
00096 );
00103 ub1_t
00104 skip_quote( ub1_t symbol = 0
00105 );
00107 inline
00108 size_t
00109 current_pos() const;
00111 void
00112 push( const ub1_t* x,
00113 size_t len
00114 );
00116 inline
00117 void
00118 push( ub1_t x
00119 );
00120
00122 size_t
00123 pull( ub1_t* x,
00124 size_t len
00125 );
00127 inline
00128 encodingSchema
00129 get_encoding() const;
00131 inline
00132 void
00133 set_encoding(encodingSchema schema);
00135 inline
00136 const char*
00137 get_location() const;
00138
00139 protected:
00142 virtual
00143 bool
00144 data_request( ub1_t* buf,
00145 size_t& len
00146 ) = 0;
00147
00150 encodingSchema
00151 parseXMLDecl();
00154 encodingSchema
00155 parseTextDecl();
00156
00157 private:
00159 bool
00160 convert_chars(size_t count);
00162 bool
00163 taste_buffer();
00165 bool
00166 auto_convert();
00168 ub1_t
00169 go_shopping();
00171 bool
00172 parseXMLDeclInfo();
00174 void
00175 parseVersion();
00177 encodingSchema
00178 parseEncoding();
00180 size_t
00181 parseStandalone();
00183 encodingSchema
00184 checkEncodingSchema(const char* schema
00185 );
00187 void
00188 scanQuotedValue(ub1_t* value,
00189 size_t len,
00190 bool (*fn)(ub1_t),
00191 const char* message
00192 );
00193
00194 public:
00196 size_t
00197 get_standalone() const;
00199 bool get_subset() const;
00201 size_t
00202 get_version() const;
00204 inline
00205 size_t
00206 get_xml_size() const;
00207
00208 protected:
00210 inline
00211 size_t
00212 get_buffer_pos() const;
00214 void
00215 reset_buffer();
00216 protected:
00217 byte_allocator* _depot_allocator;
00218 byte_allocator* _convert_allocator;
00219 byte_allocator* _store_allocator;
00220 byte_allocator* _list_allocator;
00221 mem_pool_t& _small_pool;
00222 mem_pool_t& _big_pool;
00223 const size_t _xml_size;
00224 string_t _url;
00225 private:
00226 bool _subset;
00227 ub1_t* _buffer;
00228 ub1_t* _convert_buffer;
00229 size_t _buffer_pos;
00230 ub1_t _symbol;
00231 store_list_t _active_store;
00232 store_list_t _used_store;
00233 size_t _line_counter;
00234 size_t _char_counter;
00235 size_t _pos_counter;
00236 encodingSchema _encodingSchema;
00237 size_t _version;
00238 size_t _standalone;
00239 bool _end;
00240 };
00241
00246 class byte_consumer
00247 {
00248 public:
00250 byte_consumer( mem_pool_t& small_pool,
00251 mem_pool_t& big_pool,
00252 size_t xml_size
00253 );
00255 virtual
00256 ~byte_consumer();
00258 void
00259 push( const ub1_t* x,
00260 size_t len
00261 );
00263 inline
00264 void
00265 push( ub1_t x
00266 );
00268 inline
00269 void
00270 push( const char* x
00271 );
00273 inline
00274 size_t
00275 get_xml_size() const;
00277 inline
00278 size_t
00279 get_buffer_pos() const;
00281 void
00282 flush();
00283
00284 protected:
00287 virtual
00288 bool
00289 data_persist( const ub1_t* buf,
00290 size_t len
00291 ) = 0;
00292
00293 private:
00294 byte_allocator* _depot_allocator;
00295 mem_pool_t& _small_pool;
00296 mem_pool_t& _big_pool;
00297 const size_t _xml_size;
00298 ub1_t* _buffer;
00299 size_t _buffer_pos;
00300 };
00301
00302
00303 #pragma pack()
00304 END_TERIMBER_NAMESPACE
00305
00306 #endif // _terimber_storexml_h_