summaryrefslogtreecommitdiff
path: root/inc/LDOM_Node.hxx
blob: 855211359f17264ba6303bb12e64e91057a337f9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// File:      LDOM_Node.hxx
// Created:   26.06.01 14:40:53
// Author:    Alexander GRIGORIEV
// Copyright: OpenCascade 2001
// History:     AGV 120202: Replace myDocument for myPtrDocument for better
//                          consistency of data

#ifndef LDOM_Node_HeaderFile
#define LDOM_Node_HeaderFile

#include <Standard_Macro.hxx>
#include <Standard_TypeDef.hxx>
#include <Handle_LDOM_MemManager.hxx>
#include <LDOMString.hxx>

class LDOM_BasicNode;

//  LDOM_Node : base class for LDOM interface objects
//              references LDOM_BasicNode - the real data stored in Document
//  This type can be safely cast to any derived type, e.g. :
//         LDOM_Node aNode          = MyGetElementNode();
//         LDOM_Element& anElemNode = (LDOM_Element&) aNode;
//         LDOMString anXcoord      = anElemNode.getAtttribute("x");

class LDOM_Node
{
 public:
  enum NodeType {
    UNKNOWN             = 0,
    ELEMENT_NODE        = 1,
    ATTRIBUTE_NODE      = 2,
    TEXT_NODE           = 3,
    CDATA_SECTION_NODE  = 4,
    COMMENT_NODE        = 8
    };

  // ---------- PUBLIC METHODS ----------

  LDOM_Node () : myOrigin        (NULL),
                 myLastChild     (NULL) {}
  //    Empty constructor

  LDOM_Node (const LDOM_Node& anOther)
    : myDocument        (anOther.myDocument),
      myOrigin          (anOther.myOrigin),
      myLastChild       (anOther.myLastChild) {}
  //    Copy constructor

  Standard_EXPORT const LDOM_MemManager& getOwnerDocument () const;

  Standard_EXPORT LDOM_Node&
                        operator =      (const LDOM_Node& anOther);

  Standard_EXPORT LDOM_Node&
                        operator =      (const LDOM_NullPtr * aNull); 

  Standard_Boolean      operator ==     (const LDOM_NullPtr *) const
                                        { return isNull(); }

  Standard_Boolean      operator !=     (const LDOM_NullPtr *) const
                                        { return ! isNull(); }

  Standard_EXPORT Standard_Boolean
                        operator ==     (const LDOM_Node& anOther) const;

  Standard_EXPORT Standard_Boolean
                        operator !=     (const LDOM_Node& anOther) const;

  Standard_EXPORT Standard_Boolean
                        isNull          () const;

  Standard_EXPORT NodeType
                        getNodeType     () const;

  Standard_EXPORT LDOMString
                        getNodeName     () const;

  Standard_EXPORT LDOMString
                        getNodeValue     () const;

  Standard_EXPORT LDOM_Node
                        getFirstChild   () const;

  Standard_EXPORT LDOM_Node
                        getLastChild   () const;

  Standard_EXPORT LDOM_Node
                        getNextSibling  () const;

  Standard_EXPORT void  removeChild     (const LDOM_Node& aChild);

  Standard_EXPORT void  appendChild     (const LDOM_Node& aChild);

  Standard_EXPORT Standard_Boolean
                        hasChildNodes   () const;

  Standard_EXPORT void  SetValueClear   () const;
  //    Avoids checking for '<', '&', '\'', '\"', etc. on storage (saves time)
  //    You MUST be pretty sure that the node value string is OK in this sense
  //    NEVER call this method if you are not stuck on the performance 

 protected:
friend class LDOM_BasicAttribute;
friend class LDOM_BasicElement;
friend class LDOM_BasicText;
friend class LDOM_NodeList;
  // ---------- PROTECTED METHODS ----------

  const LDOM_BasicNode& Origin          () const;

  LDOM_Node (const LDOM_BasicNode& anOrig, const Handle(LDOM_MemManager)& aDoc)
    : myDocument        (aDoc),
      myOrigin          ((LDOM_BasicNode *) &anOrig),
      myLastChild       (NULL) {}
  //    Copy constructor with assignment to Document

 protected:
  // ---------- PROTECTED FIELDS ----------

        // smart pointer to document owner of the node
  Handle(LDOM_MemManager)       myDocument;

        // pointer to (non-transient) node data in the document-managed memory
  LDOM_BasicNode                * myOrigin;

        // Transient data (only applicable to LDOM_Element type):
        // the last child; myLastChild->mySibling points to the first attribute
  const LDOM_BasicNode          * myLastChild;

  friend char * db_pretty_print (const LDOM_Node *, int, char *);
};

#endif