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_sxml_h_
00029 #define _terimber_sxml_h_
00030
00031 #include "xml/sxs.h"
00032 #include "base/stack.h"
00033
00034 BEGIN_TERIMBER_NAMESPACE
00035 #pragma pack(4)
00036
00041 class xml_node
00042 {
00043 protected:
00045 xml_node(const xml_node& x);
00046 xml_node& operator=(const xml_node& x);
00047 public:
00049 xml_node( const namedNodeDecl* decl
00050 );
00052 ~xml_node();
00054 xml_forceinline
00055 const attributeDecl*
00056 cast_to_attribute() const;
00058 void
00059 clear();
00060 public:
00061 const namedNodeDecl* _decl;
00062 };
00063
00067 class xml_tree_node : public xml_node
00068 {
00069 protected:
00070
00073 xml_tree_node(const xml_tree_node& x);
00074 xml_tree_node& operator=(const xml_tree_node& x);
00075 public:
00077 xml_tree_node( const namedNodeDecl* decl,
00078 xml_tree_node* parent
00079 );
00081 ~xml_tree_node();
00083 void
00084 clear();
00085 public:
00086 xml_tree_node* _parent;
00087 xml_tree_node* _left;
00088 xml_tree_node* _right;
00089 };
00090
00094 class xml_value_node : public xml_tree_node
00095 {
00096 protected:
00099 xml_value_node(const xml_value_node& x);
00100 xml_value_node& operator=(const xml_value_node& x);
00101 public:
00103 xml_value_node( const namedNodeDecl* decl,
00104 xml_tree_node* parent
00105 );
00107 ~xml_value_node();
00109 const char*
00110 persist( byte_allocator& allocator
00111 ) const;
00113 xml_forceinline
00114 static
00115 const xml_value_node*
00116 cast_to_node_value(const xml_tree_node* x
00117 );
00119 xml_forceinline
00120 static
00121 xml_value_node*
00122 cast_to_node_value(xml_tree_node* x
00123 );
00125 void
00126 clear();
00127
00128
00129 public:
00130 terimber_xml_value _value;
00131 };
00132
00133
00134
00135 class xml_document;
00136 class xml_element;
00137
00140 class xml_container : public xml_tree_node
00141 {
00142 public:
00144 xml_container( const namedNodeDecl* decl,
00145 xml_tree_node* parent
00146 );
00148 void
00149 clear();
00150 public:
00152 xml_forceinline
00153 xml_tree_node*
00154 add_node( xml_tree_node* node
00155 );
00157 xml_forceinline
00158 xml_tree_node*
00159 append_node( xml_tree_node* after,
00160 xml_tree_node* node
00161 );
00163 xml_forceinline
00164 xml_tree_node*
00165 insert_node( xml_tree_node* before,
00166 xml_tree_node* node
00167 );
00169 xml_forceinline
00170 xml_tree_node*
00171 remove_node( xml_tree_node* node
00172 );
00174 xml_forceinline
00175 bool
00176 has_children() const;
00178 xml_forceinline
00179 bool
00180 is_container() const;
00182 xml_forceinline
00183 static
00184 const xml_container*
00185 cast_to_container(const xml_tree_node* x
00186 );
00188 xml_forceinline
00189 static
00190 xml_container*
00191 cast_to_container(xml_tree_node* x
00192 );
00193 public:
00194 xml_tree_node* _first_child;
00195 xml_tree_node* _last_child;
00196 };
00197
00201 typedef _map< const attributeDecl*, const xml_value_node* > attr_states_map_t;
00202
00205 class xml_element : public xml_container
00206 {
00209 xml_element(const xml_element& x);
00210 xml_element& operator=(const xml_element& x);
00211 public:
00213 xml_element( const elementDecl* decl,
00214 xml_tree_node* parent
00215 );
00217 xml_forceinline
00218 bool
00219 has_attributes() const;
00221 xml_forceinline
00222 const elementDecl*
00223 cast_decl() const;
00225 xml_forceinline
00226 void
00227 clear();
00229 xml_forceinline
00230 static
00231 const xml_element*
00232 cast_to_element(const xml_tree_node* x
00233 );
00235 xml_forceinline
00236 static
00237 xml_element*
00238 cast_to_element(xml_tree_node* x
00239 );
00240
00242 xml_forceinline
00243 xml_tree_node*
00244 add_attribute( xml_tree_node* node
00245 );
00246
00248 xml_forceinline
00249 xml_tree_node*
00250 append_attribute(xml_tree_node* after,
00251 xml_tree_node* node
00252 );
00254 xml_forceinline
00255 xml_tree_node*
00256 insert_attribute(xml_tree_node* before,
00257 xml_tree_node* node
00258 );
00260 xml_forceinline
00261 xml_tree_node*
00262 remove_attribute(xml_tree_node* node
00263 );
00264
00265 public:
00266 xml_tree_node* _first_attr;
00267 xml_tree_node* _last_attr;
00268 };
00269
00270
00271 class content_interface;
00275 typedef _map< const elementDecl*, content_interface*, byte_allocator, less< const elementDecl* >, false > model_map_t;
00278 typedef node_allocator< base_stack< xml_container* >::_node > xml_container_stack_allocator_t;
00281 typedef _stack< xml_container*, xml_container_stack_allocator_t > xml_container_stack_t;
00282
00285 class xml_document : public xml_container,
00286 public xml_grammar
00287 {
00288 public:
00290 xml_document( mem_pool_t& small_manager,
00291 mem_pool_t& big_manager,
00292 size_t xml_size,
00293 const xml_grammar* grammar
00294 );
00296 ~xml_document();
00298 content_interface*
00299 find_model( const elementDecl* decl
00300 );
00302 void
00303 add_model( const elementDecl* decl,
00304 content_interface* model
00305 );
00307 xml_forceinline
00308 byte_allocator&
00309 get_data_allocator();
00311 xml_forceinline
00312 byte_allocator&
00313 get_model_allocator();
00315 xml_forceinline
00316 byte_allocator&
00317 get_tmp_allocator();
00319 xml_forceinline
00320 mem_pool_t&
00321 get_small_manager();
00323 xml_forceinline
00324 mem_pool_t&
00325 get_big_manager();
00327 xml_forceinline
00328 bool
00329 is_on_fly() const;
00331 xml_forceinline
00332 xml_element&
00333 get_root_element();
00335 xml_forceinline
00336 const xml_element&
00337 get_root_element() const;
00339 void
00340 add_escaped_symbols();
00342 xml_forceinline
00343 const string_t&
00344 get_doc_name() const;
00346 bool
00347 set_doc_name( const char* name
00348 );
00350 bool
00351 check_root();
00353 void clear();
00355 void
00356 clear_root();
00359 void
00360 container_reset();
00362 void
00363 container_push( xml_element* el
00364 );
00366 xml_element*
00367 container_pop();
00369 bool
00370 container_peak();
00372 void container_start_doctype();
00374 void container_stop_doctype();
00376 void
00377 validate( xml_element& el
00378 );
00380 xml_forceinline
00381 void
00382 add_entity_desc(const entityDecl& decl
00383 );
00385 xml_forceinline
00386 void
00387 add_notation_desc(const notationDecl& decl
00388 );
00390 xml_forceinline
00391 void
00392 add_element_desc(const elementDecl& decl
00393 );
00395 xml_forceinline
00396 xml_value_node*
00397 add_comment( const char* value,
00398 xml_tree_node* sibling = 0,
00399 bool after = true
00400 );
00402 xml_forceinline
00403 xml_value_node*
00404 add_cdata( const char* value,
00405 xml_tree_node* sibling = 0,
00406 bool after = true
00407 );
00409 xml_forceinline
00410 xml_value_node*
00411 add_pi( const char* name,
00412 const char* value,
00413 xml_tree_node* sibling = 0,
00414 bool after = true
00415 );
00417 xml_forceinline
00418 xml_value_node*
00419 add_text( const char* value,
00420 xml_tree_node* sibling = 0,
00421 bool after = true
00422 );
00424 xml_element*
00425 add_element( const char* name,
00426 xml_tree_node* sibling = 0,
00427 bool after = true
00428 );
00430 xml_value_node*
00431 add_attribute( xml_element& el,
00432 const char* name,
00433 const char* value,
00434 xml_tree_node* sibling = 0,
00435 bool after = true
00436 );
00438 void
00439 update_attribute(xml_element* el,
00440 xml_value_node* att,
00441 const char* value
00442 );
00444 void
00445 add_def_attributes(xml_element& el,
00446 attr_states_map_t& attrStates
00447 );
00451 terimber_xml_value
00452 find_attribute_value(const xml_element& el,
00453 const char* name
00454 ) const;
00456 xml_value_node*
00457 find_attribute( const xml_element& el,
00458 const char* name
00459 );
00460
00461 private:
00463 void
00464 validate_attributes(xml_element& el
00465 );
00467 void
00468 validate_children(xml_element& el
00469 );
00471 void
00472 assign_attribute_value(xml_element& el,
00473 const attributeDecl& attr_decl,
00474 xml_value_node* att,
00475 const char* value
00476 );
00477 public:
00478 size_t _standalone;
00479
00480 private:
00481 xml_container_stack_t _container_stack;
00482 byte_allocator _model_allocator;
00483 xml_container_stack_allocator_t _stack_allocator;
00484 bool _on_fly;
00485 model_map_t _model_map;
00486 xml_element _root;
00487 xml_container _doc_type;
00488 };
00489
00490 #pragma pack()
00491 END_TERIMBER_NAMESPACE
00492
00493 #endif // _terimber_sxml_h_