7fd59977 |
1 | //szv#4 S4163 |
2 | #include <Interface_ParamSet.ixx> |
3 | |
4 | |
5 | Interface_ParamSet::Interface_ParamSet (const Standard_Integer nres, const Standard_Integer )//nst) |
6 | { |
7 | thelist = new Interface_ParamList;// (nst,nst+nres+2); |
8 | themxpar = nres; |
9 | thenbpar = 0; |
10 | thelnval = 0; |
11 | thelnres = 100; // *20; // 10 caracteres par Param (\0 inclus) : raisonnable |
12 | theval = new char[thelnres]; //szv#4:S4163:12Mar99 `thelnres+1` chars was wrong |
13 | } |
14 | |
15 | |
16 | // Append(CString) : Gestion des caracteres selon <lnval> |
17 | // Si lnval < 0, ParamSet passif, memoire geree de l exterieur, ParamSet |
18 | // se contente de s y referer |
19 | // Sinon, recopie dans une page locale |
20 | |
21 | Standard_Integer Interface_ParamSet::Append (const Standard_CString val, const Standard_Integer lnval, |
22 | const Interface_ParamType typ, const Standard_Integer nument) |
23 | { |
24 | // Ici, gestion locale de String |
25 | thenbpar ++; |
26 | if (thenbpar > themxpar) { |
27 | thenext = new Interface_ParamSet (themxpar,1); |
28 | return (thenbpar + thenext->Append(val,lnval,typ,nument)); |
29 | } |
30 | else if (lnval < 0) { |
31 | // .. Gestion externe des caracteres .. |
32 | Interface_FileParameter& FP = thelist->ChangeValue(thenbpar); |
33 | FP.Init(val,typ); |
34 | if (nument != 0) FP.SetEntityNumber(nument); |
35 | } |
36 | else { |
37 | // .. Gestion locale des caracteres .. |
38 | Standard_Integer i; |
39 | if (thelnval + lnval + 1 > thelnres) { |
40 | // Reservation de caracteres insuffisante : d abord augmenter |
41 | Standard_Integer newres = thelnres*2 + lnval ; |
42 | char* newval = new char[newres]; |
43 | for (i = 0; i < thelnval; i++) |
44 | newval[i] = theval[i]; //szv#4:S4163:12Mar99 `<= thelnres` was wrong |
45 | // et cepatou : il faut realigner les Params deja enregistres sur |
46 | // l ancienne reservation de caracteres ... |
47 | //Standard_Integer delta = (Standard_Integer) (newval - theval); |
48 | // difference a appliquer |
49 | char* poldVal = &theval[0]; |
50 | char* pnewVal= &newval[0]; |
51 | for (i = 1; i < thenbpar; i ++) { |
52 | Interface_FileParameter& OFP = thelist->ChangeValue(i); |
53 | Interface_ParamType otyp = OFP.ParamType(); |
54 | char* oval = (char*)OFP.CValue(); |
55 | Standard_Integer delta = (Standard_Integer) (oval - poldVal); |
56 | //if (oval < theval || oval >= (theval+thelnres)) |
57 | // continue; //hors reserve //szv#4:S4163:12Mar99 `oval >` was wrong |
58 | Standard_Integer onum = OFP.EntityNumber(); |
59 | OFP.Init(pnewVal+delta,otyp); // et voila; on remet dans la boite |
60 | if (onum != 0) OFP.SetEntityNumber(onum); |
61 | } |
62 | // Enteriner la nouvelle reservation |
63 | delete [] theval; |
64 | theval = newval; |
65 | thelnres = newres; |
66 | } |
67 | // Enregistrer ce parametre |
68 | for (i = 0; i < lnval; i ++) theval[thelnval + i] = val[i]; |
69 | theval[thelnval+lnval] = '\0'; |
70 | |
71 | Interface_FileParameter& FP = thelist->ChangeValue(thenbpar); |
72 | FP.Init(&theval[thelnval],typ); |
73 | if (nument != 0) FP.SetEntityNumber(nument); |
74 | thelnval += (lnval+1); |
75 | } |
76 | return thenbpar; |
77 | } |
78 | |
79 | Standard_Integer Interface_ParamSet::Append (const Interface_FileParameter& FP) |
80 | { |
81 | // Ici, FP tout pret : pas de gestion memoire sur String (dommage) |
82 | |
83 | thenbpar ++; |
84 | if (thenbpar > themxpar) { |
85 | thenext = new Interface_ParamSet (themxpar,1); |
86 | return thenbpar + thenext->Append(FP); |
87 | } |
88 | thelist->SetValue(thenbpar,FP); |
89 | return thenbpar; |
90 | } |
91 | |
92 | Standard_Integer Interface_ParamSet::NbParams () const |
93 | { return thenbpar; } |
94 | |
95 | const Interface_FileParameter& Interface_ParamSet::Param (const Standard_Integer num) const |
96 | { |
97 | if (num > themxpar) return thenext->Param(num - themxpar); |
98 | else return thelist->Value(num); |
99 | } |
100 | |
101 | Interface_FileParameter& Interface_ParamSet::ChangeParam (const Standard_Integer num) |
102 | { |
103 | if (num > themxpar) return thenext->ChangeParam(num - themxpar); |
104 | else return thelist->ChangeValue(num); |
105 | } |
106 | |
107 | void Interface_ParamSet::SetParam (const Standard_Integer num, const Interface_FileParameter& FP) |
108 | { |
109 | if (num > themxpar) thenext->SetParam(num - themxpar, FP); |
110 | else thelist->SetValue(num,FP); |
111 | } |
112 | |
113 | Handle(Interface_ParamList) Interface_ParamSet::Params (const Standard_Integer num, |
114 | const Standard_Integer nb) const |
115 | { |
116 | Standard_Integer i, n0 = num-1, nbp = nb; |
117 | if (num > themxpar) |
118 | return thenext->Params (num-themxpar,nb); |
119 | if (num == 0 && nb == 0) { |
120 | n0 = 0; nbp = thenbpar; |
121 | if (thenbpar <= themxpar) |
122 | return thelist; // et zou |
123 | } |
124 | Handle(Interface_ParamList) list = new Interface_ParamList; |
125 | if (nb == 0) |
126 | return list; |
127 | |
128 | for (i = 1; i <= nbp; i ++) list->SetValue(i,Param(n0+i)); |
129 | return list; |
130 | } |
131 | |
132 | void Interface_ParamSet::Destroy () |
133 | { |
134 | // if (!thenext.IsNull()) thenext->Destroy(); |
135 | thenext.Nullify(); |
136 | // Destruction "manuelle" (gestion memoire directe) |
137 | if (theval) delete [] theval; |
138 | theval = NULL; |
139 | thelist->Clear(); |
140 | thelist.Nullify(); |
141 | } |