7fd59977 |
1 | // File: LDOM_Node.hxx |
2 | // Created: 26.06.01 14:40:53 |
3 | // Author: Alexander GRIGORIEV |
4 | // Copyright: OpenCascade 2001 |
5 | // History: AGV 120202: Replace myDocument for myPtrDocument for better |
6 | // consistency of data |
7 | |
8 | #ifndef LDOM_Node_HeaderFile |
9 | #define LDOM_Node_HeaderFile |
10 | |
11 | #include <Standard_Macro.hxx> |
12 | #include <Standard_TypeDef.hxx> |
13 | #include <Handle_LDOM_MemManager.hxx> |
14 | #include <LDOMString.hxx> |
15 | |
16 | class LDOM_BasicNode; |
17 | |
18 | // LDOM_Node : base class for LDOM interface objects |
19 | // references LDOM_BasicNode - the real data stored in Document |
20 | // This type can be safely cast to any derived type, e.g. : |
21 | // LDOM_Node aNode = MyGetElementNode(); |
22 | // LDOM_Element& anElemNode = (LDOM_Element&) aNode; |
23 | // LDOMString anXcoord = anElemNode.getAtttribute("x"); |
24 | |
25 | class LDOM_Node |
26 | { |
27 | public: |
28 | enum NodeType { |
29 | UNKNOWN = 0, |
30 | ELEMENT_NODE = 1, |
31 | ATTRIBUTE_NODE = 2, |
32 | TEXT_NODE = 3, |
33 | CDATA_SECTION_NODE = 4, |
34 | COMMENT_NODE = 8 |
35 | }; |
36 | |
37 | // ---------- PUBLIC METHODS ---------- |
38 | |
39 | LDOM_Node () : myOrigin (NULL), |
40 | myLastChild (NULL) {} |
41 | // Empty constructor |
42 | |
43 | LDOM_Node (const LDOM_Node& anOther) |
44 | : myDocument (anOther.myDocument), |
45 | myOrigin (anOther.myOrigin), |
46 | myLastChild (anOther.myLastChild) {} |
47 | // Copy constructor |
48 | |
49 | Standard_EXPORT const LDOM_MemManager& getOwnerDocument () const; |
50 | |
51 | Standard_EXPORT LDOM_Node& |
52 | operator = (const LDOM_Node& anOther); |
53 | |
54 | Standard_EXPORT LDOM_Node& |
55 | operator = (const LDOM_NullPtr * aNull); |
56 | |
57 | Standard_Boolean operator == (const LDOM_NullPtr *) const |
58 | { return isNull(); } |
59 | |
60 | Standard_Boolean operator != (const LDOM_NullPtr *) const |
61 | { return ! isNull(); } |
62 | |
63 | Standard_EXPORT Standard_Boolean |
64 | operator == (const LDOM_Node& anOther) const; |
65 | |
66 | Standard_EXPORT Standard_Boolean |
67 | operator != (const LDOM_Node& anOther) const; |
68 | |
69 | Standard_EXPORT Standard_Boolean |
70 | isNull () const; |
71 | |
72 | Standard_EXPORT NodeType |
73 | getNodeType () const; |
74 | |
75 | Standard_EXPORT LDOMString |
76 | getNodeName () const; |
77 | |
78 | Standard_EXPORT LDOMString |
79 | getNodeValue () const; |
80 | |
81 | Standard_EXPORT LDOM_Node |
82 | getFirstChild () const; |
83 | |
84 | Standard_EXPORT LDOM_Node |
85 | getLastChild () const; |
86 | |
87 | Standard_EXPORT LDOM_Node |
88 | getNextSibling () const; |
89 | |
90 | Standard_EXPORT void removeChild (const LDOM_Node& aChild); |
91 | |
92 | Standard_EXPORT void appendChild (const LDOM_Node& aChild); |
93 | |
94 | Standard_EXPORT Standard_Boolean |
95 | hasChildNodes () const; |
96 | |
97 | Standard_EXPORT void SetValueClear () const; |
98 | // Avoids checking for '<', '&', '\'', '\"', etc. on storage (saves time) |
99 | // You MUST be pretty sure that the node value string is OK in this sense |
100 | // NEVER call this method if you are not stuck on the performance |
101 | |
102 | protected: |
103 | friend class LDOM_BasicAttribute; |
104 | friend class LDOM_BasicElement; |
105 | friend class LDOM_BasicText; |
106 | friend class LDOM_NodeList; |
107 | // ---------- PROTECTED METHODS ---------- |
108 | |
109 | const LDOM_BasicNode& Origin () const; |
110 | |
111 | LDOM_Node (const LDOM_BasicNode& anOrig, const Handle(LDOM_MemManager)& aDoc) |
112 | : myDocument (aDoc), |
113 | myOrigin ((LDOM_BasicNode *) &anOrig), |
114 | myLastChild (NULL) {} |
115 | // Copy constructor with assignment to Document |
116 | |
117 | protected: |
118 | // ---------- PROTECTED FIELDS ---------- |
119 | |
120 | // smart pointer to document owner of the node |
121 | Handle(LDOM_MemManager) myDocument; |
122 | |
123 | // pointer to (non-transient) node data in the document-managed memory |
124 | LDOM_BasicNode * myOrigin; |
125 | |
126 | // Transient data (only applicable to LDOM_Element type): |
127 | // the last child; myLastChild->mySibling points to the first attribute |
128 | const LDOM_BasicNode * myLastChild; |
129 | |
130 | friend char * db_pretty_print (const LDOM_Node *, int, char *); |
131 | }; |
132 | |
133 | #endif |