Statistics
| Branch: | Revision:

root / src / sim / minixpath.h @ e26d3d25

History | View | Annotate | Download (2.15 KB)

1
//==========================================================================
2
//  MINIXPATH.H - part of
3
//                 OMNeT++/OMNEST
4
//              Discrete System Simulation in C++
5
//
6
// Contents:
7
//   class MiniXPath
8
//
9
//==========================================================================
10

    
11
/*--------------------------------------------------------------*
12
  Copyright (C) 2002-2008 Andras Varga
13
  Copyright (C) 2006-2008 OpenSim Ltd.
14

15
  This file is distributed WITHOUT ANY WARRANTY. See the file
16
  `license' for details on this and other legal matters.
17
*--------------------------------------------------------------*/
18

    
19

    
20
#ifndef __MINIXPATH_H__
21
#define __MINIXPATH_H__
22

    
23
#include "cxmlelement.h"
24

    
25
NAMESPACE_BEGIN
26

    
27

    
28
/**
29
 * A minimalistic XPath interpreter.
30
 */
31
class MiniXPath
32
{
33
  private:
34
    cXMLElement *docNode; // document node (parent of root element) of the ongoing match
35
    cXMLElement::ParamResolver *resolver;
36

    
37
  private:
38
    bool parseTagNameFromStepExpr(std::string& tagname, const char *stepexpr, int len);
39
    bool parseBracketedNum(int& n, const char *s, int len);
40
    bool parseConstant(std::string& value, const char *s, int len);
41
    bool parseBracketedAttrEquals(std::string& attr, std::string& value, const char *s, int len);
42
    cXMLElement *getFirstSiblingWithAttribute(cXMLElement *firstsibling, const char *tagname, const char *attr, const char *attrvalue);
43
    cXMLElement *getNthSibling(cXMLElement *firstsibling, const char *tagname, int n);
44
    cXMLElement *recursiveMatch(cXMLElement *node, const char *pathexpr);
45
    cXMLElement *matchSeparator(cXMLElement *node, const char *seppathexpr);
46
    cXMLElement *matchStep(cXMLElement *node, const char *pathexpr);
47

    
48
  public:
49
    /**
50
     * Ctor takes the resolver for parameters ($PARAM).
51
     */
52
    MiniXPath(cXMLElement::ParamResolver *resolver);
53

    
54
    /**
55
     * Returns the first match for pathexpr, from the given node as context.
56
     * Optional document node (i.e. parent of root element) will be used
57
     * if path expression starts with '/' or '//'.
58
     */
59
    cXMLElement *matchPathExpression(cXMLElement *contextNode, const char *pathexpr, cXMLElement *documentNode);
60
};
61

    
62
NAMESPACE_END
63

    
64

    
65
#endif
66

    
67