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_sxs_h_
00029 #define _terimber_sxs_h_
00030
00031 #include "xml/defxml.h"
00032 #include "xml/xmlaccss.h"
00033 #include "xmltypes.h"
00034
00035 #include "alg/algorith.h"
00036 #include "base/map.h"
00037
00038 BEGIN_TERIMBER_NAMESPACE
00039 #pragma pack(4)
00040
00042 void xml_exception_throw(const char* first, ...);
00044 const size_t big_xml_size = 1024*1024;
00045
00048 enum attributeType
00049 {
00050 attributeType_MIN,
00051 ATTR_TYPE_CDATA,
00052 ATTR_TYPE_ID,
00053 ATTR_TYPE_IDREF,
00054 ATTR_TYPE_IDREFS,
00055 ATTR_TYPE_ENTITY,
00056 ATTR_TYPE_ENTITIES,
00057 ATTR_TYPE_NOTATION,
00058 ATTR_TYPE_NMTOKEN,
00059 ATTR_TYPE_NMTOKENS,
00060 ATTR_TYPE_ENUMERATION,
00061 attributeType_MAX
00062 };
00063
00066 enum attributeRule
00067 {
00068 attributeRule_MIN,
00069 ATTR_RULE_DEFAULT,
00070 ATTR_RULE_REQUIRED,
00071 ATTR_RULE_IMPLIED,
00072 ATTR_RULE_FIXED,
00073 attributeRule_MAX
00074 };
00075
00079 enum contentSpec
00080 {
00081 contentSpec_MIN,
00082 CONTENT_EMPTY,
00083 CONTENT_ANY,
00084
00085 CONTENT_MIXED,
00086
00087
00088
00089
00090 CONTENT_CHILDREN,
00091 contentSpec_MAX
00092 };
00093
00096 enum dfaRule
00097 {
00098 dfaRule_MIN,
00099 DFA_LEAF,
00100 DFA_QUESTION,
00101 DFA_ASTERISK,
00102 DFA_PLUS,
00103 DFA_CHOICE,
00104 DFA_SEQUENCE,
00105 DFA_ANY,
00106 dfaRule_MAX
00107 };
00108
00111 class nodeDecl
00112 {
00114 nodeDecl& operator=(const nodeDecl& x);
00115 public:
00117 nodeDecl( xmlNodeType type
00118 );
00120 nodeDecl(const nodeDecl& x);
00122 ~nodeDecl();
00123
00125 inline
00126 xmlNodeType
00127 get_type() const;
00128
00129 protected:
00130 xmlNodeType _type;
00131 };
00132
00135 class namedNode
00136 {
00138 namedNode& operator=(const namedNode& x);
00139 public:
00141 namedNode( const char* name,
00142 byte_allocator* allocator
00143 );
00145 namedNode(const namedNode& x);
00147 void
00148 clear();
00149
00150 public:
00151 string_t _name;
00152 };
00153
00156 class namedNodeDecl : public nodeDecl,
00157 public namedNode
00158 {
00160 namedNodeDecl& operator=(const namedNodeDecl& x);
00161 public:
00163 namedNodeDecl( xmlNodeType type,
00164 const char* name,
00165 byte_allocator* allocator_
00166 );
00168 namedNodeDecl(const namedNodeDecl& x);
00170 void
00171 clear();
00172 };
00173
00176 class enumNodeDecl
00177 {
00179 enumNodeDecl& operator=(const enumNodeDecl& x);
00180 public:
00182 enumNodeDecl( byte_allocator* allocator_
00183 );
00185 enumNodeDecl(const enumNodeDecl& x);
00186
00187 public:
00188
00189 size_t _id;
00190 string_t _value;
00191 };
00192
00195 class attributeDecl : public namedNodeDecl
00196 {
00198 attributeDecl& operator=(const attributeDecl& x);
00199 public:
00201 attributeDecl( const char* name,
00202 byte_allocator* allocator_
00203 );
00205 attributeDecl(const attributeDecl& x);
00207 const char*
00208 persist_attribute(const terimber_xml_value& value,
00209 byte_allocator* allocator_
00210 ) const;
00211
00212 public:
00213 attributeType _atype;
00214 vt_types _ctype;
00215 _list< enumNodeDecl > _enum;
00216 string_t _defval;
00217 attributeRule _rule;
00218 };
00219
00222 class notationDecl : public namedNodeDecl
00223 {
00225 notationDecl& operator=(const notationDecl& x);
00226 public:
00228 notationDecl( const char* name,
00229 byte_allocator* allocator_
00230 );
00232 notationDecl(const notationDecl& x);
00233 public:
00234 string_t _systemId;
00235 string_t _publicId;
00236 };
00237
00240 class entityDecl : public namedNodeDecl
00241 {
00243 entityDecl& operator=(const entityDecl& x);
00244 public:
00246 entityDecl( const char* name,
00247 byte_allocator* allocator_
00248 );
00250 entityDecl(const entityDecl& x);
00251
00252 string_t _systemId;
00253 string_t _publicId;
00254 string_t _notation;
00255 string_t _value;
00256
00257 bool _is_in_subset;
00258 bool _is_parameter;
00259 bool _is_encoded_char;
00260 bool _is_unparsed;
00261 };
00262
00263
00264 class dfa_token;
00267 typedef _map< size_t, attributeDecl, byte_allocator, less< size_t >, true > attribute_decl_map_t;
00268
00271 class elementDecl : public namedNodeDecl
00272 {
00274 elementDecl& operator=(const elementDecl& x);
00275 public:
00277 elementDecl( const char* name,
00278 byte_allocator* allocator_
00279 );
00281 elementDecl(const elementDecl& x);
00282
00283 public:
00284 contentSpec _content;
00285 dfa_token* _token;
00286 attribute_decl_map_t _attributes;
00287 };
00288
00291 class attributeRefDecl : public namedNode
00292 {
00294 attributeRefDecl& operator=(const attributeRefDecl& x);
00295 public:
00297 attributeRefDecl(const char* name,
00298 byte_allocator* allocator_
00299 );
00301 attributeRefDecl(const attributeRefDecl& x);
00302
00303 public:
00304 bool _declared;
00305 bool _refered;
00306 };
00307
00310 class dfa_token
00311 {
00312 public:
00314 dfa_token();
00316 ~dfa_token();
00318 dfa_token( byte_allocator& allocator_,
00319 const dfa_token& x
00320 );
00322 dfa_token( dfaRule rule,
00323 const elementDecl* decl,
00324 dfa_token* first,
00325 dfa_token* last
00326 );
00327
00329 void
00330 assign( byte_allocator& allocator_,
00331 const dfa_token& x
00332 );
00333
00335 bool
00336 find_any_resursively() const;
00337
00338 dfaRule _rule;
00339 const elementDecl* _decl;
00340 dfa_token* _first;
00341 dfa_token* _last;
00342 };
00343
00346 typedef _map< size_t, namedNodeDecl, byte_allocator, less< size_t >, true > namednode_decl_map_t;
00349 typedef _map< size_t, elementDecl, byte_allocator, less< size_t >, true > element_decl_map_t;
00352 typedef _map< size_t, notationDecl, byte_allocator, less< size_t >, true > notation_decl_map_t;
00355 typedef _map< size_t, entityDecl, byte_allocator, less< size_t >, true > entity_decl_map_t;
00358 typedef _map< size_t, attributeRefDecl, byte_allocator, less< size_t >, true > attribute_ref_decl_map_t;
00359
00362 class xml_grammar
00363 {
00366 xml_grammar(const xml_grammar& x);
00368 xml_grammar& operator=(const xml_grammar& x);
00369
00370 public:
00372 xml_grammar( mem_pool_t& small_manager,
00373 mem_pool_t& big_manager,
00374 size_t xml_size
00375 );
00377 ~xml_grammar();
00379 xml_grammar&
00380 copy( const xml_grammar& x
00381 );
00383 elementDecl&
00384 add_element_decl(const char* name,
00385 bool on_fly,
00386 bool fromDecl,
00387 bool modelAny
00388 );
00390 elementDecl*
00391 find_element_decl(const char* name
00392 );
00394 const elementDecl*
00395 find_element_decl(const char* name
00396 ) const;
00398 notationDecl&
00399 add_notation_decl(const char* name
00400 );
00402 const notationDecl*
00403 find_notation_decl(const char* name
00404 ) const;
00406 entityDecl&
00407 add_entity_decl(const char* name,
00408 bool& wasAdded
00409 );
00411 entityDecl*
00412 find_entity_decl(const char* name
00413 );
00415 const entityDecl*
00416 find_entity_decl(const char* name
00417 ) const;
00419 attributeDecl&
00420 add_attribute_decl(const elementDecl& decl,
00421 const char* name,
00422 bool mustPresent,
00423 bool& wasAdded
00424 );
00426 const attributeDecl*
00427 find_attribute_decl(const elementDecl& decl,
00428 const char* name
00429 ) const;
00431 attributeRefDecl&
00432 add_reference_decl(const char* name,
00433 bool fromID
00434 );
00436 attributeRefDecl*
00437 find_reference_decl(const char* name
00438 );
00440 void
00441 resolve_references();
00443 namedNodeDecl&
00444 add_pi_decl( const char* name
00445 );
00447 const namedNodeDecl*
00448 find_pi_decl( const char* name
00449 ) const;
00451 inline
00452 byte_allocator&
00453 get_data_allocator();
00455 inline
00456 byte_allocator&
00457 get_tmp_allocator();
00459 inline
00460 const namedNodeDecl*
00461 get_document_decl() const;
00463 inline
00464 const namedNodeDecl*
00465 get_doctype_decl() const;
00467 inline
00468 const namedNodeDecl*
00469 get_comment_decl() const;
00471 inline
00472 const namedNodeDecl*
00473 get_cdata_decl() const;
00475 inline
00476 void
00477 clear();
00479 inline
00480 const element_decl_map_t&
00481 get_elementMap() const;
00483 inline
00484 const namednode_decl_map_t&
00485 get_piMap() const;
00487 inline
00488 const entity_decl_map_t&
00489 get_entityMap() const;
00491 inline
00492 const notation_decl_map_t&
00493 get_notationMap() const;
00494 private:
00496 xml_forceinline
00497 void
00498 check_readonly();
00499
00500 protected:
00501 mem_pool_t& _small_manager;
00502 mem_pool_t& _big_manager;
00503 size_t _xml_size;
00504 byte_allocator& _data_allocator;
00505 byte_allocator& _tmp_allocator;
00506 element_decl_map_t _elementMap;
00507 notation_decl_map_t _notationMap;
00508 entity_decl_map_t _entityMap;
00509 attribute_ref_decl_map_t _attributeRefMap;
00510 namednode_decl_map_t _piMap;
00511
00513 namedNodeDecl _document_decl;
00514 namedNodeDecl _doctype_decl;
00515 namedNodeDecl _text_decl;
00516 namedNodeDecl _comment_decl;
00517 namedNodeDecl _cdata_decl;
00518 bool _read_only;
00519
00520 public:
00521 string_t _doc_name;
00522 string_t _public_id;
00523 string_t _system_id;
00524 };
00525
00526 #pragma pack()
00527 END_TERIMBER_NAMESPACE
00528
00529 #endif // _terimber_sxs_h_