1
1
/* ************ Array C++ Functions Source Code File (.CPP) *************/
2
2
/* Name: ARRAY.CPP Version 2.3 */
3
3
/* */
4
- /* (C) Copyright to the author Olivier BERTRAND 2005-2017 */
4
+ /* (C) Copyright to the author Olivier BERTRAND 2005-2019 */
5
5
/* */
6
6
/* This file contains the XOBJECT derived class ARRAY functions. */
7
7
/* ARRAY is used for elaborate type of processing, such as sorting */
@@ -67,7 +67,7 @@ PARRAY MakeValueArray(PGLOBAL g, PPARM pp); // avoid gcc warning
67
67
/* MakeValueArray: Makes a value array from a value list. */
68
68
/* **********************************************************************/
69
69
PARRAY MakeValueArray (PGLOBAL g, PPARM pp)
70
- {
70
+ {
71
71
int n, valtyp = 0 ;
72
72
size_t len = 0 ;
73
73
PARRAY par;
@@ -82,8 +82,7 @@ PARRAY MakeValueArray(PGLOBAL g, PPARM pp)
82
82
if ((valtyp = pp->Type ) != TYPE_STRING)
83
83
len = 1 ;
84
84
85
- if (trace (1 ))
86
- htrc (" valtyp=%d len=%d\n " , valtyp, len);
85
+ xtrc (1 , " valtyp=%d len=%d\n " , valtyp, len);
87
86
88
87
/* ********************************************************************/
89
88
/* Firstly check the list and count the number of values in it. */
@@ -127,13 +126,13 @@ PARRAY MakeValueArray(PGLOBAL g, PPARM pp)
127
126
// Integer stored inside pp->Value
128
127
par->AddValue (g, parmp->Intval );
129
128
break ;
130
- } // endswitch valtyp
129
+ } // endswitch valtyp
131
130
132
131
/* ********************************************************************/
133
132
/* Send back resulting array. */
134
133
/* ********************************************************************/
135
134
return par;
136
- } // end of MakeValueArray
135
+ } // end of MakeValueArray
137
136
138
137
/* -------------------------- Class ARRAY ---------------------------- */
139
138
@@ -151,6 +150,9 @@ ARRAY::ARRAY(PGLOBAL g, int type, int size, int length, int prec)
151
150
Type = type;
152
151
Xsize = -1 ;
153
152
Len = 1 ;
153
+ X = 0 ;
154
+ Inf = 0 ;
155
+ Sup = 0 ;
154
156
155
157
switch (type) {
156
158
case TYPE_STRING:
@@ -281,130 +283,109 @@ void ARRAY::Empty(void)
281
283
/* Add a string element to an array. */
282
284
/* **********************************************************************/
283
285
bool ARRAY::AddValue (PGLOBAL g, PSZ strp)
284
- {
286
+ {
285
287
if (Type != TYPE_STRING) {
286
288
sprintf (g->Message , MSG (ADD_BAD_TYPE), GetTypeName (Type), " CHAR" );
287
289
return true ;
288
- } // endif Type
289
-
290
- if (trace (1 ))
291
- htrc (" adding string(%d): '%s'\n " , Nval, strp);
290
+ } // endif Type
292
291
293
- // Value->SetValue_psz(strp);
294
- // Vblp->SetValue(valp, Nval++);
292
+ xtrc (1 , " adding string(%d): '%s'\n " , Nval, strp);
295
293
Vblp->SetValue (strp, Nval++);
296
294
return false ;
297
- } // end of AddValue
295
+ } // end of AddValue
298
296
299
297
/* **********************************************************************/
300
298
/* Add a char pointer element to an array. */
301
299
/* **********************************************************************/
302
300
bool ARRAY::AddValue (PGLOBAL g, void *p)
303
- {
301
+ {
304
302
if (Type != TYPE_PCHAR) {
305
303
sprintf (g->Message , MSG (ADD_BAD_TYPE), GetTypeName (Type), " PCHAR" );
306
304
return true ;
307
- } // endif Type
308
-
309
- if (trace (1 ))
310
- htrc (" adding pointer(%d): %p\n " , Nval, p);
305
+ } // endif Type
311
306
307
+ xtrc (1 , " adding pointer(%d): %p\n " , Nval, p);
312
308
Vblp->SetValue ((PSZ)p, Nval++);
313
309
return false ;
314
- } // end of AddValue
310
+ } // end of AddValue
315
311
316
312
/* **********************************************************************/
317
313
/* Add a short integer element to an array. */
318
314
/* **********************************************************************/
319
315
bool ARRAY::AddValue (PGLOBAL g, short n)
320
- {
316
+ {
321
317
if (Type != TYPE_SHORT) {
322
318
sprintf (g->Message , MSG (ADD_BAD_TYPE), GetTypeName (Type), " SHORT" );
323
319
return true ;
324
- } // endif Type
325
-
326
- if (trace (1 ))
327
- htrc (" adding SHORT(%d): %hd\n " , Nval, n);
320
+ } // endif Type
328
321
329
- // Value->SetValue(n);
330
- // Vblp->SetValue(valp, Nval++);
322
+ xtrc (1 , " adding SHORT(%d): %hd\n " , Nval, n);
331
323
Vblp->SetValue (n, Nval++);
332
324
return false ;
333
- } // end of AddValue
325
+ } // end of AddValue
334
326
335
327
/* **********************************************************************/
336
328
/* Add an integer element to an array. */
337
329
/* **********************************************************************/
338
330
bool ARRAY::AddValue (PGLOBAL g, int n)
339
- {
331
+ {
340
332
if (Type != TYPE_INT) {
341
333
sprintf (g->Message , MSG (ADD_BAD_TYPE), GetTypeName (Type), " INTEGER" );
342
334
return true ;
343
- } // endif Type
335
+ } // endif Type
344
336
345
- if (trace (1 ))
346
- htrc (" adding int(%d): %d\n " , Nval, n);
347
-
348
- // Value->SetValue(n);
349
- // Vblp->SetValue(valp, Nval++);
337
+ xtrc (1 , " adding int(%d): %d\n " , Nval, n);
350
338
Vblp->SetValue (n, Nval++);
351
339
return false ;
352
- } // end of AddValue
340
+ } // end of AddValue
353
341
354
342
/* **********************************************************************/
355
343
/* Add a double float element to an array. */
356
344
/* **********************************************************************/
357
345
bool ARRAY::AddValue (PGLOBAL g, double d)
358
- {
346
+ {
359
347
if (Type != TYPE_DOUBLE) {
360
348
sprintf (g->Message , MSG (ADD_BAD_TYPE), GetTypeName (Type), " DOUBLE" );
361
349
return true ;
362
- } // endif Type
363
-
364
- if (trace (1 ))
365
- htrc (" adding float(%d): %lf\n " , Nval, d);
350
+ } // endif Type
366
351
352
+ xtrc (1 , " adding float(%d): %lf\n " , Nval, d);
367
353
Value->SetValue (d);
368
354
Vblp->SetValue (Value, Nval++);
369
355
return false ;
370
- } // end of AddValue
356
+ } // end of AddValue
371
357
372
358
/* **********************************************************************/
373
359
/* Add the value of a XOBJECT block to an array. */
374
360
/* **********************************************************************/
375
361
bool ARRAY::AddValue (PGLOBAL g, PXOB xp)
376
- {
377
- if (Type != xp->GetResultType ()) {
378
- sprintf (g->Message , MSG (ADD_BAD_TYPE),
379
- GetTypeName (xp->GetResultType ()), GetTypeName (Type));
380
- return true ;
381
- } // endif Type
382
-
383
- if (trace (1 ))
384
- htrc (" adding (%d) from xp=%p\n " , Nval, xp);
362
+ {
363
+ if (Type != xp->GetResultType ()) {
364
+ sprintf (g->Message , MSG (ADD_BAD_TYPE),
365
+ GetTypeName (xp->GetResultType ()), GetTypeName (Type));
366
+ return true ;
367
+ } // endif Type
385
368
386
- // AddValue(xp->GetValue() );
387
- Vblp->SetValue (xp->GetValue (), Nval++);
388
- return false ;
389
- } // end of AddValue
369
+ xtrc ( 1 , " adding (%d) from xp=%p \n " , Nval, xp );
370
+ Vblp->SetValue (xp->GetValue (), Nval++);
371
+ return false ;
372
+ } // end of AddValue
390
373
391
374
/* **********************************************************************/
392
375
/* Add a value to an array. */
393
376
/* **********************************************************************/
394
377
bool ARRAY::AddValue (PGLOBAL g, PVAL vp)
395
- {
378
+ {
396
379
if (Type != vp->GetType ()) {
397
380
sprintf (g->Message , MSG (ADD_BAD_TYPE),
398
381
GetTypeName (vp->GetType ()), GetTypeName (Type));
399
382
return true ;
400
- } // endif Type
401
-
402
- if (trace (1 ))
403
- htrc (" adding (%d) from vp=%p\n " , Nval, vp);
383
+ } // endif Type
404
384
385
+ xtrc (1 , " adding (%d) from vp=%p\n " , Nval, vp);
405
386
Vblp->SetValue (vp, Nval++);
406
387
return false ;
407
- } // end of AddValue
388
+ } // end of AddValue
408
389
409
390
/* **********************************************************************/
410
391
/* Retrieve the nth value of the array. */
@@ -973,7 +954,7 @@ int ARRAY::BlockTest(PGLOBAL, int opc, int opm,
973
954
/* MakeArrayList: Makes a value list from an SQL IN array (in work). */
974
955
/* **********************************************************************/
975
956
PSZ ARRAY::MakeArrayList (PGLOBAL g)
976
- {
957
+ {
977
958
char *p, *tp;
978
959
int i;
979
960
size_t z, len = 2 ;
@@ -988,11 +969,9 @@ PSZ ARRAY::MakeArrayList(PGLOBAL g)
988
969
Value->SetValue_pvblk (Vblp, i);
989
970
Value->Prints (g, tp, z);
990
971
len += strlen (tp);
991
- } // enfor i
992
-
993
- if (trace (1 ))
994
- htrc (" Arraylist: len=%d\n " , len);
972
+ } // enfor i
995
973
974
+ xtrc (1 , " Arraylist: len=%d\n " , len);
996
975
p = (char *)PlugSubAlloc (g, NULL , len);
997
976
strcpy (p, " (" );
998
977
@@ -1001,19 +980,17 @@ PSZ ARRAY::MakeArrayList(PGLOBAL g)
1001
980
Value->Prints (g, tp, z);
1002
981
strcat (p, tp);
1003
982
strcat (p, (++i == Nval) ? " )" : " ," );
1004
- } // enfor i
1005
-
1006
- if (trace (1 ))
1007
- htrc (" Arraylist: newlen=%d\n " , strlen (p));
983
+ } // enfor i
1008
984
985
+ xtrc (1 , " Arraylist: newlen=%d\n " , strlen (p));
1009
986
return p;
1010
- } // end of MakeArrayList
987
+ } // end of MakeArrayList
1011
988
1012
989
/* **********************************************************************/
1013
990
/* Make file output of ARRAY contents. */
1014
991
/* **********************************************************************/
1015
992
void ARRAY::Printf (PGLOBAL g, FILE *f, uint n)
1016
- {
993
+ {
1017
994
char m[64 ];
1018
995
int lim = MY_MIN (Nval,10 );
1019
996
@@ -1035,19 +1012,19 @@ void ARRAY::Printf(PGLOBAL g, FILE *f, uint n)
1035
1012
} else
1036
1013
fprintf (f, " %sVALLST: numval=%d\n " , m, Nval);
1037
1014
1038
- } // end of Printf
1015
+ } // end of Printf
1039
1016
1040
1017
/* **********************************************************************/
1041
1018
/* Make string output of ARRAY contents. */
1042
1019
/* **********************************************************************/
1043
1020
void ARRAY::Prints (PGLOBAL, char *ps, uint z)
1044
- {
1021
+ {
1045
1022
if (z < 16 )
1046
1023
return ;
1047
1024
1048
1025
sprintf (ps, " ARRAY: type=%d\n " , Type);
1049
1026
// More to be implemented later
1050
- } // end of Prints
1027
+ } // end of Prints
1051
1028
1052
1029
/* -------------------------- Class MULAR ---------------------------- */
1053
1030
0 commit comments