Warnings on vc14 were eliminated
[occt.git] / src / Interface / Interface_UndefinedContent.cxx
CommitLineData
973c2be1 1// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 2//
973c2be1 3// This file is part of Open CASCADE Technology software library.
b311480e 4//
d5f74e42 5// This library is free software; you can redistribute it and/or modify it under
6// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 7// by the Free Software Foundation, with special exception defined in the file
8// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9// distribution for complete text of the license and disclaimer of any warranty.
b311480e 10//
973c2be1 11// Alternatively, this file may be used under the terms of Open CASCADE
12// commercial license or contractual agreement.
b311480e 13
42cf5bc1 14
15#include <Interface_CopyTool.hxx>
16#include <Interface_EntityList.hxx>
7fd59977 17#include <Interface_InterfaceError.hxx>
42cf5bc1 18#include <Interface_InterfaceMismatch.hxx>
19#include <Interface_UndefinedContent.hxx>
7fd59977 20#include <Standard_NoSuchObject.hxx>
42cf5bc1 21#include <Standard_OutOfRange.hxx>
22#include <Standard_Transient.hxx>
23#include <Standard_Type.hxx>
24#include <TCollection_HAsciiString.hxx>
7fd59977 25
92efcf78 26IMPLEMENT_STANDARD_RTTIEXT(Interface_UndefinedContent,MMgt_TShared)
27
7fd59977 28#define Content_TypeField 31
29#define Content_LocalField 7
30#define Content_LocalRef 1
31#define Content_LocalShift 5
32#define Content_NumberShift 8
33
34// Cette classe donne les services de base pour definir des entites
35// Unknown (ceci, a defaut d'un double heritage) : description litterale
36
37
b311480e 38Interface_UndefinedContent::Interface_UndefinedContent () // Unknown
7fd59977 39{ thenbparams = 0; thenbstr = 0; }
40
41// .... Les Parametres ....
42
43// Les parametres sont organises comme suit (pas de FileParameter) :
44// - une liste de descripteurs (tenant sur un entier chacun) en tableau, avec
45// la localisation (Entity/literal), le type (ParamType), le rang dans la
46// la liste ad hoc (Entity ou literal)
47// (5 bits droits pour type; 3 bits pour localisation; restant pouradresse)
48// - pour les litteraux, une liste de String (tableau)
49// - pour les Entity, une liste d Entites (EntityList)
50// L aspect "place memoire" fait preferer des Tableaux a des Sequences, bien
51// que ces dernieres soient plus simples a gerer
52// En effet, il faut reserver et etendre si necessaire ...
53
54 Standard_Integer Interface_UndefinedContent::NbParams () const
55 { return thenbparams; }
56
57 Standard_Integer Interface_UndefinedContent::NbLiterals () const
58 { return thenbstr; }
59
60 Standard_Boolean Interface_UndefinedContent::ParamData
61 (const Standard_Integer num, Interface_ParamType& ptype,
62 Handle(Standard_Transient)& ent,
63 Handle(TCollection_HAsciiString)& val) const
64{
9775fa61 65 if (num < 1 || num > thenbparams) throw Standard_OutOfRange("Interface UndefinedContent : ParamData");
7fd59977 66 Standard_Integer desc = theparams->Value(num);
67 Standard_Integer local = ((desc >> Content_LocalShift) & Content_LocalField);
68 ptype = Interface_ParamType (desc & Content_TypeField);
69 Standard_Integer adr = desc >> Content_NumberShift;
70 if (local == Content_LocalRef) ent = theentities.Value(adr);
71 else val = thevalues->Value(adr);
72 return (local == Content_LocalRef); }
73
74
75 Interface_ParamType Interface_UndefinedContent::ParamType
76 (const Standard_Integer num) const
77{ return Interface_ParamType(theparams->Value(num) & Content_TypeField); }
78
79 Standard_Boolean Interface_UndefinedContent::IsParamEntity
80 (const Standard_Integer num) const
81{
82 return ( ((theparams->Value(num) >> Content_LocalShift) & Content_LocalField)
83 == Content_LocalRef);
84}
85
86 Handle(Standard_Transient) Interface_UndefinedContent::ParamEntity
87 (const Standard_Integer num) const
88{
89 Standard_Integer desc = theparams->Value(num);
90 if (((desc >> Content_LocalShift) & Content_LocalField) != Content_LocalRef)
9775fa61 91 throw Interface_InterfaceError("UndefinedContent : Param is not Entity type");
7fd59977 92 return theentities.Value (desc >> Content_NumberShift);
93}
94
95 Handle(TCollection_HAsciiString)
96Interface_UndefinedContent::ParamValue
97 (const Standard_Integer num) const
98{
99 Standard_Integer desc = theparams->Value(num);
100 if (((desc >> Content_LocalShift) & Content_LocalField) != 0)
9775fa61 101 throw Interface_InterfaceError("UndefinedContent : Param is not literal");
7fd59977 102 return thevalues->Value (desc >> Content_NumberShift);
103}
104
105
106// .... Remplissage des parametres ....
107
108 void Interface_UndefinedContent::Reservate
109 (const Standard_Integer nb, const Standard_Integer nblit)
110{
111// Reservation : Si agrandissement, recopier ancien dans nouveau ...
112 if (nb > thenbparams) { // Reservation en total
113 if (theparams.IsNull()) theparams =
114 new TColStd_HArray1OfInteger (1,nb);
115 else if (nb > theparams->Length()) {
116 Standard_Integer nbnew = 2*thenbparams; // on reserve un peu large
117 if (nbnew < nb) nbnew = nb;
118 Handle(TColStd_HArray1OfInteger) newparams =
119 new TColStd_HArray1OfInteger (1,nbnew);
120 for (Standard_Integer i = 1; i <= thenbparams; i ++)
121 newparams->SetValue(i,theparams->Value(i));
122 theparams = newparams;
123 }
124 }
125
126 if (nblit > thenbstr) { // Reservation en Litteraux
127 if (thevalues.IsNull()) thevalues =
128 new Interface_HArray1OfHAsciiString (1,nblit);
129 else if (nblit > thevalues->Length()) {
130 Standard_Integer nbnew = 2*thenbstr; // on reserve un peu large
131 if (nbnew < nblit) nbnew = nblit;
132 Handle(Interface_HArray1OfHAsciiString) newvalues =
133 new Interface_HArray1OfHAsciiString (1,nbnew);
134 for (Standard_Integer i = 1; i <= thenbstr; i ++)
135 newvalues->SetValue(i,thevalues->Value(i));
136 thevalues = newvalues;
137 }
138 }
139 // Entites : Parametres - Litteraux. En fait, EntityList est dynamique
140}
141
142 void Interface_UndefinedContent::AddLiteral
143 (const Interface_ParamType ptype,
144 const Handle(TCollection_HAsciiString)& val)
145{
146 Reservate (thenbparams+1,thenbstr+1);
147 Standard_Integer desc = Standard_Integer(ptype);
148 thenbstr ++;
149 thenbparams ++;
150 thevalues->SetValue (thenbstr,val);
151 desc += (thenbstr << Content_NumberShift);
152 theparams->SetValue (thenbparams,desc);
153}
154
155 void Interface_UndefinedContent::AddEntity
156 (const Interface_ParamType ptype,
157 const Handle(Standard_Transient)& ent)
158{
159 Reservate (thenbparams+1,0);
160 Standard_Integer desc = Standard_Integer(ptype);
161 theentities.Append (ent);
162 desc += Content_LocalRef << Content_LocalShift; // "C est une Entite"
163 thenbparams ++; // Rang : thenbparams - thenbstr
164 desc += ((thenbparams - thenbstr) << Content_NumberShift);
165 theparams->SetValue (thenbparams,desc);
166}
167
168
169// .... Edition des parametres ....
170
171 void Interface_UndefinedContent::RemoveParam (const Standard_Integer num)
172{
173 Standard_Integer desc = theparams->Value(num);
174 Standard_Integer rang = desc >> Content_NumberShift;
175 Standard_Integer local = ((desc >> Content_LocalShift) & Content_LocalField);
176 Standard_Boolean c1ent = (local == Content_LocalRef);
177// Supprimer une Entite
178 if (c1ent) theentities.Remove(rang);
179// Supprimer un Literal
180 else { // thevalues->Remove(rang) mais c est un tableau
181 for (Standard_Integer i = rang+1; i <= thenbstr; i ++)
182 thevalues->SetValue(i-1,thevalues->Value(i));
183 Handle(TCollection_HAsciiString) nulstr;
184 thevalues->SetValue(thenbstr,nulstr);
185 thenbstr --;
186 }
187// Supprimer ce parametre de la liste (qui est un tableau)
188 Standard_Integer np; // svv Jan11 2000 : porting on DEC
189 for (np = num+1; np <= thenbparams; np ++)
190 theparams->SetValue(np-1,theparams->Value(np));
191 theparams->SetValue(thenbparams,0);
192 thenbparams --;
193// Renumeroter, Entite ou Literal, selon
194 for (np = 1; np <= thenbparams; np ++) {
195 desc = theparams->Value(np);
196 if ( ((desc >> Content_LocalShift) & Content_LocalField) == local
197 && (desc >> Content_NumberShift) > rang)
198 theparams->SetValue(np,desc - (1 << Content_NumberShift));
199 }
200}
201
202 void Interface_UndefinedContent::SetLiteral
203 (const Standard_Integer num,
204 const Interface_ParamType ptype,
205 const Handle(TCollection_HAsciiString)& val)
206{
207// On change un parametre. Si deja literal, simple substitution
208// Si Entite, supprimer l entite et renumeroter les Parametres "Entite"
209 Standard_Integer desc = theparams->Value(num);
210 Standard_Integer rang = desc >> Content_NumberShift;
211 Standard_Integer local = ((desc >> Content_LocalShift) & Content_LocalField);
212 Standard_Boolean c1ent = (local == Content_LocalRef);
213 if (c1ent) {
214// Entite : la supprimer et renumeroter les Parametres de type "Entity"
215 theentities.Remove(rang);
216 for (Standard_Integer i = 1; i <= thenbparams; i ++) {
217 desc = theparams->Value(i);
218 if ( ((desc >> Content_LocalShift) & Content_LocalField) == Content_LocalRef
219 && (desc >> Content_NumberShift) > rang)
220 theparams->SetValue(i , desc - (1 << Content_NumberShift));
221 }
222// Et Preparer arrivee d un Literal supplementaire
223 Reservate (thenbparams,thenbstr+1);
224 thenbstr ++;
225 rang = thenbstr;
226 }
227// Mettre en place la nouvelle valeur et reconstruire le descripteur du Param
228 thevalues->SetValue(rang,val);
229 desc = Standard_Integer(ptype) + (rang << Content_NumberShift);
230 theparams->SetValue(num,desc);
231}
232
233
234 void Interface_UndefinedContent::SetEntity
235 (const Standard_Integer num,
236 const Interface_ParamType ptype,
237 const Handle(Standard_Transient)& ent)
238{
239// On change un Parametre. Si deja Entity, simple substitution
240// Si Literal, supprimer sa valeur et renumeroter les parametres Litteraux
241 Standard_Integer desc = theparams->Value(num);
242 Standard_Integer rang = desc >> Content_NumberShift;
243 Standard_Integer local = ((desc >> Content_LocalShift) & Content_LocalField);
244 Standard_Boolean c1ent = (local == Content_LocalRef);
245 if (!c1ent) {
246// Literal : le supprimer et renumeroter les Parametres de type "Entity"
247// (Remove Literal mais dans un tableau)
248 Standard_Integer i; // svv Jan11 2000 : porting on DEC
249 for (i = rang+1; i <= thenbstr; i ++)
250 thevalues->SetValue(i-1,thevalues->Value(i));
251 Handle(TCollection_HAsciiString) nulstr;
252 thevalues->SetValue(thenbstr,nulstr);
253
254 for (i = 1; i <= thenbparams; i ++) {
255 desc = theparams->Value(i);
256 if ( ((desc >> Content_LocalShift) & Content_LocalField) == 0
257 && (desc >> Content_NumberShift) > rang)
258 theparams->SetValue(i , desc - (1 << Content_NumberShift));
259 }
260// Et Preparer arrivee d une Entite supplementaire
261 thenbstr --;
262 rang = thenbparams - thenbstr;
263// Mettre en place la nouvelle valeur et reconstruire le descripteur du Param
264 theentities.Append(ent);
265 }
266 else theentities.SetValue(rang,ent);
267
268 desc = Standard_Integer(ptype) + (Content_LocalRef << Content_LocalShift)
269 + (rang << Content_NumberShift);
270 theparams->SetValue(num,desc);
271}
272
273
274 void Interface_UndefinedContent::SetEntity
275 (const Standard_Integer num,
276 const Handle(Standard_Transient)& ent)
277{
278// On change l Entite definie par un Parametre, toutes autres choses egales,
279// A CONDITION que ce soit deja un Parametre de type "Entity"
280 Standard_Integer desc = theparams->Value(num);
281 Standard_Integer rang = desc >> Content_NumberShift;
282 Standard_Integer local = ((desc >> Content_LocalShift) & Content_LocalField);
283 Standard_Boolean c1ent = (local == Content_LocalRef);
9775fa61 284 if (!c1ent) throw Interface_InterfaceError("UndefinedContent : SetEntity");
7fd59977 285 theentities.SetValue(rang,ent);
286}
287
288
289 Interface_EntityList Interface_UndefinedContent::EntityList () const
290 { return theentities; }
291
292
293
294// toutes les recopies de UndefinedEntity se ressemblent ... Partie commune
295 void Interface_UndefinedContent::GetFromAnother
296 (const Handle(Interface_UndefinedContent)& other, Interface_CopyTool& TC)
297{
298 Standard_Integer nb = other->NbParams();
299 theentities.Clear();
300 thevalues.Nullify();
301 theparams.Nullify();
302 Reservate (nb,other->NbLiterals());
303
304 Handle(Standard_Transient) ent;
305 for (Standard_Integer i = 1; i <= nb; i ++) {
306 Interface_ParamType ptype;
307 Handle(TCollection_HAsciiString) val;
308 if (other->ParamData (i, ptype,ent,val)) {
309 ent = TC.Transferred(ent);
310 AddEntity (ptype,ent);
311 }
312 else AddLiteral (ptype,val);
313 }
314}