7fd59977 |
1 | // File: TDataStd_ExtStringArray.cxx |
2 | // Created: Wed Jan 16 10:10:40 2002 |
3 | // Author: Michael PONIKAROV |
4 | // <mpv@covox> |
5 | |
6 | |
7 | #include <TDataStd_ExtStringArray.ixx> |
8 | #include <TDataStd_DeltaOnModificationOfExtStringArray.hxx> |
9 | #include <TDF_DefaultDeltaOnModification.hxx> |
10 | |
11 | //======================================================================= |
12 | //function : GetID |
13 | //purpose : |
14 | //======================================================================= |
15 | |
16 | const Standard_GUID& TDataStd_ExtStringArray::GetID() |
17 | { |
18 | static Standard_GUID anExtStringArrayID ("2a96b624-ec8b-11d0-bee7-080009dc3333"); |
19 | return anExtStringArrayID; |
20 | } |
21 | |
22 | |
23 | //======================================================================= |
24 | //function : TDataStd_ExtStringArray::TDataStd_ExtStringArray |
25 | //purpose : |
26 | //======================================================================= |
27 | |
28 | TDataStd_ExtStringArray::TDataStd_ExtStringArray() |
29 | : myIsDelta(Standard_False){} |
30 | |
31 | //======================================================================= |
32 | //function : Init |
33 | //purpose : |
34 | //======================================================================= |
35 | |
36 | void TDataStd_ExtStringArray::Init(const Standard_Integer lower, |
37 | const Standard_Integer upper) |
38 | { |
39 | Backup(); |
40 | myValue = new TColStd_HArray1OfExtendedString(lower, upper, ""); |
41 | } |
42 | |
43 | //======================================================================= |
44 | //function : Set |
45 | //purpose : |
46 | //======================================================================= |
47 | |
48 | Handle(TDataStd_ExtStringArray) TDataStd_ExtStringArray::Set ( |
49 | const TDF_Label& label, |
50 | const Standard_Integer lower, |
51 | const Standard_Integer upper, |
52 | const Standard_Boolean isDelta) |
53 | |
54 | { |
55 | Handle(TDataStd_ExtStringArray) A; |
56 | if (!label.FindAttribute (TDataStd_ExtStringArray::GetID(), A)) { |
57 | A = new TDataStd_ExtStringArray; |
58 | A->Init (lower, upper); |
59 | A->SetDelta(isDelta); |
60 | label.AddAttribute(A); |
61 | } |
62 | else if (lower != A->Lower() || upper != A->Upper()) |
63 | { |
64 | A->Init (lower, upper); |
65 | } |
66 | return A; |
67 | } |
68 | |
69 | |
70 | //======================================================================= |
71 | //function : SetValue |
72 | //purpose : |
73 | //======================================================================= |
74 | |
75 | void TDataStd_ExtStringArray::SetValue(const Standard_Integer index, const TCollection_ExtendedString& value) |
76 | { |
77 | if(myValue.IsNull()) return; |
78 | if( myValue->Value(index) == value) |
79 | return; |
80 | |
81 | Backup(); |
82 | myValue->SetValue(index, value); |
83 | } |
84 | |
85 | |
86 | //======================================================================= |
87 | //function : GetValue |
88 | //purpose : |
89 | //======================================================================= |
90 | |
91 | TCollection_ExtendedString TDataStd_ExtStringArray::Value (const Standard_Integer index) const |
92 | { |
93 | if(myValue.IsNull()) return TCollection_ExtendedString(); |
94 | return myValue->Value(index); |
95 | } |
96 | |
97 | |
98 | |
99 | //======================================================================= |
100 | //function : Lower |
101 | //purpose : |
102 | //======================================================================= |
103 | Standard_Integer TDataStd_ExtStringArray::Lower (void) const |
104 | { |
105 | if(myValue.IsNull()) return 0; |
106 | return myValue->Lower(); |
107 | } |
108 | |
109 | |
110 | //======================================================================= |
111 | //function : Upper |
112 | //purpose : |
113 | //======================================================================= |
114 | Standard_Integer TDataStd_ExtStringArray::Upper (void) const |
115 | { |
116 | if(myValue.IsNull()) return 0; |
117 | return myValue->Upper(); |
118 | } |
119 | |
120 | |
121 | //======================================================================= |
122 | //function : Length |
123 | //purpose : |
124 | //======================================================================= |
125 | Standard_Integer TDataStd_ExtStringArray::Length (void) const |
126 | { |
127 | if(myValue.IsNull()) return 0; |
128 | return myValue->Length(); |
129 | } |
130 | |
131 | |
132 | |
133 | //======================================================================= |
134 | //function : ChangeArray |
135 | //purpose : If value of <newArray> differs from <myValue>, Backup |
136 | // : performed and myValue refers to new instance of HArray1OfExtendedString |
137 | // : that holds <newArray> |
138 | //======================================================================= |
139 | |
140 | void TDataStd_ExtStringArray::ChangeArray(const Handle(TColStd_HArray1OfExtendedString)& newArray, |
141 | const Standard_Boolean isCheckItems) |
142 | { |
143 | Standard_Integer aLower = newArray->Lower(); |
144 | Standard_Integer anUpper = newArray->Upper(); |
145 | Standard_Boolean aDimEqual = Standard_False; |
146 | Standard_Integer i; |
147 | |
a855b7eb |
148 | if (Lower() == aLower && Upper() == anUpper ) { |
7fd59977 |
149 | aDimEqual = Standard_True; |
150 | Standard_Boolean isEqual = Standard_True; |
151 | if(isCheckItems) { |
152 | for(i = aLower; i <= anUpper; i++) { |
153 | if(myValue->Value(i) != newArray->Value(i)) { |
154 | isEqual = Standard_False; |
155 | break; |
156 | } |
157 | } |
158 | if(isEqual) |
159 | return; |
160 | } |
161 | } |
162 | |
163 | Backup(); |
164 | |
165 | // Handles of myValue of current and backuped attributes will be different!!! |
a855b7eb |
166 | if(myValue.IsNull() || !aDimEqual) |
7fd59977 |
167 | myValue = new TColStd_HArray1OfExtendedString(aLower, anUpper); |
168 | |
169 | for(i = aLower; i <= anUpper; i++) |
170 | myValue->SetValue(i, newArray->Value(i)); |
171 | } |
172 | |
173 | //======================================================================= |
174 | //function : ID |
175 | //purpose : |
176 | //======================================================================= |
177 | |
178 | const Standard_GUID& TDataStd_ExtStringArray::ID () const { return GetID(); } |
179 | |
180 | |
181 | //======================================================================= |
182 | //function : NewEmpty |
183 | //purpose : |
184 | //======================================================================= |
185 | |
186 | Handle(TDF_Attribute) TDataStd_ExtStringArray::NewEmpty () const |
187 | { |
188 | return new TDataStd_ExtStringArray(); |
189 | } |
190 | |
191 | //======================================================================= |
192 | //function : Restore |
193 | //purpose : |
194 | //======================================================================= |
195 | |
196 | void TDataStd_ExtStringArray::Restore(const Handle(TDF_Attribute)& With) |
197 | { |
198 | Standard_Integer i, lower, upper; |
199 | Handle(TDataStd_ExtStringArray) anArray = Handle(TDataStd_ExtStringArray)::DownCast(With); |
200 | if(!anArray->myValue.IsNull()) { |
201 | lower = anArray->Lower(); |
202 | upper = anArray->Upper(); |
203 | myValue = new TColStd_HArray1OfExtendedString(lower, upper); |
204 | for(i = lower; i<=upper; i++) |
205 | myValue->SetValue(i, anArray->Value(i)); |
206 | myIsDelta = anArray->myIsDelta; |
207 | } |
208 | else |
209 | myValue.Nullify(); |
210 | } |
211 | |
212 | //======================================================================= |
213 | //function : Paste |
214 | //purpose : |
215 | //======================================================================= |
216 | |
217 | void TDataStd_ExtStringArray::Paste (const Handle(TDF_Attribute)& Into, |
218 | const Handle(TDF_RelocationTable)& ) const |
219 | { |
220 | if(!myValue.IsNull()) { |
221 | Handle(TDataStd_ExtStringArray) anAtt = Handle(TDataStd_ExtStringArray)::DownCast(Into); |
222 | if(!anAtt.IsNull()) { |
223 | anAtt->ChangeArray( myValue, Standard_False ); |
224 | anAtt->SetDelta(myIsDelta); |
225 | } |
226 | } |
227 | } |
228 | |
229 | //======================================================================= |
230 | //function : Dump |
231 | //purpose : |
232 | //======================================================================= |
233 | |
234 | Standard_OStream& TDataStd_ExtStringArray::Dump (Standard_OStream& anOS) const |
235 | { |
236 | anOS << "ExtStringArray :"; |
237 | if(!myValue.IsNull()) { |
238 | Standard_Integer i, lower, upper; |
239 | lower = myValue->Lower(); |
240 | upper = myValue->Upper(); |
241 | for(i = lower; i<=upper; i++) |
242 | anOS << "\t" <<myValue->Value(i)<<endl; |
243 | } |
244 | anOS << " Delta is " << myIsDelta ? "ON":"OFF"; |
245 | anOS << endl; |
246 | return anOS; |
247 | } |
248 | |
249 | //======================================================================= |
250 | //function : DeltaOnModification |
251 | //purpose : |
252 | //======================================================================= |
253 | |
254 | Handle(TDF_DeltaOnModification) TDataStd_ExtStringArray::DeltaOnModification |
255 | (const Handle(TDF_Attribute)& OldAttribute) const |
256 | { |
257 | if(myIsDelta) |
258 | return new TDataStd_DeltaOnModificationOfExtStringArray(*((Handle(TDataStd_ExtStringArray)*)&OldAttribute)); |
259 | else return new TDF_DefaultDeltaOnModification(OldAttribute); |
260 | } |
261 | |