0003513: There is no check for boundary of array in method Set for array attributes
[occt.git] / src / TDataStd / TDataStd_Expression.cxx
1 // Created on: 1997-12-16
2 // Created by: Denis PASCAL
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
5 //
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
10 //
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 //
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
20
21
22
23 #include <TDataStd_Expression.ixx>
24 #include <TCollection_AsciiString.hxx>
25 #include <TDataStd_Variable.hxx>
26 #include <TDF_ListIteratorOfAttributeList.hxx>
27
28 //=======================================================================
29 //function : GetID
30 //purpose  : 
31 //=======================================================================
32
33 const Standard_GUID& TDataStd_Expression::GetID() 
34 {  
35   static Standard_GUID TDataStd_ExpressionID("ce24146a-8e57-11d1-8953-080009dc4425");
36   return TDataStd_ExpressionID;
37 }
38
39 //=======================================================================
40 //function : Set
41 //purpose  : 
42 //=======================================================================
43
44 Handle(TDataStd_Expression) TDataStd_Expression::Set(const TDF_Label& L) 
45 {  
46   Handle(TDataStd_Expression) A;
47   if (!L.FindAttribute (TDataStd_Expression::GetID(), A)) {
48     A = new TDataStd_Expression (); 
49     L.AddAttribute(A);
50   }
51   return A;
52 }
53
54 //=======================================================================
55 //function : TDataStd_Expression
56 //purpose  : 
57 //=======================================================================
58
59 TDataStd_Expression::TDataStd_Expression()
60 {
61 }
62
63
64 //=======================================================================
65 //function : Name
66 //purpose  : 
67 //=======================================================================
68 TCollection_ExtendedString TDataStd_Expression::Name () const 
69 {  
70   return myExpression; // ->String();
71 }
72
73 //=======================================================================
74 //function : SetExpression
75 //purpose  : 
76 //=======================================================================
77
78 void TDataStd_Expression::SetExpression(const TCollection_ExtendedString& E)
79 {
80   // OCC2932 correction
81   if(myExpression == E) return;
82
83   Backup();
84   myExpression = E;
85 }
86
87 //=======================================================================
88 //function : GetExpression
89 //purpose  : 
90 //=======================================================================
91
92 const TCollection_ExtendedString& TDataStd_Expression::GetExpression () const
93 {
94   return myExpression;
95 }
96
97 //=======================================================================
98 //function : GetVariables
99 //purpose  : 
100 //=======================================================================
101
102 TDF_AttributeList& TDataStd_Expression::GetVariables()
103 {
104   return myVariables;
105 }
106
107 //=======================================================================
108 //function : ID
109 //purpose  : 
110 //=======================================================================
111
112 const Standard_GUID& TDataStd_Expression::ID() const
113 {
114   return GetID();
115 }
116
117 //=======================================================================
118 //function : Restore
119 //purpose  : 
120 //=======================================================================
121
122 void TDataStd_Expression::Restore(const Handle(TDF_Attribute)& With) 
123 {  
124   Handle(TDataStd_Expression) EXPR = Handle(TDataStd_Expression)::DownCast (With);
125   myExpression = EXPR->GetExpression();
126
127   Handle(TDataStd_Variable) V;
128   for (TDF_ListIteratorOfAttributeList it (EXPR->GetVariables()); it.More(); it.Next()) {
129     V = Handle(TDataStd_Variable)::DownCast(it.Value());
130     myVariables.Append(V);
131   }
132 }
133
134 //=======================================================================
135 //function : NewEmpty
136 //purpose  : 
137 //=======================================================================
138
139 Handle(TDF_Attribute) TDataStd_Expression::NewEmpty() const
140 {
141   return new TDataStd_Expression();
142 }
143
144 //=======================================================================
145 //function : Paste
146 //purpose  : 
147 //=======================================================================
148
149 void TDataStd_Expression::Paste(const Handle(TDF_Attribute)& Into,
150                                  const Handle(TDF_RelocationTable)& RT) const
151 {  
152   Handle(TDataStd_Expression) EXPR = Handle(TDataStd_Expression)::DownCast (Into); 
153   EXPR->SetExpression(myExpression);  
154   Handle(TDataStd_Variable) V1,V2;
155   for (TDF_ListIteratorOfAttributeList it (myVariables); it.More(); it.Next()) {
156     V1 = Handle(TDataStd_Variable)::DownCast(it.Value());
157     RT->HasRelocation (V1,V2);
158     EXPR->GetVariables().Append(V2);
159   }
160 }
161
162 //=======================================================================
163 //function : Dump
164 //purpose  : 
165 //=======================================================================
166
167 Standard_OStream& TDataStd_Expression::Dump(Standard_OStream& anOS) const
168
169   anOS << "Expression";
170   return anOS;
171 }
172