summaryrefslogtreecommitdiff
path: root/src/Interface/Interface_UndefinedContent.cxx
blob: 33a4939c41088a593664875d7f4c77d2946cc17a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
#include <Interface_UndefinedContent.ixx>
#include <Interface_InterfaceMismatch.hxx>
#include <Interface_InterfaceError.hxx>
#include <Standard_NoSuchObject.hxx>


#define Content_TypeField 31
#define Content_LocalField 7
#define Content_LocalRef 1
#define Content_LocalShift 5
#define Content_NumberShift 8

// Cette classe donne les services de base pour definir des entites
// Unknown (ceci, a defaut d'un double heritage) : description litterale


    Interface_UndefinedContent::Interface_UndefinedContent () // Unknown
{  thenbparams = 0;  thenbstr = 0;  }

// ....  Les Parametres ....

// Les parametres sont organises comme suit (pas de FileParameter) :
// - une liste de descripteurs (tenant sur un entier chacun) en tableau, avec
// la localisation (Entity/literal), le type (ParamType), le rang dans la
// la liste ad hoc (Entity ou literal)
// (5 bits droits pour type; 3 bits pour localisation; restant pouradresse)
// - pour les litteraux, une liste de String (tableau)
// - pour les Entity, une liste d Entites (EntityList)
// L aspect "place memoire" fait preferer des Tableaux a des Sequences, bien
// que ces dernieres soient plus simples a gerer
// En effet, il faut reserver et etendre si necessaire ...

    Standard_Integer Interface_UndefinedContent::NbParams () const
      { return thenbparams; }

    Standard_Integer Interface_UndefinedContent::NbLiterals () const
      { return thenbstr; }

    Standard_Boolean Interface_UndefinedContent::ParamData
  (const Standard_Integer num, Interface_ParamType& ptype,
   Handle(Standard_Transient)& ent,
   Handle(TCollection_HAsciiString)& val) const
{
  if (num < 1 || num > thenbparams) Standard_OutOfRange::Raise
    ("Interface UndefinedContent : ParamData");
  Standard_Integer desc  = theparams->Value(num);
  Standard_Integer local = ((desc >> Content_LocalShift) & Content_LocalField);
  ptype = Interface_ParamType (desc & Content_TypeField);
  Standard_Integer adr = desc >> Content_NumberShift;
  if (local == Content_LocalRef) ent = theentities.Value(adr);
  else val = thevalues->Value(adr);
  return (local == Content_LocalRef); }


    Interface_ParamType Interface_UndefinedContent::ParamType
  (const Standard_Integer num) const
{ return Interface_ParamType(theparams->Value(num) & Content_TypeField); }

    Standard_Boolean Interface_UndefinedContent::IsParamEntity
  (const Standard_Integer num) const
{
  return ( ((theparams->Value(num) >> Content_LocalShift) & Content_LocalField)
	  == Content_LocalRef);
}

    Handle(Standard_Transient) Interface_UndefinedContent::ParamEntity
  (const Standard_Integer num) const
{
  Standard_Integer desc = theparams->Value(num);
  if (((desc >> Content_LocalShift) & Content_LocalField) != Content_LocalRef)
    Interface_InterfaceError::Raise
      ("UndefinedContent : Param is not Entity type");
  return theentities.Value (desc >> Content_NumberShift);
}

    Handle(TCollection_HAsciiString)
Interface_UndefinedContent::ParamValue
  (const Standard_Integer num) const
{
  Standard_Integer desc = theparams->Value(num);
  if (((desc >> Content_LocalShift) & Content_LocalField) != 0)
    Interface_InterfaceError::Raise
      ("UndefinedContent : Param is not literal");
  return thevalues->Value (desc >> Content_NumberShift);
}


// ....  Remplissage des parametres ....

    void Interface_UndefinedContent::Reservate
  (const Standard_Integer nb, const Standard_Integer nblit)
{
// Reservation : Si agrandissement, recopier ancien dans nouveau ...
  if (nb > thenbparams) { // Reservation en total
    if (theparams.IsNull()) theparams =
      new TColStd_HArray1OfInteger (1,nb);
    else if (nb > theparams->Length()) {
      Standard_Integer nbnew = 2*thenbparams;    // on reserve un peu large
      if (nbnew < nb) nbnew = nb;
      Handle(TColStd_HArray1OfInteger) newparams =
	new TColStd_HArray1OfInteger (1,nbnew);
      for (Standard_Integer i = 1; i <= thenbparams; i ++)
	newparams->SetValue(i,theparams->Value(i));
      theparams = newparams;
    }
  }

  if (nblit > thenbstr) { // Reservation en Litteraux
    if (thevalues.IsNull()) thevalues =
      new Interface_HArray1OfHAsciiString (1,nblit);
    else if (nblit > thevalues->Length()) {
      Standard_Integer nbnew = 2*thenbstr;    // on reserve un peu large
      if (nbnew < nblit) nbnew = nblit;
      Handle(Interface_HArray1OfHAsciiString) newvalues =
	new Interface_HArray1OfHAsciiString (1,nbnew);
      for (Standard_Integer i = 1; i <= thenbstr; i ++)
	newvalues->SetValue(i,thevalues->Value(i));
      thevalues = newvalues;
    }
  }
  //  Entites : Parametres - Litteraux. En fait, EntityList est dynamique
}

    void Interface_UndefinedContent::AddLiteral
  (const Interface_ParamType ptype,
   const Handle(TCollection_HAsciiString)& val)
{
  Reservate (thenbparams+1,thenbstr+1);
  Standard_Integer desc = Standard_Integer(ptype);
  thenbstr ++;
  thenbparams ++;
  thevalues->SetValue (thenbstr,val);
  desc += (thenbstr << Content_NumberShift);
  theparams->SetValue (thenbparams,desc);
}

    void Interface_UndefinedContent::AddEntity
  (const Interface_ParamType ptype,
   const Handle(Standard_Transient)& ent)
{
  Reservate (thenbparams+1,0);
  Standard_Integer desc = Standard_Integer(ptype);
  theentities.Append (ent);
  desc += Content_LocalRef << Content_LocalShift;        // "C est une Entite"
  thenbparams ++;    // Rang  :  thenbparams - thenbstr
  desc += ((thenbparams - thenbstr) << Content_NumberShift);
  theparams->SetValue (thenbparams,desc);
}


// ....  Edition des parametres ....

    void Interface_UndefinedContent::RemoveParam (const Standard_Integer num)
{
  Standard_Integer desc  = theparams->Value(num);
  Standard_Integer rang  = desc >> Content_NumberShift;
  Standard_Integer local = ((desc >> Content_LocalShift) & Content_LocalField);
  Standard_Boolean c1ent = (local == Content_LocalRef);
//    Supprimer une Entite
  if (c1ent) theentities.Remove(rang);
//    Supprimer un Literal
  else {      // thevalues->Remove(rang)  mais c est un tableau
    for (Standard_Integer i = rang+1; i <= thenbstr; i ++)
      thevalues->SetValue(i-1,thevalues->Value(i));
    Handle(TCollection_HAsciiString) nulstr;
    thevalues->SetValue(thenbstr,nulstr);
    thenbstr --;
  }
//    Supprimer ce parametre de la liste (qui est un tableau)
  Standard_Integer np; // svv Jan11 2000 : porting on DEC
  for (np = num+1; np <= thenbparams; np ++)
    theparams->SetValue(np-1,theparams->Value(np));
  theparams->SetValue(thenbparams,0);
  thenbparams --;
//    Renumeroter, Entite ou Literal, selon
  for (np = 1; np <= thenbparams; np ++) {
    desc = theparams->Value(np);
    if (  ((desc >> Content_LocalShift) & Content_LocalField) == local
	&& (desc >> Content_NumberShift) > rang)
      theparams->SetValue(np,desc - (1 << Content_NumberShift));
  }
}

    void Interface_UndefinedContent::SetLiteral
  (const Standard_Integer num,
   const Interface_ParamType ptype,
   const Handle(TCollection_HAsciiString)& val)
{
//  On change un parametre. Si deja literal, simple substitution
//  Si Entite, supprimer l entite et renumeroter les Parametres "Entite"
  Standard_Integer desc  = theparams->Value(num);
  Standard_Integer rang  = desc >> Content_NumberShift;
  Standard_Integer local = ((desc >> Content_LocalShift) & Content_LocalField);
  Standard_Boolean c1ent = (local == Content_LocalRef);
  if (c1ent) {
//  Entite : la supprimer et renumeroter les Parametres de type "Entity"
    theentities.Remove(rang);
    for (Standard_Integer i = 1; i <= thenbparams; i ++) {
      desc = theparams->Value(i);
      if (  ((desc >> Content_LocalShift) & Content_LocalField) == Content_LocalRef
	  && (desc >> Content_NumberShift) > rang)
	theparams->SetValue(i , desc - (1 << Content_NumberShift));
    }
//  Et Preparer arrivee d un Literal supplementaire
    Reservate (thenbparams,thenbstr+1);
    thenbstr ++;
    rang = thenbstr;
  }
//  Mettre en place la nouvelle valeur et reconstruire le descripteur du Param
  thevalues->SetValue(rang,val);
  desc = Standard_Integer(ptype) + (rang << Content_NumberShift);
  theparams->SetValue(num,desc);
}


    void Interface_UndefinedContent::SetEntity
  (const Standard_Integer num,
   const Interface_ParamType ptype,
   const Handle(Standard_Transient)& ent)
{
//  On change un Parametre. Si deja Entity, simple substitution
//  Si Literal, supprimer sa valeur et renumeroter les parametres Litteraux
  Standard_Integer desc  = theparams->Value(num);
  Standard_Integer rang  = desc >> Content_NumberShift;
  Standard_Integer local = ((desc >> Content_LocalShift) & Content_LocalField);
  Standard_Boolean c1ent = (local == Content_LocalRef);
  if (!c1ent) {
//  Literal : le supprimer et renumeroter les Parametres de type "Entity"
//  (Remove Literal mais dans un tableau)
    Standard_Integer i; // svv Jan11 2000 : porting on DEC
    for (i = rang+1; i <= thenbstr; i ++)
      thevalues->SetValue(i-1,thevalues->Value(i));
    Handle(TCollection_HAsciiString) nulstr;
    thevalues->SetValue(thenbstr,nulstr);

    for (i = 1; i <= thenbparams; i ++) {
      desc = theparams->Value(i);
      if (  ((desc >> Content_LocalShift) & Content_LocalField) == 0
	  && (desc >> Content_NumberShift) > rang)
	theparams->SetValue(i , desc - (1 << Content_NumberShift));
    }
//  Et Preparer arrivee d une Entite supplementaire
    thenbstr --;
    rang = thenbparams - thenbstr;
//  Mettre en place la nouvelle valeur et reconstruire le descripteur du Param
    theentities.Append(ent);
  }
  else theentities.SetValue(rang,ent);

  desc = Standard_Integer(ptype) + (Content_LocalRef << Content_LocalShift)
    + (rang << Content_NumberShift);
  theparams->SetValue(num,desc);
}


    void Interface_UndefinedContent::SetEntity
  (const Standard_Integer num,
   const Handle(Standard_Transient)& ent)
{
//  On change l Entite definie par un Parametre, toutes autres choses egales,
//  A CONDITION que ce soit deja un Parametre de type "Entity"
  Standard_Integer desc  = theparams->Value(num);
  Standard_Integer rang  = desc >> Content_NumberShift;
  Standard_Integer local = ((desc >> Content_LocalShift) & Content_LocalField);
  Standard_Boolean c1ent = (local == Content_LocalRef);
  if (!c1ent) Interface_InterfaceError::Raise("UndefinedContent : SetEntity");
  theentities.SetValue(rang,ent);
}


    Interface_EntityList Interface_UndefinedContent::EntityList () const
      {  return theentities;  }



//    toutes les recopies de UndefinedEntity se ressemblent ... Partie commune
    void Interface_UndefinedContent::GetFromAnother
  (const Handle(Interface_UndefinedContent)& other,  Interface_CopyTool& TC)
{
  Standard_Integer nb = other->NbParams();
  theentities.Clear();
  thevalues.Nullify();
  theparams.Nullify();
  Reservate (nb,other->NbLiterals());

  Handle(Standard_Transient) ent;
  for (Standard_Integer i = 1; i <= nb; i ++) {
    Interface_ParamType ptype;
    Handle(TCollection_HAsciiString) val;
    if (other->ParamData (i, ptype,ent,val)) {
      ent = TC.Transferred(ent);
      AddEntity  (ptype,ent);
    }
    else AddLiteral (ptype,val);
  }
}