0024157: Parallelization of assembly part of BO
[occt.git] / src / XmlObjMgt / XmlObjMgt_Array1.gxx
CommitLineData
b311480e 1// Created on: 2001-08-01
2// Created by: Julia DOROVSKIKH
3// Copyright (c) 2001-2012 OPEN CASCADE SAS
4//
5// The content of this file is subject to the Open CASCADE Technology Public
6// License Version 6.5 (the "License"). You may not use the content of this file
7// except in compliance with the License. Please obtain a copy of the License
8// at http://www.opencascade.org and read it completely before using this file.
9//
10// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12//
13// The Original Code and all software distributed under the License is
14// distributed on an "AS IS" basis, without warranty of any kind, and the
15// Initial Developer hereby disclaims all such warranties, including without
16// limitation, any warranties of merchantability, fitness for a particular
17// purpose or non-infringement. Please see the License for the specific terms
18// and conditions governing the rights and limitations under the License.
19
20//AGV 130202: Changed prototype LDOM_Node::getOwnerDocument()
7fd59977 21
22#include <XmlObjMgt.hxx>
23#include <XmlObjMgt_DOMString.hxx>
24#include <TCollection_AsciiString.hxx>
25
26IMPLEMENT_DOMSTRING (LowerString, "lower")
27IMPLEMENT_DOMSTRING (UpperString, "upper")
28IMPLEMENT_DOMSTRING (IndString, "index")
29
30//=======================================================================
31//function : XmlObjMgt_Array1
32//purpose : Constructor
33//=======================================================================
34
35XmlObjMgt_Array1::XmlObjMgt_Array1 (const XmlObjMgt_Element& theParent,
36 const XmlObjMgt_DOMString& theName)
37 : myElement (XmlObjMgt::FindChildByName (theParent, theName)),
38 myFirst (1),
39 myLast (0)
40{
41 if (myElement != NULL) {
42 if (!myElement.getAttribute(::LowerString()).GetInteger(myFirst))
43 myFirst = 1;
44 if (!myElement.getAttribute(::UpperString()).GetInteger (myLast))
45 myLast = 1;
46 }
47}
48
49//=======================================================================
50//function : XmlObjMgt_Array1
51//purpose : Constructor
52//=======================================================================
53
54XmlObjMgt_Array1::XmlObjMgt_Array1 (const Standard_Integer aFirst,
55 const Standard_Integer aLast)
56 : myFirst (aFirst), myLast (aLast)
57{}
58
59//=======================================================================
60//function : CreateArrayElement
61//purpose : Create DOM_Element representing the array, under 'theParent'
62//=======================================================================
63
64void XmlObjMgt_Array1::CreateArrayElement (XmlObjMgt_Element& theParent,
65 const XmlObjMgt_DOMString& theName)
66{
67 if (myLast > 0)
68 {
69//AGV XmlObjMgt_Document& anOwnerDoc =
70//AGV (XmlObjMgt_Document&)theParent.getOwnerDocument();
71 XmlObjMgt_Document anOwnerDoc =
72 XmlObjMgt_Document (theParent.getOwnerDocument());
73 myElement = anOwnerDoc.createElement (theName);
74 theParent.appendChild (myElement);
75 if (myLast > 1) {
76 myElement.setAttribute (::UpperString(), myLast);
77 if (myFirst != 1)
78 myElement.setAttribute (::LowerString(), myFirst);
79 }
80 }
81}
82
83//=======================================================================
84//function : SetValue
85//purpose :
86//=======================================================================
87
88void XmlObjMgt_Array1::SetValue
89 (const Standard_Integer theIndex, XmlObjMgt_Element& theValue)
90{
91 myElement.appendChild (theValue);
92 theValue.setAttribute(::IndString(), theIndex);
93}
94
95//=======================================================================
96//function : Value
97//purpose :
98//=======================================================================
99
100XmlObjMgt_Element XmlObjMgt_Array1::Value(const Standard_Integer theIndex) const
101{
102 XmlObjMgt_Element anElem;
103
104 if (theIndex >= myFirst && theIndex <= myLast)
105 {
106 Standard_Integer ind;
107 LDOM_Node aNode = myElement.getFirstChild();
108 while (!aNode.isNull())
109 {
110 if (aNode.getNodeType() == LDOM_Node::ELEMENT_NODE)
111 {
112 anElem = (XmlObjMgt_Element &) aNode;
113 if (anElem.getAttribute(::IndString()).GetInteger(ind))
114 if (ind == theIndex)
115 break;
116 }
117 aNode = aNode.getNextSibling();
118 }
119 }
120 return anElem;
121}