Thread portable class


Gate portable class


Timer class


Pool class


Terimber 2.0


About C++


Downloads Products & Services Support Clients Open Source About



Home / Open source / Terimber 2.0

xml_designer_impl Class Reference

implements abstract xml_designer interface More...

#include <xmlimpl.h>

Inheritance diagram for xml_designer_impl:

xml_designer

List of all members.

Public Member Functions

 xml_designer_impl (size_t xml_size)
 constructor
virtual ~xml_designer_impl ()
 destructor
virtual bool load (const char *name, const char *grammar)
 load xml from file if the name is not null and the grammar is not null then parse external xml according to the provided external grammar if the name is not null and the grammar is null then parse external xml according to the internal grammar if specified if the name is null and the grammar is not null then parse external grammar and clear internal document if the name is null and the grammar is not null
virtual bool load (const void *buffer, size_t length, const char *grammar)
 loads xml from memory DTD data comes from file
virtual bool load (const char *name, const void *grammar, size_t grammar_length)
 loads xml from file DTD data comes from memory
virtual bool load (const void *buffer, size_t length, const void *grammar, size_t grammar_length)
 loads xml from memory DTD data comes from memory
virtual const char * error () const
 returns the last error
virtual void select_document () const
 resets navigator to the document
virtual bool select_root () const
 resets navigator to the root element
virtual bool has_children () const
 checks the presence of children
virtual bool select_first_child () const
 navigates to the next level looking for the first child
virtual bool select_last_child () const
 navigates to the next level looking for the last child
virtual bool select_parent () const
 navigates up a level
virtual bool has_attributes () const
 checks the attributes' presence
virtual bool select_first_attribute () const
 navigates to the first attribute
virtual bool select_last_attribute () const
 navigates to the last attribute
virtual bool select_attribute_by_name (const char *name) const
 navigates to the attribute by name
virtual bool select_next_sibling () const
 navigates through the same level go to the next node for attributes and nodes
virtual bool select_prev_sibling () const
 navigates through the same level go to the previous node for attributes and nodes
virtual xmlNodeType get_type () const
 returns type of the current node
virtual const char * get_name () const
 returns name of the current node text, comment, cdata - name == null element, attribute - name == name document, doc_type - document name processing instruction - name == target
virtual const char * get_value () const
 returns value of the current node for attributes this is an attribute value for element this is a text for processing instruction - instruction text for cdata, comment - text NB!!! value is allocated on temporary allocator char pointer will be valid until next function call
virtual const char * get_xpath () const
 returns the xpath (a/b/c format, where a root element c is current element) of the current node NB!!! value is allocated on temporary allocator char pointer will be valid until next function call
virtual bool select_xpath (const char *path) const
 global navigation looking for element specified according to format (a/b/c)
virtual bool save (const char *name, bool add_doc_type) const
 saves xml to file adding DTD is optional
virtual bool save (void *buffer, size_t &length, bool add_doc_type) const
 saves xml to memory adding DTD is optional if buffer is null, the function returns the required memory size through length
virtual bool add_child (xmlNodeType type, const char *name, const char *value, bool dont_move)
 add node as a child to the current node
virtual bool insert_sibling (xmlNodeType type, const char *name, const char *value, bool dont_move)
 inserts node before current node beneath the same parent
virtual bool append_sibling (xmlNodeType type, const char *name, const char *value, bool dont_move)
 appends node after current node beneath the same parent
virtual bool remove_node ()
 removes the current node
virtual bool update_value (const char *value)
 updates the current node attribute value == value processing instruction value = text cdata, text, comment value == text
virtual bool merge (const xml_designer *x, bool recursive)
 adds beneath the current node an external xml fragment starting with the current node
virtual bool validate (bool recursive)
 validates the xml node accorging to the current grammar

Protected Member Functions

xmlNodeType get_cur_type () const
 gets the selected node type
bool is_attribute () const
 checks if the selected node is an attribute
bool is_element () const
 checks if the selected node is an element
bool is_container () const
 checks if the selected node is a container (element or document)

Private Member Functions

bool _import_node (xmlNodeType type, const char *name, const char *value, bool sibling, bool after, bool dont_move)
 inserts new xml node into document
void _validate (xml_element *el, bool recursive)
 validates element
bool _load (byte_source *stream, byte_source *grammar)
 parses xml document from abstract streams for xml and DTD sources

Private Attributes

size_t _xml_size
 xml size - just a tip
mem_pool_t _small_manager
 small memory pool
mem_pool_t _big_manager
 big memory pool
byte_allocator_tmp_allocator
 temporary allocator
xml_document _doc
 xml document
string_t _error
 last error
xml_tree_node_cur_node
 selected node


Detailed Description

implements abstract xml_designer interface

Definition at line 43 of file xmlimpl.h.


Constructor & Destructor Documentation

BEGIN_TERIMBER_NAMESPACE xml_designer_impl::xml_designer_impl ( size_t  xml_size  ) 

constructor

Parameters:
xml_size  xml size - just a tip

Definition at line 73 of file xmlimpl.cpp.

References _cur_node, _doc, _small_manager, _tmp_allocator, and pool< C >::loan_object().

xml_designer_impl::~xml_designer_impl (  )  [virtual]

destructor

Definition at line 81 of file xmlimpl.cpp.

References _small_manager, _tmp_allocator, and pool< C >::return_object().


Member Function Documentation

bool xml_designer_impl::load ( const char *  name,
const char *  grammar 
) [virtual]

load xml from file if the name is not null and the grammar is not null then parse external xml according to the provided external grammar if the name is not null and the grammar is null then parse external xml according to the internal grammar if specified if the name is null and the grammar is not null then parse external grammar and clear internal document if the name is null and the grammar is not null

Parameters:
name  xml file name
grammar  external DTD file

Implements xml_designer.

Definition at line 88 of file xmlimpl.cpp.

References _big_manager, _error, _load(), _small_manager, _xml_size, and stream_input_common::open().

Referenced by xmlconfig::xmlconfig().

bool xml_designer_impl::load ( const void *  buffer,
size_t  length,
const char *  grammar 
) [virtual]

loads xml from memory DTD data comes from file

Parameters:
buffer  memory buffer
length  buffer length
grammar  external DTD file

Implements xml_designer.

Definition at line 125 of file xmlimpl.cpp.

References _big_manager, _error, _load(), _small_manager, _xml_size, and stream_input_common::open().

bool xml_designer_impl::load ( const char *  name,
const void *  grammar,
size_t  grammar_length 
) [virtual]

loads xml from file DTD data comes from memory

Parameters:
name  xml file name
grammar  DTD memory buffer
grammar_length  buffer length

Implements xml_designer.

Definition at line 151 of file xmlimpl.cpp.

References _big_manager, _error, _load(), _small_manager, _xml_size, and stream_input_common::open().

bool xml_designer_impl::load ( const void *  buffer,
size_t  length,
const void *  grammar,
size_t  grammar_length 
) [virtual]

loads xml from memory DTD data comes from memory

Parameters:
buffer  xml memory buffer
length  xml buffer length
grammar  DTD memory buffer
grammar_length  DTD buffer length

Implements xml_designer.

Definition at line 178 of file xmlimpl.cpp.

References _big_manager, _load(), _small_manager, and _xml_size.

const char * xml_designer_impl::error (  )  const [virtual]

returns the last error

Implements xml_designer.

Definition at line 195 of file xmlimpl.cpp.

References _error.

void xml_designer_impl::select_document (  )  const [virtual]

resets navigator to the document

Implements xml_designer.

Definition at line 202 of file xmlimpl.cpp.

References _cur_node, and _doc.

bool xml_designer_impl::select_root (  )  const [virtual]

resets navigator to the root element

Implements xml_designer.

Definition at line 209 of file xmlimpl.cpp.

References _cur_node, xml_node::_decl, _doc, and xml_document::get_root_element().

Referenced by xmlconfig::get(), xmlconfig::getlist(), xmlconfig::set(), xmlconfig::setlist(), and xmlconfig::xmlconfig().

bool xml_designer_impl::has_children (  )  const [virtual]

checks the presence of children

Implements xml_designer.

Definition at line 221 of file xmlimpl.cpp.

References _cur_node, xml_container::cast_to_container(), xml_container::has_children(), and is_container().

Referenced by select_first_child(), and select_last_child().

bool xml_designer_impl::select_first_child (  )  const [virtual]

navigates to the next level looking for the first child

Implements xml_designer.

Definition at line 227 of file xmlimpl.cpp.

References _cur_node, xml_container::_first_child, xml_container::cast_to_container(), and has_children().

Referenced by xmlconfig::getlist(), and xmlconfig::setlist().

bool xml_designer_impl::select_last_child (  )  const [virtual]

navigates to the next level looking for the last child

Implements xml_designer.

Definition at line 237 of file xmlimpl.cpp.

References _cur_node, xml_container::_last_child, xml_container::cast_to_container(), and has_children().

bool xml_designer_impl::select_parent (  )  const [virtual]

navigates up a level

Implements xml_designer.

Definition at line 270 of file xmlimpl.cpp.

References _cur_node, and xml_tree_node::_parent.

Referenced by xmlconfig::getlist(), merge(), and xmlconfig::setlist().

bool xml_designer_impl::has_attributes (  )  const [virtual]

checks the attributes' presence

attribute navigation

Implements xml_designer.

Definition at line 281 of file xmlimpl.cpp.

References _cur_node, xml_element::cast_to_element(), xml_element::has_attributes(), and is_element().

Referenced by select_attribute_by_name(), select_first_attribute(), and select_last_attribute().

bool xml_designer_impl::select_first_attribute (  )  const [virtual]

navigates to the first attribute

Implements xml_designer.

Definition at line 288 of file xmlimpl.cpp.

References _cur_node, xml_element::_first_attr, xml_element::cast_to_element(), and has_attributes().

bool xml_designer_impl::select_last_attribute (  )  const [virtual]

navigates to the last attribute

Implements xml_designer.

Definition at line 298 of file xmlimpl.cpp.

References _cur_node, xml_element::_last_attr, xml_element::cast_to_element(), and has_attributes().

bool xml_designer_impl::select_attribute_by_name ( const char *  name  )  const [virtual]

navigates to the attribute by name

Parameters:
name  attribute name

Implements xml_designer.

Definition at line 308 of file xmlimpl.cpp.

References _cur_node, _doc, xml_tree_node::_right, xml_element::cast_to_element(), xml_grammar::find_attribute_decl(), and has_attributes().

Referenced by xmlconfig::get(), xmlconfig::getlist(), xmlconfig::set(), and xmlconfig::setlist().

bool xml_designer_impl::select_next_sibling (  )  const [virtual]

navigates through the same level go to the next node for attributes and nodes

Implements xml_designer.

Definition at line 248 of file xmlimpl.cpp.

References _cur_node, and xml_tree_node::_right.

Referenced by xmlconfig::getlist(), and xmlconfig::setlist().

bool xml_designer_impl::select_prev_sibling (  )  const [virtual]

navigates through the same level go to the previous node for attributes and nodes

Implements xml_designer.

Definition at line 259 of file xmlimpl.cpp.

References _cur_node, and xml_tree_node::_left.

xmlNodeType xml_designer_impl::get_type (  )  const [virtual]

returns type of the current node

where am I?

Implements xml_designer.

Definition at line 329 of file xmlimpl.cpp.

References get_cur_type().

Referenced by xmlconfig::getlist(), and xmlconfig::setlist().

const char * xml_designer_impl::get_name (  )  const [virtual]

returns name of the current node text, comment, cdata - name == null element, attribute - name == name document, doc_type - document name processing instruction - name == target

Implements xml_designer.

Definition at line 335 of file xmlimpl.cpp.

References _cur_node, xml_node::_decl, _doc, namedNode::_name, ATTRIBUTE_NODE, DOCUMENT_NODE, DOCUMENT_TYPE_NODE, ELEMENT_NODE, get_cur_type(), xml_document::get_doc_name(), and PROCESSING_INSTRUCTION_NODE.

Referenced by xmlconfig::getlist(), xmlconfig::setlist(), and xmlconfig::xmlconfig().

const char * xml_designer_impl::get_value (  )  const [virtual]

returns value of the current node for attributes this is an attribute value for element this is a text for processing instruction - instruction text for cdata, comment - text NB!!! value is allocated on temporary allocator char pointer will be valid until next function call

Implements xml_designer.

Definition at line 352 of file xmlimpl.cpp.

References _cur_node, _tmp_allocator, ATTRIBUTE_NODE, xml_node::cast_to_attribute(), xml_value_node::cast_to_node_value(), CDATA_SECTION_NODE, COMMENT_NODE, get_cur_type(), attributeDecl::persist_attribute(), persist_value(), PROCESSING_INSTRUCTION_NODE, byte_allocator::reset(), TEXT_NODE, and vt_string.

Referenced by xmlconfig::get(), xmlconfig::getlist(), and xmlconfig::setlist().

const char * xml_designer_impl::get_xpath (  )  const [virtual]

returns the xpath (a/b/c format, where a root element c is current element) of the current node NB!!! value is allocated on temporary allocator char pointer will be valid until next function call

Implements xml_designer.

Definition at line 376 of file xmlimpl.cpp.

References _cur_node, xml_node::_decl, _doc, namedNode::_name, xml_tree_node::_parent, _tmp_allocator, byte_allocator::allocate(), base_list< T >::begin(), ch_forward_slash, base_list< T >::end(), is_element(), _list< T, A >::push_front(), and byte_allocator::reset().

bool xml_designer_impl::select_xpath ( const char *  path  )  const [virtual]

bool xml_designer_impl::save ( const char *  name,
bool  add_doc_type 
) const [virtual]

saves xml to file adding DTD is optional

Parameters:
name  file name
add_doc_type  flag save the grammar to the output xml

Implements xml_designer.

Definition at line 503 of file xmlimpl.cpp.

References _big_manager, _doc, _error, _small_manager, _xml_size, stream_output_file::close(), xml_persistor::get_error(), stream_output_file::open(), and xml_persistor::persist().

Referenced by xmlconfig::~xmlconfig().

bool xml_designer_impl::save ( void *  buffer,
size_t &  length,
bool  add_doc_type 
) const [virtual]

saves xml to memory adding DTD is optional if buffer is null, the function returns the required memory size through length

Parameters:
buffer  output buffer
length  buffer length
add_doc_type  flag save the grammar to the output xml

Implements xml_designer.

Definition at line 527 of file xmlimpl.cpp.

References _big_manager, _doc, _error, _small_manager, _xml_size, xml_persistor::get_error(), memory_output_stream::get_required_size(), memory_output_stream::is_overflow(), and xml_persistor::persist().

bool xml_designer_impl::add_child ( xmlNodeType  type,
const char *  name,
const char *  value,
bool  dont_move 
) [virtual]

add node as a child to the current node

node management element, attribute - name == name text, cdata, comment - name is ignored processing instruction - name == target

Parameters:
type  xml node type
name  name
value  value
dont_move  do not navigate from current position

Implements xml_designer.

Definition at line 551 of file xmlimpl.cpp.

References _import_node().

Referenced by merge(), xmlconfig::set(), xmlconfig::setlist(), and xmlconfig::xmlconfig().

bool xml_designer_impl::insert_sibling ( xmlNodeType  type,
const char *  name,
const char *  value,
bool  dont_move 
) [virtual]

inserts node before current node beneath the same parent

Parameters:
type  xml node type
name  name
value  value
dont_move  do not navigate from current position

Implements xml_designer.

Definition at line 557 of file xmlimpl.cpp.

References _import_node().

bool xml_designer_impl::append_sibling ( xmlNodeType  type,
const char *  name,
const char *  value,
bool  dont_move 
) [virtual]

appends node after current node beneath the same parent

Parameters:
type  xml node type
name  name
value  value
dont_move  do not navigate from current position

Implements xml_designer.

Definition at line 563 of file xmlimpl.cpp.

References _import_node().

bool xml_designer_impl::update_value ( const char *  value  )  [virtual]

bool xml_designer_impl::merge ( const xml_designer x,
bool  recursive 
) [virtual]

bool xml_designer_impl::validate ( bool  recursive  )  [virtual]

validates the xml node accorging to the current grammar

Parameters:
recursive  validate recursively

Implements xml_designer.

Definition at line 724 of file xmlimpl.cpp.

References _cur_node, _error, _validate(), xml_element::cast_to_element(), is_element(), and exception::what().

BEGIN_TERIMBER_NAMESPACE xmlNodeType xml_designer_impl::get_cur_type (  )  const [inline, protected]

gets the selected node type

Definition at line 38 of file xmlimpl.hpp.

References _cur_node, xml_node::_decl, and nodeDecl::get_type().

Referenced by get_name(), get_type(), get_value(), is_attribute(), is_container(), and is_element().

bool xml_designer_impl::is_attribute (  )  const [inline, protected]

checks if the selected node is an attribute

Definition at line 45 of file xmlimpl.hpp.

References ATTRIBUTE_NODE, and get_cur_type().

bool xml_designer_impl::is_element (  )  const [inline, protected]

checks if the selected node is an element

Definition at line 58 of file xmlimpl.hpp.

References ELEMENT_NODE, and get_cur_type().

Referenced by get_xpath(), has_attributes(), and validate().

bool xml_designer_impl::is_container (  )  const [inline, protected]

checks if the selected node is a container (element or document)

Definition at line 71 of file xmlimpl.hpp.

References DOCUMENT_NODE, ELEMENT_NODE, and get_cur_type().

Referenced by has_children().

bool xml_designer_impl::_import_node ( xmlNodeType  type,
const char *  name,
const char *  value,
bool  sibling,
bool  after,
bool  dont_move 
) [private]

inserts new xml node into document

Parameters:
type  node type
name  node name
value  node value
sibling  insert as a sibling to the selected node or as a child
after  insert before or after selected node
dont_move  do not navigate to the new node

Definition at line 763 of file xmlimpl.cpp.

References _cur_node, xml_node::_decl, _doc, _error, xml_tree_node::_parent, xml_document::add_attribute(), xml_document::add_cdata(), xml_document::add_comment(), xml_document::add_element(), xml_document::add_pi(), xml_document::add_text(), ATTRIBUTE_NODE, CDATA_SECTION_NODE, COMMENT_NODE, xml_document::container_pop(), xml_document::container_push(), DOCUMENT_NODE, DOCUMENT_TYPE_NODE, ELEMENT_NODE, nodeDecl::get_type(), PROCESSING_INSTRUCTION_NODE, TEXT_NODE, and exception::what().

Referenced by add_child(), append_sibling(), and insert_sibling().

void xml_designer_impl::_validate ( xml_element el,
bool  recursive 
) [private]

validates element

Parameters:
el  validate element
recursive  flag recursively

Definition at line 747 of file xmlimpl.cpp.

References _doc, xml_container::_first_child, xml_tree_node::_right, xml_element::cast_to_element(), ELEMENT_NODE, and xml_document::validate().

Referenced by validate().

bool xml_designer_impl::_load ( byte_source stream,
byte_source grammar 
) [private]

parses xml document from abstract streams for xml and DTD sources

Parameters:
stream  optional xml stream
grammar  optional DTD stream

Definition at line 883 of file xmlimpl.cpp.

References _big_manager, _cur_node, _doc, _error, _small_manager, _xml_size, xml_document::add_escaped_symbols(), xml_document::clear(), xml_document::container_start_doctype(), xml_document::container_stop_doctype(), xml_processor::get_error(), xml_processor::parse(), dtd_processor::parse(), and exception::what().

Referenced by load().


Member Data Documentation

size_t xml_designer_impl::_xml_size [private]

xml size - just a tip

Definition at line 285 of file xmlimpl.h.

Referenced by _load(), load(), and save().

small memory pool

Definition at line 286 of file xmlimpl.h.

Referenced by _load(), load(), save(), xml_designer_impl(), and ~xml_designer_impl().

big memory pool

Definition at line 287 of file xmlimpl.h.

Referenced by _load(), load(), and save().

temporary allocator

Definition at line 288 of file xmlimpl.h.

Referenced by get_value(), get_xpath(), select_xpath(), xml_designer_impl(), and ~xml_designer_impl().

string_t xml_designer_impl::_error [mutable, private]

last error

Definition at line 290 of file xmlimpl.h.

Referenced by _import_node(), _load(), error(), load(), merge(), remove_node(), save(), select_xpath(), update_value(), and validate().


The documentation for this class was generated from the following files:


© Copyright Terimber 2003-.