-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGS_LIST.CPP.bak
11871 lines (9676 loc) · 340 KB
/
GS_LIST.CPP.bak
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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**********************************************************
Name: GS_LIST
Module description: File funzioni di base per la gestione
delle classi di entita'
Author: Poltini Roberto
(c) Copyright 1995-2014 by IREN ACQUA GAS S.p.a.
Modification history:
Notes and restrictions on use:
**********************************************************/
/*****************************************************************************/
/* INCLUDE */
/*****************************************************************************/
#include "stdafx.h" // MFC core and standard components
#define INITGUID
#import "msado15.dll" no_namespace rename ("EOF", "EndOfFile") rename ("EOS", "ADOEOS")
#include <stdio.h>
#include <stdlib.h>
#include <io.h>
#include <string.h>
#include <math.h>
#include "rxdefs.h"
#include "adslib.h"
#include "..\gs_def.h" // definizioni globali
#include "gs_error.h"
#include "gs_utily.h"
#include "gs_resbf.h"
#include "gs_list.h"
#include "gs_ase.h"
#include "gs_init.h"
#include "gs_class.h"
#include "gs_area.h"
#include "gs_lisp.h"
#include "gs_graph.h"
#include "gs_topo.h" // per "gsc_OverlapValidation"
//---------------------------------------------------------------------------//
// class C_NODE //
//---------------------------------------------------------------------------//
C_NODE::C_NODE()
{
next=prev=NULL;
}
C_NODE::C_NODE(C_NODE *p,C_NODE *n)
{
prev=p;
next=n;
}
C_NODE::~C_NODE() {}
int C_NODE::get_key()
{
GS_ERR_COD=eGSInvClassType;
return GS_BAD;
}
int C_NODE::set_key(int in)
{
GS_ERR_COD=eGSInvClassType;
return GS_BAD;
}
double C_NODE::get_key_double()
{
GS_ERR_COD=eGSInvClassType;
return GS_BAD;
}
long C_NODE::get_id()
{
GS_ERR_COD=eGSInvClassType;
return GS_BAD;
}
int C_NODE::set_key(double in)
{
GS_ERR_COD=eGSInvClassType;
return GS_BAD;
}
int C_NODE::get_type()
{
GS_ERR_COD=eGSInvClassType;
return GS_BAD;
}
int C_NODE::set_type(int in)
{
GS_ERR_COD=eGSInvClassType;
return GS_BAD;
}
TCHAR* C_NODE::get_name()
{
GS_ERR_COD=eGSInvClassType;
return _T("");
}
int C_NODE::set_name(const TCHAR *in)
{
GS_ERR_COD=eGSInvClassType;
return GS_BAD;
}
int C_NODE::set_name(const char *in)
{
GS_ERR_COD=eGSInvClassType;
return GS_BAD;
}
TCHAR* C_NODE::get_name2()
{
GS_ERR_COD=eGSInvClassType;
return _T("");
}
int C_NODE::set_name2(const TCHAR *in)
{
GS_ERR_COD=eGSInvClassType;
return GS_BAD;
}
int C_NODE::set_name2(const char *in)
{
GS_ERR_COD=eGSInvClassType;
return GS_BAD;
}
C_NODE* C_NODE::get_next()
{
return next;
}
C_NODE* C_NODE::get_prev()
{
return prev;
}
int C_NODE::get_category()
{
GS_ERR_COD=eGSInvClassType;
return GS_BAD;
}
GSDataPermissionTypeEnum C_NODE::get_level()
{
GS_ERR_COD = eGSInvClassType;
return GSNonePermission;
}
int C_NODE::comp(void *in)
{
return 0;
}
//---------------------------------------------------------------------------//
// class C_LIST. //
//---------------------------------------------------------------------------//
C_LIST::C_LIST()
{
head=tail=cursor=NULL;
count=0;
fCompPtr = NULL;
}
C_LIST::~C_LIST()
{
remove_all();
}
int C_LIST::get_count() const
{
return count;
}
int C_LIST::is_empty() const
{
if (count==0)
return TRUE;
else
return FALSE;
}
C_NODE* C_LIST::get_head()
{
cursor=head;
return head;
}
C_NODE* C_LIST::get_tail()
{
cursor=tail;
return tail;
}
C_NODE* C_LIST::get_cursor()
{
return cursor;
}
C_NODE* C_LIST::get_next()
{
if (cursor != NULL)
cursor = cursor->next;
return cursor;
}
C_NODE* C_LIST::get_prev()
{
if (cursor != NULL)
cursor = cursor->prev;
return cursor;
}
int C_LIST::set_mother_class(C_NODE *p_class)
{
GS_ERR_COD=eGSInvClassType;
return GS_BAD;
}
int C_LIST::remove_head()
{
if (head==NULL) return GS_BAD;
if ((cursor=head->next)==NULL) tail=NULL;
else cursor->prev=NULL;
delete head; head=cursor;
count--;return GS_GOOD;
}
int C_LIST::remove_tail()
{
if (tail==NULL) return GS_BAD;
if ((cursor=tail->prev)==NULL) head=NULL;
else cursor->next=NULL;
delete tail; tail=cursor;
count--; return GS_GOOD;
}
int C_LIST::add_head(C_NODE* new_node)
{
if (new_node==NULL) return GS_BAD;
if (count==0) tail=new_node;
else head->prev=new_node;
new_node->next=head; new_node->prev=NULL; head=new_node;
count++; cursor=head; return GS_GOOD;
}
int C_LIST::add_tail(C_NODE* new_node)
{
if (new_node==NULL) return GS_BAD;
if (count==0) head=new_node;
else tail->next=new_node;
new_node->next=NULL; new_node->prev=tail; tail=new_node;
count++; cursor=tail;
return GS_GOOD;
}
int C_LIST::paste_head(C_LIST &new_list)
{
C_NODE *pnode;
int result = GS_GOOD;
if (new_list.is_empty() == TRUE) return GS_GOOD;
while ((pnode = new_list.cut_tail()) != NULL)
if (add_head(pnode)==GS_BAD) { result=GS_BAD; break; }
return result;
}
int C_LIST::paste_tail(C_LIST &new_list)
{
C_NODE *pnode;
int result = GS_GOOD;
if (new_list.is_empty() == TRUE) return GS_GOOD;
while ((pnode = new_list.cut_head()) != NULL)
if (add_tail(pnode)==GS_BAD) { result=GS_BAD; break; }
return result;
}
int C_LIST::remove(C_NODE *punt)
{ // il cursore punterà all'elemento successivo quello cancellato
C_NODE *ptr;
if (!punt) return GS_BAD;
if (punt == head) return remove_head();
if (punt == tail) return remove_tail();
ptr = head;
while (ptr != NULL)
{
if (ptr == punt)
{
cursor=punt->prev->next=punt->next;
punt->next->prev=punt->prev;
count--; delete punt;
return GS_GOOD;
}
ptr = ptr->next;
}
return GS_BAD; // Il nodo non appartiene alla lista
}
int C_LIST::remove_all()
{
while(head!=NULL)
{
cursor=head->next;
delete head;
head=cursor;
}
count=0;
tail=NULL;
return GS_GOOD;
}
C_NODE *C_LIST::getptr_at(int pos) // 1 e' il primo //
{
int i;
if (pos>count || pos<1) return NULL;
if (pos<count/2)
{ cursor=head; for (i=1;i<pos;i++) cursor=cursor->next; }
else
{ cursor=tail; for (i=count;i>pos;i--) cursor=cursor->prev; }
return cursor;
}
int C_LIST::getpos(C_NODE *ptr) // 1 e' il primo //
{ // 0 non trovato //
int cc=0;
cursor=head;
while(cursor!=NULL)
{
cc++;
if (cursor==ptr) return cc;
cursor = cursor->get_next();
}
return 0;
}
int C_LIST::getpos_key(int in) // 1 e' il primo //
{ // 0 non trovato //
int cc=0;
cursor=head;
while(cursor!=NULL)
{
cc++;
if (cursor->get_key()==in) return cc;
cursor = cursor->get_next();
}
return 0;
}
int C_LIST::getpos_name(const char *in, int sensitive) // 1 e' il primo
{ // 0 non trovato
TCHAR *UnicodeString = gsc_CharToUnicode(in);
int res = getpos_name(UnicodeString, sensitive);
if (UnicodeString) free(UnicodeString);
return res;
}
int C_LIST::getpos_name(const TCHAR *in, int sensitive) // 1 e' il primo
{ // 0 non trovato
int cc = 0;
if (!in) return 0;
cursor = head;
while (cursor)
{
cc++;
if (gsc_strcmp(cursor->get_name(), in, sensitive) == 0) return cc;
cursor = cursor->get_next();
}
return 0;
}
int C_LIST::getpos_name2(const char *in) // 1 e' il primo
{ // 0 non trovato
TCHAR *UnicodeString = gsc_CharToUnicode(in);
int res = getpos_name2(UnicodeString);
if (UnicodeString) free(UnicodeString);
return res;
}
int C_LIST::getpos_name2(const TCHAR *in) // 1 e' il primo
{ // 0 non trovato
int cc=0;
if (!in) return 0;
cursor = head;
while (cursor)
{
cc++;
if (gsc_strcmp(cursor->get_name2(), in) == 0) return cc;
cursor = cursor->get_next();
}
return 0;
}
int C_LIST::remove_at(int pos) // 1 e' il primo
{
getptr_at(pos);
return remove_at();
}
// se viene rimosso un elemento il cursore va all'elemento successivo
int C_LIST::remove_at()
{
C_NODE *punt;
if (!cursor) return GS_BAD;
punt = cursor;
if (cursor->prev == NULL) // rimozione in testa
{
head = cursor = punt->next;
if (cursor) cursor->prev = NULL;
else tail = NULL;
}
else
if (cursor->next == NULL) // rimozione in coda
{
tail = punt->prev;
if (tail) tail->next = NULL;
else head = NULL;
cursor = NULL;
}
else
{
cursor = punt->prev->next = punt->next;
punt->next->prev = punt->prev;
}
delete punt;
count--;
return GS_GOOD;
}
int C_LIST::remove_key(int key)
{
C_NODE *punt;
if ((punt=C_LIST::search_key(key))==NULL) return GS_BAD;
return remove(punt);
}
int C_LIST::remove_key(long key)
{
C_NODE *punt;
if ((punt=C_LIST::search_key(key))==NULL) return GS_BAD;
return remove(punt);
}
int C_LIST::remove_name(const char *name, int sensitive)
{
TCHAR *UnicodeString = gsc_CharToUnicode(name);
int res = remove_name(UnicodeString, sensitive);
if (UnicodeString) free(UnicodeString);
return res;
}
int C_LIST::remove_name(const TCHAR *name, int sensitive)
{
C_NODE *punt;
if ((punt = search_name(name, sensitive)) == NULL) return GS_BAD;
return remove(punt);
}
int C_LIST::remove_name2(const char *name)
{
TCHAR *UnicodeString = gsc_CharToUnicode(name);
int res = remove_name2(UnicodeString);
if (UnicodeString) free(UnicodeString);
return res;
}
int C_LIST::remove_name2(const TCHAR *name)
{
C_NODE *punt;
if ((punt = search_name2(name)) == NULL) return GS_BAD;
return remove(punt);
}
int C_LIST::insert_before(int pos, C_NODE* newnod)
{
C_NODE *punt;
if (newnod==NULL) return GS_BAD;
if(pos==1) return add_head(newnod);
if((punt=getptr_at(pos))==NULL) return GS_BAD;
punt->prev->next=newnod; newnod->prev=punt->prev;
punt->prev=newnod; newnod->next=punt;
cursor=newnod; count++; return GS_GOOD;
}
int C_LIST::paste_before(int pos, C_LIST* pNewList)
{
C_NODE *pnode;
int ndx = pos;
if (!pNewList) return GS_BAD;
if (pos == 1) return paste_head(*pNewList);
while ((pnode = pNewList->cut_head()) != NULL)
if (insert_before(ndx++, pnode) == NULL) return GS_BAD;
return GS_GOOD;
}
int C_LIST::insert_before(C_NODE* newnod) // prima del cursore
{
C_NODE *punt;
if (newnod==NULL) return GS_BAD;
if(cursor==NULL) return GS_BAD;
if(cursor->prev==NULL) return add_head(newnod);
punt=cursor;
punt->prev->next=newnod; newnod->prev=punt->prev;
punt->prev=newnod; newnod->next=punt;
cursor=newnod; count++; return GS_GOOD;
}
int C_LIST::insert_after (int pos, C_NODE* newnod)
{
C_NODE *punt;
if (newnod==NULL) return GS_BAD;
if(pos==count) return add_tail(newnod);
if((punt=getptr_at(pos))==NULL) return GS_BAD;
punt->next->prev=newnod; newnod->next=punt->next;
punt->next=newnod; newnod->prev=punt;
cursor=newnod; count++; return GS_GOOD;
}
int C_LIST::insert_after (C_NODE* newnod)
{
C_NODE *punt;
if (newnod==NULL) return GS_BAD;
if(cursor==NULL) return GS_BAD;
if(cursor->next==NULL) return add_tail(newnod);
punt=cursor;
punt->next->prev=newnod; newnod->next=punt->next;
punt->next=newnod; newnod->prev=punt;
cursor=newnod; count++; return GS_GOOD;
}
int C_LIST::insert_ordered(C_NODE *pNewNod, bool *inserted)
{
C_NODE *p = get_head();
int res;
while (p)
{
res = p->comp(pNewNod);
if (res < 0) // p minore di pNewNod
p = get_next();
else if (res == 0) // c'è già
{
*inserted = false;
return GS_GOOD;
}
else // p maggiore di pNewNod
break;
}
*inserted = true;
if (!p)
return add_tail(pNewNod);
else
return insert_before(pNewNod);
}
C_NODE *C_LIST::cut_head()
{
C_NODE *punt;
if (head==NULL) return NULL;
punt=head;
if ((cursor=head->next)==NULL) tail=NULL;
else cursor->prev=NULL;
head=cursor;
count--;return punt;
}
C_NODE *C_LIST::cut_tail()
{
C_NODE *punt;
if (tail==NULL) return NULL;
punt=tail;
if ((cursor=tail->prev)==NULL) head=NULL;
else cursor->next=NULL;
tail=cursor;
count--; return punt;
}
C_NODE *C_LIST::cut_key(int in)
{
search_key(in);
return cut_at();
}
C_NODE *C_LIST::cut_at(void)
{
C_NODE *punt = cursor;
return (cut(cursor) == GS_GOOD) ? punt : NULL;
}
int C_LIST::cut(C_NODE *node)
{
C_NODE *punt;
if ((punt = node) == NULL) return GS_BAD;
if (punt == head) { cut_head(); return GS_GOOD; }
if (punt == tail) { cut_tail(); return GS_GOOD; }
cursor = punt->prev->next=punt->next;
punt->next->prev = punt->prev;
count--;
return GS_GOOD;
}
int C_LIST::move_all(C_LIST *target)
{
if (target==NULL) return GS_BAD;
target->remove_all();
target->head=head; head=NULL;
target->tail=tail; tail=NULL;
target->cursor=cursor; cursor=NULL;
target->count=count; count=0;
return GS_GOOD;
}
C_NODE *C_LIST::search_key(int in)
{
cursor = head;
while (cursor)
{
if (cursor->get_key() == in) break;
get_next();
}
return cursor;
}
C_NODE *C_LIST::search_key(double in)
{
cursor = head;
while (cursor)
{
if (cursor->get_key_double() == in) break;
get_next();
}
return cursor;
}
C_NODE *C_LIST::search_key(long in)
{
cursor = head;
while (cursor)
{
if (cursor->get_id() == in) break;
get_next();
}
return cursor;
}
C_NODE *C_LIST::search_next_key(int in)
{
get_next();
while(cursor!=NULL)
{
if (cursor->get_key()==in) break;
get_next();
}
return cursor;
}
C_NODE *C_LIST::search_type(int in)
{
cursor=head;
while(cursor!=NULL)
{
if (cursor->get_type()==in) break;
get_next();
}
return cursor;
}
C_NODE *C_LIST::search_next_type(int in)
{
get_next();
while(cursor!=NULL)
{
if (cursor->get_type()==in) break;
get_next();
}
return cursor;
}
/*********************************************************/
/*.doc search_name <internal> */
/*+
Questa funzione cerca un elemento nella lista.
Parametri:
const char *in; stringa da cercare
int sensitive; sensibile al maiuscolo (default = TRUE)
Restituisce GS_GOOD in caso di successo altrimenti restituisce GS_BAD.
-*/
/*********************************************************/
C_NODE *C_LIST::search_name(const char *in, int sensitive)
{
TCHAR *UnicodeString = gsc_CharToUnicode(in);
C_NODE *res = search_name(UnicodeString, sensitive);
if (UnicodeString) free(UnicodeString);
return res;
}
C_NODE *C_LIST::search_name(const TCHAR *in, int sensitive)
{
cursor = head;
while (cursor)
{
if (gsc_strcmp(cursor->get_name(), in, sensitive) == 0) break;
get_next();
}
return cursor;
}
C_NODE *C_LIST::search_next_name(const char *in, int sensitive)
{
TCHAR *UnicodeString = gsc_CharToUnicode(in);
C_NODE *res = search_next_name(UnicodeString, sensitive);
if (UnicodeString) free(UnicodeString);
return res;
}
C_NODE *C_LIST::search_next_name(const TCHAR *in, int sensitive)
{
get_next();
while (cursor)
{
if (gsc_strcmp(cursor->get_name(), in, sensitive) == 0) break;
get_next();
}
return cursor;
}
C_NODE *C_LIST::search_name2(const char *in, int sensitive)
{
TCHAR *UnicodeString = gsc_CharToUnicode(in);
C_NODE *res = search_name2(UnicodeString, sensitive);
if (UnicodeString) free(UnicodeString);
return res;
}
C_NODE *C_LIST::search_name2(const TCHAR *in, int sensitive)
{
cursor = head;
while (cursor)
{
if (gsc_strcmp(cursor->get_name2(), in, sensitive) == 0) break;
get_next();
}
return cursor;
}
C_NODE *C_LIST::search_next_name2(const char *in, int sensitive)
{
TCHAR *UnicodeString = gsc_CharToUnicode(in);
C_NODE *res = search_next_name2(UnicodeString, sensitive);
if (UnicodeString) free(UnicodeString);
return res;
}
C_NODE *C_LIST::search_next_name2(const TCHAR *in, int sensitive)
{
get_next();
while (cursor)
{
if (gsc_strcmp(cursor->get_name2(), in, sensitive) == 0) break;
get_next();
}
return cursor;
}
// ricerca la stringa che inizia per ...
C_NODE *C_LIST::search_name2_prefix(const char *in)
{
TCHAR *UnicodeString = gsc_CharToUnicode(in);
C_NODE *res = search_name2_prefix(UnicodeString);
if (UnicodeString) free(UnicodeString);
return res;
}
C_NODE *C_LIST::search_name2_prefix(const TCHAR *in)
{
cursor = head;
while (cursor)
{
if (wcsstr(cursor->get_name2(), in) == cursor->get_name2()) break;
get_next();
}
return cursor;
}
C_NODE *C_LIST::search_category(int in)
{
cursor=head;
while(cursor!=NULL)
{
if (cursor->get_category()==in) break;
get_next();
}
return cursor;
}
C_NODE *C_LIST::search_next_category(int in)
{
get_next();
while(cursor!=NULL)
{
if (cursor->get_category()==in) break;
get_next();
}
return cursor;
}
int C_LIST::print_list()
{
C_NODE *punt;
int i=1;
acutPrintf(_T("LEN : %d\n"), count);
punt = head;
while(punt!=NULL)
{
acutPrintf(_T("%d->\t%d\t%d\t%s"), i,
punt->get_key(), punt->get_type(), punt->get_name());
if(punt==head) acutPrintf(_T(" HEAD"));
if(punt==tail) acutPrintf(_T(" TAIL"));
if(punt==cursor) acutPrintf(_T(" CURS"));
acutPrintf(GS_LFSTR);
punt=punt->next;i++;
}
return GS_GOOD;
}
C_NODE *C_LIST::goto_pos(int in) // 1 e' il primo
{
int i = 1;
if (in > count || in == 0) return NULL;
cursor = head;
while (cursor && i < in)
{
get_next();
i++;
}
return cursor;
}
// questa funzione è estremamente pericolosa perchè si fida che ptr
// sia il puntatore di un elemento della C_LIST corrente
int C_LIST::set_cursor(C_NODE *ptr)
{
cursor = ptr;
return GS_GOOD;
}
/*********************************************************/
/*.doc C_LIST::sort <external> */
/*+
Questa funzione ordina una lista C_LIST o derivate in base alla
funzione fCompPtr impostato per la lista.
Parametri:
int ascending; se = TRUE ordina in modo crescente (default = TRUE)
Restituisce GS_GOOD in caso di successo altrimenti restituisce GS_BAD.
-*/
/*********************************************************/
void C_LIST::sort(void)
{
bool stop = false;
int i, j = 0;
C_NODE *p_item1, *p_item2, *p_next;
if (!head || !fCompPtr) return;
while (!stop)
{
stop = true;
i = 1;
p_item1 = head;
p_item2 = p_item1->next;
while (p_item2 && i < count - j)
{
if ((*fCompPtr)(p_item1, p_item2) > 0) // richiamo la funzione di comparazione
{ // inverto la posizione dei 2 C_NODE
stop = false;
// precedente di p_item1
p_item2->prev = p_item1->prev;
p_next = p_item2->next;
p_item2->next = p_item1;
// successivo di p_item2
p_item1->next = p_next;
p_item1->prev = p_item2;
if (p_item1->next) p_item1->next->prev = p_item1; // collego l'elemento successivo
else tail = p_item1; // non c'era il successivo quindi è in coda
if (p_item2->prev) p_item2->prev->next = p_item2; // collego l'elemento precedente
else head = p_item2; // non c'era il precedente quindi è in testa
}
else p_item1 = p_item2;
p_item2 = p_item1->next;
i++;
}
j++;
}
}
int CALLBACK gsc_C_NODE_compare_by_name_asc_sensitive(C_NODE *p1, C_NODE *p2)
{ return gsc_strcmp(p1->get_name(), p2->get_name(), TRUE); }
int CALLBACK gsc_C_NODE_compare_by_name_asc_insensitive(C_NODE *p1, C_NODE *p2)
{ return gsc_strcmp(p1->get_name(), p2->get_name(), FALSE); }
int CALLBACK gsc_C_NODE_compare_by_name_desc_sensitive(C_NODE *p1, C_NODE *p2)
{ return gsc_strcmp(p1->get_name(), p2->get_name(), TRUE); }
int CALLBACK gsc_C_NODE_compare_by_name_desc_insensitive(C_NODE *p1, C_NODE *p2)
{ return gsc_strcmp(p1->get_name(), p2->get_name(), FALSE); }
int CALLBACK gsc_C_NODE_compare_by_key_asc(C_NODE *p1, C_NODE *p2)
{
if (p1->get_key() == p2->get_key())
return 0;
else
return (p1->get_key() > p2->get_key()) ? 1 : -1;
}
int CALLBACK gsc_C_NODE_compare_by_key_desc(C_NODE *p1, C_NODE *p2)
{ return gsc_C_NODE_compare_by_key_asc(p2, p1); }
int CALLBACK gsc_C_REAL_compare_by_key_asc(C_NODE *p1, C_NODE *p2)
{
double n1 = ((C_REAL *) p1)->get_key_double();
double n2 = ((C_REAL *) p2)->get_key_double();
if (n1 == n2)
return 0;
else
return (n1 > n2) ? 1 : -1;
}
int CALLBACK gsc_C_REAL_compare_by_key_desc(C_NODE *p1, C_NODE *p2)
{ return gsc_C_REAL_compare_by_key_asc(p2, p1); }
int CALLBACK gsc_C_NODE_compare_by_nameAsNum_asc(C_NODE *p1, C_NODE *p2)
{
double n1 = (p1->get_name()) ? _wtof(p1->get_name()) : 0;
double n2 = (p2->get_name()) ? _wtof(p2->get_name()) : 0;
if (n1 == n2)