Public Types | Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes

XMLStorage::XMLStreamReader Struct Reference

#include <xmlstorage.h>

Collaboration diagram for XMLStorage::XMLStreamReader:
Collaboration graph
[legend]

List of all members.

Public Types

typedef XMLReader super

Public Member Functions

 XMLStreamReader (std::istream &in)
 XMLStreamReader (LPCTSTR path)
 ~XMLStreamReader ()
const XMLNodeoperator-> () const
 operator const XMLNode * () const
XS_String str () const
XS_String operator[] (const XS_String &attr_name) const
 Return the value of an attribute in the current node.
bool go_down ()
 Go down to first child.
bool go_down (LPCXSSTR child_name)
 Search for child and go down.
bool back ()
 Move back to the next higher nesting level.
bool first_child (LPCXSSTR node_name=NULL)
 Move to the first child node with the specified name.
bool next ()
 Move to the next sibling node independent from its name.
bool next_skip_others (const XS_String &node_name)
 Move to the next sibling node with the specified name.
bool next_stop_on_others (LPCXSSTR node_name=NULL)
 Move to the next sibling node with the specified name but stop on other tags.
bool find (const XPathElement &xelem)
bool find_relative (const XPath &xpath)
 XPath find function.
const XMLErrorListget_errors () const

Public Attributes

int _level

Protected Member Functions

bool find_node (LPCXSSTR target_tag, int target_level, int min_level, bool stop_on_others)
virtual void StartElementHandler (const XS_String &name, const XMLNode::AttributeMap &attr)
virtual void EndElementHandler ()
virtual void DefaultHandler (const std::string &s)

Protected Attributes

XMLNode _node

Private Member Functions

 XMLStreamReader (const XMLStreamReader &)

Private Attributes

tifstream_pInFile
XMLStateReader _state_rdr
std::string _content

Detailed Description

Definition at line 3113 of file xmlstorage.h.


Member Typedef Documentation

Definition at line 3115 of file xmlstorage.h.


Constructor & Destructor Documentation

XMLStorage::XMLStreamReader::XMLStreamReader ( std::istream &  in ) [inline]

Definition at line 3117 of file xmlstorage.h.

     :  _pInFile(NULL),
        _state_rdr(NULL, in),
        _level(0),
        _node(XS_EMPTY_STR)
    {
    }
XMLStorage::XMLStreamReader::XMLStreamReader ( LPCTSTR  path ) [inline]

Definition at line 3125 of file xmlstorage.h.

References XMLStorage::XMLStateReader::_parse_ctx, XMLStorage::ParseContext::_reader, _state_rdr, and XMLStorage::XMLReaderBase::setSystemId().

     :  _pInFile(new tifstream(path)),
        _state_rdr(NULL, *_pInFile),
        _level(0),
        _node(XS_EMPTY_STR)
    {
#ifdef UNICODE
        _state_rdr._parse_ctx._reader.setSystemId(std::string(XS_String(path)).c_str());
#else
        _state_rdr._parse_ctx._reader.setSystemId(path);
#endif
    }

Here is the call graph for this function:

XMLStorage::XMLStreamReader::~XMLStreamReader (  ) [inline]

Definition at line 3138 of file xmlstorage.h.

References _pInFile.

    {
        delete _pInFile;
    }
XMLStorage::XMLStreamReader::XMLStreamReader ( const XMLStreamReader  ) [private]

Member Function Documentation

bool XMLStorage::XMLStreamReader::back (  ) [inline]

Move back to the next higher nesting level.

Remark: This implementation does _not_ jump more than one level up like XMLPos.node() when using go() to move down more than one level at a time.

Returns:
true if successfull

Definition at line 3199 of file xmlstorage.h.

References _level, and find_node().

Referenced by test_read().

    {
        if (find_node(NULL, -1, _level+1, false))
//      if (find_node(NULL, _level-1, _level-1, false))
            return true;
        else {
            assert(_level>=0); // tried to move out of the tree hierarchy
            return false;
        }
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void XMLStorage::XMLStreamReader::DefaultHandler ( const std::string &  s ) [protected, virtual]

Definition at line 1245 of file xmlstorage.cpp.

{
    _content.append(DecodeXMLString(s));
}
void XMLStorage::XMLStreamReader::EndElementHandler (  ) [protected, virtual]

Definition at line 1236 of file xmlstorage.cpp.

{
    _node.clear();
    _node.get_attributes().clear();
    _content.erase();

    --_level;
}
bool XMLStorage::XMLStreamReader::find ( const XPathElement xelem ) [inline]

Definition at line 3248 of file xmlstorage.h.

References XMLStorage::XPathElement::_child_name, _node, first_child(), XMLStorage::XPathElement::matches(), and next_skip_others().

    {
        // cppcheck-suppress variableScope
        int n = 0;

        if (first_child(xelem._child_name)) {
            if (xelem.matches(_node, n))
                return true;

            while(next_skip_others(xelem._child_name))
                if (xelem.matches(_node, n))
                    return true;
        }

        return false;
    }

Here is the call graph for this function:

bool XMLStorage::XMLStreamReader::find_node ( LPCXSSTR  target_tag,
int  target_level,
int  min_level,
bool  stop_on_others 
) [protected]

Definition at line 1149 of file xmlstorage.cpp.

Referenced by back(), first_child(), next(), next_skip_others(), and next_stop_on_others().

{
    bool found = false;

    for(; _state_rdr.has_next(); _state_rdr.next()) {
        switch(_state_rdr._state) {
            case XMLStateReader::XSS_START_ELEMENT: {
                 // stop parsing if we found the target node and its content is already processed.
                if (found)
                    goto break_parsingLoop;

                 // check for match in target level and eventually node name
                if (_level+1 == target_level) {
                    if (target_tag==NULL || _state_rdr._node_name==target_tag)
                        found = true;
                    else if (stop_on_others)
                        return false;
                }

                StartElementHandler(_state_rdr._node_name, _state_rdr._attrs);
                break;}

            case XMLStateReader::XSS_ELEMENT:
                 // stop parsing if we found the target node and its content is already processed.
                if (found)
                    goto break_parsingLoop;

                 // check for match in target level and eventually node name
                if (_level+1 == target_level) {
                    if (target_tag==NULL || _state_rdr._node_name==target_tag)
                        found = true;
                    else if (stop_on_others)
                        return false;
                }

                StartElementHandler(_state_rdr._node_name, _state_rdr._attrs);
                _state_rdr.next(); // advance to the next state
                // fall through...

            case XMLStateReader::XSS_END_ELEMENT: {
                 // stop parsing if we found the target node and its content is already processed.
                if (found)
                    goto break_parsingLoop;

                 // stop before leaving the targeted level range; used by next_stop_on_others()
                if (_level == min_level)
                    return false;

                EndElementHandler();

                 // stop searching if the current level leaves the target range; used by back()
                if (_level < min_level) {
                    _state_rdr.next();
                    return false;
                }
                break;}

            case XMLStateReader::XSS_CHARACTERS:
//          case XMLStateReader::XSS_COMMENT:
//          case XMLStateReader::XSS_SPACE:
//          case XMLStateReader::XSS_CDATA:
                DefaultHandler(_state_rdr.get_encoded_content());
                break;

//          case XMLStateReader::XSS_PROCESSING_INSTRUCTION:
//              XmlDeclHandler();
//              break;
        }
    } break_parsingLoop:

    if (found) {
        _node.set_encoded_content(_content);
        _content.erase();
        return true;
    } else
        return false;
}

Here is the caller graph for this function:

bool XMLStorage::XMLStreamReader::find_relative ( const XPath xpath )

XPath find function.

Definition at line 1137 of file xmlstorage.cpp.

{
    for(XPath::const_iterator it=xpath.begin(); it!=xpath.end(); ++it) {
        const XPathElement& xelem = *it;

        if (!find(xelem))
            return false;
    }

    return true;
}
bool XMLStorage::XMLStreamReader::first_child ( LPCXSSTR  node_name = NULL ) [inline]

Move to the first child node with the specified name.

Returns:
true on success

Definition at line 3214 of file xmlstorage.h.

References _level, and find_node().

Referenced by find(), and go_down().

    {
        return find_node(node_name, _level+1, _level, false);
    }

Here is the call graph for this function:

Here is the caller graph for this function:

const XMLErrorList& XMLStorage::XMLStreamReader::get_errors (  ) const [inline]

Definition at line 3267 of file xmlstorage.h.

References _state_rdr, and XMLStorage::XMLReaderBase::get_errors().

Referenced by test_read().

{return _state_rdr.get_errors();}

Here is the call graph for this function:

Here is the caller graph for this function:

bool XMLStorage::XMLStreamReader::go_down (  ) [inline]

Go down to first child.

Returns:
true if successfull

Definition at line 3178 of file xmlstorage.h.

References first_child().

Referenced by test_read().

    {
        return first_child();
    }

Here is the call graph for this function:

Here is the caller graph for this function:

bool XMLStorage::XMLStreamReader::go_down ( LPCXSSTR  child_name ) [inline]

Search for child and go down.

Parameters:
child_name
Returns:

Definition at line 3188 of file xmlstorage.h.

References first_child().

    {
        return first_child(child_name);
    }

Here is the call graph for this function:

bool XMLStorage::XMLStreamReader::next (  ) [inline]

Move to the next sibling node independent from its name.

Returns:
true on success

Definition at line 3223 of file xmlstorage.h.

References _level, and find_node().

Referenced by XMLStorage::XMLStreamChildrenIterator::const_iterator::search_next().

    {
        return find_node(NULL, _level, _level-1, false);
    }

Here is the call graph for this function:

Here is the caller graph for this function:

bool XMLStorage::XMLStreamReader::next_skip_others ( const XS_String node_name ) [inline]

Move to the next sibling node with the specified name.

Returns:
true on success

Definition at line 3232 of file xmlstorage.h.

References _level, and find_node().

Referenced by find(), and XMLStorage::XMLStreamChildrenFilter::const_iterator::search_next().

    {
        return find_node(node_name, _level, _level-1, false);
    }

Here is the call graph for this function:

Here is the caller graph for this function:

bool XMLStorage::XMLStreamReader::next_stop_on_others ( LPCXSSTR  node_name = NULL ) [inline]

Move to the next sibling node with the specified name but stop on other tags.

Returns:
true on success

Definition at line 3242 of file xmlstorage.h.

References _level, and find_node().

    {
        return find_node(node_name, _level, _level-1, true);
    }

Here is the call graph for this function:

XMLStorage::XMLStreamReader::operator const XMLNode * (  ) const [inline]

Definition at line 3154 of file xmlstorage.h.

References _node.

    {
        return &_node;
    }
const XMLNode* XMLStorage::XMLStreamReader::operator-> (  ) const [inline]

Definition at line 3149 of file xmlstorage.h.

References _node.

    {
        return &_node;
    }
XS_String XMLStorage::XMLStreamReader::operator[] ( const XS_String attr_name ) const [inline]

Return the value of an attribute in the current node.

Parameters:
attr_name
Returns:

Definition at line 3169 of file xmlstorage.h.

References _node.

    {
        return _node[attr_name];
    }
void XMLStorage::XMLStreamReader::StartElementHandler ( const XS_String name,
const XMLNode::AttributeMap attr 
) [protected, virtual]

Definition at line 1227 of file xmlstorage.cpp.

{
    _node.assign(name);
    _node.get_attributes() = attr;
    _content.erase();

    ++_level;
}
XS_String XMLStorage::XMLStreamReader::str (  ) const [inline]

Member Data Documentation

Definition at line 3274 of file xmlstorage.h.

Definition at line 3281 of file xmlstorage.h.

Referenced by find(), operator const XMLNode *(), operator->(), operator[](), and str().

Definition at line 3272 of file xmlstorage.h.

Referenced by ~XMLStreamReader().

Definition at line 3273 of file xmlstorage.h.

Referenced by get_errors(), and XMLStreamReader().


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