File: pntrvctr.web

package info (click to toggle)
3dldf 2.0.3%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 12,508 kB
  • ctags: 7
  • sloc: makefile: 892; sh: 117; cpp: 5
file content (1490 lines) | stat: -rw-r--r-- 33,286 bytes parent folder | download | duplicates (2)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
@q pntrvctr.web @>

@q * Copyright and License.@>

@q This file is part of GNU 3DLDF, a package for three-dimensional drawing. @>
@q Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, @>
@q 2011, 2012, 2013 The Free Software Foundation  @>

@q GNU 3DLDF is free software; you can redistribute it and/or modify @>
@q it under the terms of the GNU General Public License as published by @>
@q the Free Software Foundation; either version 3 of the License, or @>
@q (at your option) any later version. @>

@q GNU 3DLDF is distributed in the hope that it will be useful, @>
@q but WITHOUT ANY WARRANTY; without even the implied warranty of @>
@q MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the @>
@q GNU General Public License for more details. @>

@q You should have received a copy of the GNU General Public License @>
@q along with GNU 3DLDF; if not, write to the Free Software @>
@q Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA @>

@q GNU 3DLDF is a GNU package.  @>
@q It is part of the GNU Project of the  @>
@q Free Software Foundation @>
@q and is published under the GNU General Public License. @>
@q See the website http://www.gnu.org @>
@q for more information.   @>
@q GNU 3DLDF is available for downloading from @>
@q http://www.gnu.org/software/3dldf/LDF.html. @>

@q (``@@'' stands for a single at-sign in the following paragraph.) @>

@q Please send bug reports to Laurence.Finston@@gmx.de @>
@q The mailing list help-3dldf@@gnu.org is available for people to @>
@q ask other users for help.  @>
@q The mailing list info-3dldf@@gnu.org is for sending @>
@q announcements to users. To subscribe to these mailing lists, send an @>
@q email with ``subscribe <email-address>'' as the subject.  @>

@q The author can be contacted at: @>

@q Laurence D. Finston                 @> 
@q c/o Free Software Foundation, Inc.  @>
@q 51 Franklin St, Fifth Floor         @> 
@q Boston, MA  02110-1301              @>
@q USA                                 @>

@q Laurence.Finston@@gmx.de (@@ stands for a single ``at'' sign.)@>


@q * (0) |struct Pointer_Vector|.@>
@** {\bf struct Pointer\_Vector}\quad ({\tt pntrvctr\PERIOD web}).\hfil

\LOG
\initials{LDF 2005.11.12.}
Created this file.  It contains code for |struct Pointer_Vector| and its functions, 
which I've removed from \filename{pspglb.web}.  The use of |Scanner_Type| objects 
in functions caused compilation to fail on a user's system using GCC 3.4.3.
\ENDLOG

\immediate\write\functexifile{File:  pntrvctr.web^^J}

@q * (1) Include files.@>
@* Include files.

@<Include files@>=
#include "loader.h++"
#include "pspglb.h++"
#include "io.h++"

@q * (1) Template |struct Pointer_Vector|.@>
@*1 Template {\bf struct Pointer\_Vector}.  

The template parameter for a |Pointer_Vector| must be a class that 
defines a member function |show(string)|.
\initials{LDF 2004.08.25.}

\LOG
\initials{LDF 2004.08.25.}
Added this |struct| definition.

\initials{LDF 2005.02.28.}
Added the optional template parameter |class D| 
with default |class C|.
\ENDLOG 

@<Utility classes@>=

template<class C, class D>
struct
Pointer_Vector
{
    vector<C*> v;

    int ctr; /* counter  */

    @<Declare |Pointer_Vector| functions@>@;


};


@q ** (2) |struct Pointer_Vector| functions.@>
@*1 |struct Pointer_Vector| functions.

\LOG
\initials{LDF 2004.08.25.}
Added this section.
\ENDLOG 

@q *** (3) Constructors.@>
@*2 Constructors.

\LOG
\initials{LDF 2004.08.26.}
Added this section.
\ENDLOG 

@q **** (4) Default constructor.@>
@*3 Default constructor.

\LOG
\initials{LDF 2004.08.26.}
Removed this definition from the |struct Pointer_Vector| 
declaration. 
\ENDLOG 

@<Declare |Pointer_Vector| functions@>=
Pointer_Vector(void);

@
@<Define |Pointer_Vector| functions@>=
template <class C, class D>
Pointer_Vector<C, D>::Pointer_Vector(void) : ctr(0)
{
    return;
}


@q *** (3) Destructor.  @>
@*2 Destructor.

\LOG
\initials{LDF 2004.09.24.}
Added this function.  
It should fix some memory leaks.
\ENDLOG

@<Declare |Pointer_Vector| functions@>=
~Pointer_Vector(void);

@
@<Define |Pointer_Vector| functions@>=
template <class C, class D>
Pointer_Vector<C, D>::~Pointer_Vector(void)
{
   for (typename vector<C*>::iterator iter = v.begin();
        iter != v.end();
        iter++)
      {
          delete *iter;
          *iter = 0;
      }

   v.clear();

}  /* End of |~Pointer_Vector| definition.  */

@q *** (3) Operators.@>
@*2 Operators.

\LOG
\initials{LDF 2004.09.29.}
Added this section.
\ENDLOG

@q **** (4) Assignment.@>
@*3 Assignment.

\LOG
\initials{LDF 2004.11.05.}
Added this function.
\ENDLOG


@q ***** (5) Assignment from a |Pointer_Vector<C, D>|.@> 
@*4 Assignment from a {\bf Pointer\_Vector<C, D>}.
\initials{LDF 2005.04.01.}

\LOG
\initials{LDF 2005.04.01.}
Added this function.
\ENDLOG

@q ****** (6) Declaration.@> 

@<Declare |Pointer_Vector| functions@>=
const Pointer_Vector<C, D>&
operator=(const Pointer_Vector<C, D>& p);

@q ****** (6) Definition.@> 

@
@<Define |Pointer_Vector| functions@>=
template <class C, class D>
const Pointer_Vector<C, D>&
Pointer_Vector<C, D>::operator=(const Pointer_Vector<C, D>& p)
{

   if (this == &p)  /* Prevent self-assignment.  
                       \initials{LDF 2004.11.05.}  */
      return p;

   if (p.ctr <= 0)
      {
         clear();
         return p;
      }

   C* c;

@q ******* (7) Destroy excess pointers on |v|, if necessary.@>

@ Destroy excess pointers on |v|, if necessary.
\initials{LDF 2004.11.05.}

@<Define |Pointer_Vector| functions@>=

   while (ctr > p.ctr)
      {
         c = v.back();
         delete c;
         v.pop_back(); 
         --ctr;
      } /* |while|  */

@q ******* (7) Add pointers to |v|, if necessary.@>

@ Add pointers to |v|, if necessary.
\initials{LDF 2004.11.05.}

@<Define |Pointer_Vector| functions@>=

   try 
      {

          while (ctr < p.ctr)
             {
                 c = new C;
                 v.push_back(c);
                 ++ctr;           
 
             } /* |while|  */

      } /* |try|  */


@q ******** (8) Error handling:  |new C| failed.@> 

@ Error handling:  |new C| failed.
\initials{LDF 2004.11.05.}

@<Define |Pointer_Vector| functions@>=

   catch (bad_alloc)
       {

           string thread_name = "";

#ifdef HAVE_PTHREAD_H

           Thread_Info_Type* thread_info = Thread_Info_Type::get_thread_info();
  
           thread_name = Thread_Info_Type::get_thread_name(thread_info);

#endif /* |HAVE_PTHREAD_H|  */@; 


           cerr_mutex.lock(); 
           cerr << thread_name 
                << "ERROR! In `Pointer_Vector<C, D>::operator=()':"
                << endl << "`new C' failed. "
                << "Rethrowing `bad_alloc'."
                << endl << "Type <RETURN> to continue: ";
           getchar();
           cerr_mutex.unlock();

           throw;

       }  /* |catch (bad_alloc)|  */



@q ******* (7) Assign to the dereferenced elements of |v| @> 
@q ******* (7) from the dereferenced elements of |p.v|    @> 
@q ******* (7) and exit, returning |p|.                   @>                 

@ Assign to the dereferenced elements of |v| 
from the dereferenced elements of |p.v| and exit, 
returning |p|.  
\initials{LDF 2004.11.05.} 

@<Define |Pointer_Vector| functions@>=

   for (int i = 0; i < ctr; ++i)
      {

         /* !! START HERE.  Check precedence of operators.  
            LDF 2004.11.05. */ 

         *v[i]  = *(p.v[i]);

      } /* |for|  */

   return p;
      
}  /* End of |Pointer_Vector<C, D>::operator=| definition.  */

@q ***** (5) Assignment from a |vector<D>&|.@> 
@*4 Assignment from a {\bf vector<D>\AMP}.
\initials{LDF 2005.04.01.}

\LOG
\initials{LDF 2005.04.01.}
Added this function.

\initials{LDF 2007.10.14.}
@:BUG FIX@> BUG FIX:  Now calling |Pointer_Vector<C, D>::clear|.
\ENDLOG

@q ******* (7) Declaration.@> 

@<Declare |Pointer_Vector| functions@>=
const Pointer_Vector<C, D>&
operator=(const vector<D>& v);

@q ******* (7) Definition.@> 

@
@<Define |Pointer_Vector| functions@>=
template <class C, class D>
const Pointer_Vector<C, D>&
Pointer_Vector<C, D>::operator=(const vector<D>& v)
{

   clear();

   D* d;

   for(typename vector<C>::const_iterator iter = v.begin();
       iter != v.end();
       ++iter)
      {
         d = new D;

         *d = *iter;

         operator+=(d);         
      }

   return *this;
}

@q ***** (5) Assign using same pointers.@> 
@*4 Assign using same pointers.
\initials{LDF 2005.04.13.}

\LOG
\initials{LDF 2005.04.13.}
Added this function.

\initials{LDF 2005.04.13.}
Added optional |Pointer_Vector<C, C>*| argument with default 0.
If it's passed to this function, the pointers are 
cast and pushed onto it.
\ENDLOG

@q ****** (6) Declaration.@> 

@<Declare |Pointer_Vector| functions@>=
static
Pointer_Vector<C, C>*
assign_same_pointers(Pointer_Vector<D, D>* d,
                     Pointer_Vector<C, C>* c = 0,  
                     Scanner_Node scanner_node = 0);

@q ****** (6) Definition.@> 

@
@<Define |Pointer_Vector| functions@>=
template <class C, class D>
Pointer_Vector<C, C>* 
Pointer_Vector<C, D>::assign_same_pointers(Pointer_Vector<D, D>* d, 
                                           Pointer_Vector<C, C>* c,  
                                           Scanner_Node scanner_node)
{

@q ******* (7) Preliminaries.@>   

#if DEBUG_COMPILE
   bool DEBUG = false; /* |true| */ @; 
#endif /* |DEBUG_COMPILE|  */@; 

   stringstream cerr_strm;

   bool error_stop_value   = true;
   bool warning_stop_value = true;
   string thread_name      = "";

   if (scanner_node)
      scanner_node->get_thread_name_and_stop_values(&thread_name,
                                                    &error_stop_value,
                                                    &warning_stop_value);

   using namespace Scan_Parse;

@q ******* (7).@>

   Pointer_Vector<C>* pvc;

   if (c == static_cast<Pointer_Vector<C, C>*>(0))
     pvc = new Pointer_Vector<C>; 
   else 
     pvc = c;

   if (pvc->ctr > 0)
      pvc->clear();

   pvc->ctr = d->ctr;

   for (typename vector<D*>::iterator iter = d->v.begin();
        iter != d->v.end();
        ++iter)
      {
         pvc->v.push_back(reinterpret_cast<C*>(*iter));
      }
   

@q ******* (7).@>

    return pvc;
      

@q ******* (7) @> 

}  /* End of |Pointer_Vector<C, D>::assign_same_pointers|
      definition.  */


@q ***** (5) Addition with assignment.@>
@*4 Addition with assignment.

@q ****** (6) |C*| argument.@> 
@*5 {\bf C*} argument.
\initials{LDF 2004.09.29.}

\LOG
\initials{LDF 2004.09.29.}
Added this function.

\initials{LDF 2005.02.28.}
Changed the type of the argument from |C*| to |D*|. 
Now casting it to |C*|.
Changed the return type to |void|.
\ENDLOG

@q ******* (7) Declaration.@> 

@<Declare |Pointer_Vector| functions@>=
void
operator+=(D* d);

@q ******* (7) Definition.@> 

@
@<Define |Pointer_Vector| functions@>=
template <class C, class D>
void
Pointer_Vector<C, D>::operator+=(D* d)
    {
        C* c = static_cast<C*>(d);
        v.push_back(c);
        ctr++;
        return;
    }   

@q ***** (5) Assignment from a |vector<D>&| with addition.@> 
@*4 Assignment from a {\bf vector<D>\AMP} with addition.
\initials{LDF 2007.10.14.}

\LOG
\initials{LDF 2007.10.14.}
Added this function.
\ENDLOG

@q ******* (7) Declaration.@> 

@<Declare |Pointer_Vector| functions@>=
void
operator+=(const vector<D>& v);

@q ******* (7) Definition.@> 

@
@<Define |Pointer_Vector| functions@>=
template <class C, class D>
void
Pointer_Vector<C, D>::operator+=(const vector<D>& v)
{

   D* d;

   for(typename vector<C>::const_iterator iter = v.begin();
       iter != v.end();
       ++iter)
      {
         d = new D;

         *d = *iter;

         operator+=(d);         
      }

   return;

}

@q ****** (6) |const Pointer_Vector<D>&| argument.@> 
@*5 {\bf const Pointer\_Vector\<D>\AMP} argument.
\initials{LDF 2005.02.28.}

\LOG
\initials{LDF 2005.02.28.}
Added this function.
\ENDLOG

@q ******* (7) Declaration.@> 

@<Declare |Pointer_Vector| functions@>=
void
operator+=(const Pointer_Vector<D>& d);

@q ******* (7) Definition.@> 

@
@<Define |Pointer_Vector| functions@>=
template <class C, class D>
void
Pointer_Vector<C, D>::operator+=(const Pointer_Vector<D>& d)
{
    for (typename vector<D*>::const_iterator iter = d.v.begin();
         iter != d.v.end();
         ++iter)
       {
           operator+=(static_cast<C*>(*iter));
           ctr++;
       }
}   



@q *** (3) Append copy.@>
@*2 Append copy.
\initials{LDF 2005.02.26.}

@q ***** (5) |const D*| argument.@> 
@*4 {\bf const D*} argument.
\initials{LDF 2005.02.26.}

\LOG
\initials{LDF 2005.02.26.}
Added this function.

\initials{LDF 2005.02.28.}
Changed the type of the first argument from |const C*| 
to |const D*|.  Now casting it to |const C*|.
Changed the return type to int.
\ENDLOG

@q ****** (6) Declaration.@> 

@<Declare |Pointer_Vector| functions@>=
int
append_copy(const D* d, Scanner_Node scanner_node = 0);

@q ****** (6) Definition.@> 

@
@<Define |Pointer_Vector| functions@>=
template <class C, class D>
int
Pointer_Vector<C, D>::append_copy(const D* d, Scanner_Node scanner_node)
{

@q ******* (7) Preliminaries.@>   

#if DEBUG_COMPILE
   bool DEBUG = false; /* |true| */ @; 
#endif /* |DEBUG_COMPILE|  */@; 

   stringstream cerr_strm;

   bool error_stop_value   = true;
   bool warning_stop_value = true;
   string thread_name      = "";

   if (scanner_node)
      scanner_node->get_thread_name_and_stop_values(&thread_name,
                                                    &error_stop_value,
                                                    &warning_stop_value);

   using namespace Scan_Parse;

@q ******* (7).@>

    C* c;
   
    try          
       {
           c = new C;
       }
    
    catch (bad_alloc)
       {
           cerr_strm << thread_name 
                     << "ERROR!  In `Pointer_Vector<C, D>::append_copy':"
                     << endl 
                     << "`new C' failed, throwing `bad_alloc'.  "
                     << "Rethrowing.";

           log_message(cerr_strm);
           cerr_message(cerr_strm, error_stop_value);
           cerr_strm.str("");

           throw;

       }  /* |catch (bad_alloc)|  */

    *c = *(static_cast<const C*>(d));     
 
    operator+=(c);

    return 0;

@q ******* (7) @> 

}  /* End of |Pointer_Vector<C, D>::append_copy(const C* c)|
      definition.  */


@q ***** (5) |const Pointer_Vector<D>&| argument.@> 
@*4 {\bf const Pointer\_Vector<D>\AMP} argument.
\initials{LDF 2005.02.28.}

\LOG
\initials{LDF 2005.02.28.}
Added this function.
\ENDLOG

@q ****** (6) Declaration.@> 

@<Declare |Pointer_Vector| functions@>=
int
append_copy(const Pointer_Vector<D>& d, Scanner_Node scanner_node = 0);

@q ****** (6) Definition.@> 

@
@<Define |Pointer_Vector| functions@>=
template <class C, class D>
int
Pointer_Vector<C, D>::append_copy(const Pointer_Vector<D>& d, 
                                  Scanner_Node scanner_node)
{

@q ******* (7) Preliminaries.@>   

#if DEBUG_COMPILE
   bool DEBUG = false; /* |true| */ @; 
#endif /* |DEBUG_COMPILE|  */@; 

   stringstream cerr_strm;

   bool error_stop_value   = true;
   bool warning_stop_value = true;
   string thread_name      = "";

   if (scanner_node)
      scanner_node->get_thread_name_and_stop_values(&thread_name,
                                                    &error_stop_value,
                                                    &warning_stop_value);

   using namespace Scan_Parse;

@q ******* (7).@>


   try          
      {

@q ******** (8).@>

          for (typename vector<D*>::const_iterator iter = d.v.begin();
               iter != d.v.end();
               ++iter)
             {
                 append_copy(*iter, scanner_node);

             }  /* |for| */

@q ******** (8).@>

      }  /* |try|  */

@q ******* (7) @> 

   catch (bad_alloc)
      {
          cerr_strm << thread_name 
                    << "ERROR!  In `Pointer_Vector<C, D>::append_copy("
                    << "const Pointer_Vector<D>&, Scanner_Node)':"
                    << endl 
                    << "`Pointer_Vector<C, D>::append_copy(const D*, Scanner_Node)' "
                    << "failed, throwing `bad_alloc'.  "
                    << "Rethrowing.";

          log_message(cerr_strm);
          cerr_message(cerr_strm, error_stop_value);
          cerr_strm.str("");

          throw;

      }  /* |catch (bad_alloc)|  */


@q ******* (7) @> 

    return 0;
      

@q ******* (7) @> 

}  /* End of |Pointer_Vector<C, D>::append_copy(const C* c)|
      definition.  */



@q *** (3) Convert pair pointer.@> 
@*2 Convert pair pointer.
\initials{LDF 2005.10.27.}

\LOG
\initials{LDF 2005.10.27.}
Added this function.
\ENDLOG

@q ***** (5) Declaration.@>

@<Declare |Pointer_Vector| functions@>=
int
convert_pair_pointer(pair<C, C>* p, bool delete_pair = true);

@q ***** (5) Definition.@>
@
@<Define |Pointer_Vector| functions@>=
template <class C, class D>
int
Pointer_Vector<C, D>::convert_pair_pointer(pair<C, C>* p, bool delete_pair)
{
   if (!p)
      return 1;

   clear();
   v.push_back(new C);
   v.push_back(new C);
   *(v[0]) = p->first;
   *(v[1]) = p->second;
   ctr = 2;

   if (delete_pair)
      {
         delete p;
         p = 0;
      }

   return 0;
}

@q *** (3) Pop back.@>   
@*2 Pop back.
\initials{LDF 2005.02.28.}

\LOG
\initials{LDF 2005.02.28.}
Added this function.
\ENDLOG

@<Declare |Pointer_Vector| functions@>=
int
pop_back(bool delete_pointer = false);

@
@<Define |Pointer_Vector| functions@>=
template <class C, class D>
int
Pointer_Vector<C, D>::pop_back(bool delete_pointer)
{

   if (delete_pointer)
      delete v.back();

   v.pop_back();

   return 0;

}  /* End of |template <class C, class D> int
              Pointer_Vector<C, D>::pop_back(bool delete_pointer)|
      definition.  */


@q *** (3) Predicates.@> 
@*2 Predicates.
\initials{LDF 2007.07.22.}

\LOG
\initials{LDF 2007.07.22.}
Added this section.
\ENDLOG


@q **** (4) Are Distinct.@> 
@*3 Are Distinct.
\initials{LDF 2007.07.22.}

If the |real tolerance| argument is $< 0$, 
the |real factor| argument can be used to multiply the default 
value used for the tolerance in a given type's version of 
|is_equal|.  This is needed in the case of |Point|, because the value
returned by |Point::epsilon| is too small for use when comparing 
|Points|.  See the discussion of this in the log for
|Point::operator==| in \filename{points.web}.
\initials{LDF 2007.07.22.}

\LOG
\initials{LDF 2007.07.22.}
Added this function.
\ENDLOG

@q ***** (5) Declaration.@> 

@<Declare |Pointer_Vector| functions@>=
bool
are_distinct(real tolerance = -1, real factor = 1, void* parameter = 0);


@q ***** (5) Definition.@> 
@
@<Define |Pointer_Vector| functions@>=
template <class C, class D>
bool
Pointer_Vector<C, D>::are_distinct(real tolerance, 
                                   real factor, 
                                   void* parameter)
{

@q ****** (6) Preliminaries.@>   

#if DEBUG_COMPILE
   bool DEBUG = false; /* |true| */ @; 
#endif /* |DEBUG_COMPILE|  */@; 

   stringstream cerr_strm;

   bool error_stop_value   = true;
   bool warning_stop_value = true;
   string thread_name      = "";

   Scanner_Node scanner_node = static_cast<Scanner_Node>(parameter);

   if (scanner_node)
      scanner_node->get_thread_name_and_stop_values(&thread_name,
                                                    &error_stop_value,
                                                    &warning_stop_value);

   using namespace Scan_Parse;

@q ****** (6)@> 

   int i;
   int j;

   size_t size = v.size();

   if (tolerance < 0)
      tolerance = C::epsilon() * factor;

   for (i = 0; i < size - 1; ++i)
   {
       for (j = i + 1; j < size; ++j)
       {
           if (v[i]->is_equal(*v[j], tolerance, parameter))
              return false;
       }
   } 

   return true;

}  /* End of |Pointer_Vector<C, D>::are_distinct| definition.  */

@q *** (3) Conversion.@>   
@*3 Conversion.
\initials{LDF 2005.04.11.}

\LOG
\initials{LDF 2005.04.11.}
Added this function.  I wasn't able to define a version of |operator=| 
to do the job.
It was necessary to use |reinterpret_cast| 
because |static_cast| failed when I tried to convert a 
|Pointer_Vector<Shape>*| to a |Pointer_Vector<Polygon>*|.

\initials{LDF 2005.04.11.}
@:BUG FIX@> BUG FIX:  Now returning 0 if |d == 0 || d->ctr == 0|.

\initials{LDF 2005.04.14.}
@:BUG FIX@> BUG FIX:  Now incrementing |c->ctr|.


\initials{LDF 2013.11.10.}
@:BUG FIX@> BUG FIX:  Now explicitly resizing |c->v| with |static_cast<C*>(0)|
as the value.  Previously, |operator+=| was called to push the pointers onto 
|c->v|.  Now, the existing NULL values are replaced.
\par
I don't think this should be necessary:  The older code worked with GCC 4.6.2, 
but it caused a compilation error with GCC 4.8.2:  Apparently, |vector::resize| 
was called with |Shape| instead of |Shape *| as the value type, which didn't work,
because |Shape| is an abstract class.
\par
In addition, I've had to change the type of derivation of |Path| from |Shape| from
|protected| to |public|.
\ENDLOG

@q ***** (5) Declaration.@> 

@<Declare |Pointer_Vector| functions@>=
static
Pointer_Vector<C, C>* 
convert(Pointer_Vector<D, D>* d); 

@q ***** (5) Definition.@> 

@
@<Define |Pointer_Vector| functions@>=
template <class C, class D>
Pointer_Vector<C, C>* 
Pointer_Vector<C, D>::convert(Pointer_Vector<D, D>* d)
{
   if (   d == static_cast<Pointer_Vector<D, D>*>(0) 
       || d->ctr == 0)
      return 0;
   
   Pointer_Vector<C, C>* c = new Pointer_Vector<C, C>;

   c->v.resize(d->v.size(), static_cast<C*>(0));

   int i = 0;
 
   for (typename vector<D*>::iterator iter = d->v.begin();
        iter != d->v.end();
        ++iter)
      {
          c->v[i] = static_cast<C*>(*iter);

          ++(c->ctr);
      }

   d->clear(false);

   delete d;
   d = 0;

   return c;

}   /* End of |Pointer_Vector<C, D>::convert(Pointer_Vector<D, D>*& d)|
       definition.  */



@q *** (3) Clear.@>
@*2 Clear.
\initials{LDF 2004.10.01.}

\LOG
\initials{LDF 2004.10.01.}
Added this function.

\initials{LDF 2005.02.26.}
Added optional |bool delete_pointers| argument with default |true|.
\ENDLOG

@<Declare |Pointer_Vector| functions@>=
int
clear(bool delete_pointers = true);

@
@<Define |Pointer_Vector| functions@>=
template <class C, class D>
int
Pointer_Vector<C, D>::clear(bool delete_pointers)
{

    ctr = 0;

    if (delete_pointers)
       {
           for (typename vector<C*>::iterator iter = v.begin();
                iter != v.end();
                iter++)
              {
                  delete *iter;
                  *iter = 0;

              } /* |for|  */  

       }  /* |if (delete_pointers)|  */

    v.clear();
        
}  /* End of |Pointer_Vector<C, D>::clear| definition. */


@q *** (3) Cull.@>
@*2 Cull.
\initials{LDF 2007.07.22.}

@q **** (4) Non-|const| version.@> 
@*3 Non-{\bf const} version.
@^\cfunc{Pointer\_Vector}{cull}@>
\cfunctexi{Pointer\_Vector}{cull}
\initials{LDF 2007.07.22.}

This function requires the existence of a function |C::is_equal|.  Currently,
this function only exists for |class Point|.
\initials{LDF 2007.07.27.}

\LOG
\initials{LDF 2007.07.22.}
Added this function.
\ENDLOG

@q ***** (5) Declaration.@> 

@<Declare |Pointer_Vector| functions@>=
int
cull(const unsigned short comparison = Sorting::SORTING_EQUAL,
     real tolerance = -1,
     Scanner_Node scanner_node = 0,
     C* c = 0);


@q ***** (5) Definition.@> 
@
@<Define |Pointer_Vector| functions@>=
template <class C, class D>
int
Pointer_Vector<C, D>::cull(const unsigned short comparison,
                           real tolerance,
                           Scanner_Node scanner_node, 
                           C* c)
{
 
@q ****** (6) Preliminaries.@>   

#if DEBUG_COMPILE
   bool DEBUG = false; /* |true| */ @; 
#endif /* |DEBUG_COMPILE|  */@; 

   stringstream cerr_strm;

   bool error_stop_value   = true;
   bool warning_stop_value = true;
   string thread_name      = "";

   if (scanner_node)
      scanner_node->get_thread_name_and_stop_values(&thread_name,
                                                    &error_stop_value,
                                                    &warning_stop_value);

   using namespace Scan_Parse;

@q ****** (6)@> 

#if DEBUG_COMPILE
   if (DEBUG)
   {
       cerr_strm << thread_name 
                 << "Entering `Pointer_Vector::cull'.";

       log_message(cerr_strm);
       cerr_message(cerr_strm);
       cerr_strm.str("");

   }  /* |if (DEBUG)|  */

#endif /* |DEBUG_COMPILE|  */@; 

@q ****** (6)@> 

    if (comparison == Sorting::SORTING_EQUAL)
    {  

        vector<C*> temp_vector = v;

        v.clear();
        ctr = 0;

        typename vector<C*>::iterator i;
        typename vector<C*>::const_iterator i_end = temp_vector.end();
        --i_end;

        typename vector<C*>::iterator j;

        int i_ctr = 0; 
        int j_ctr = 0; 


@q ******* (7)@> 

        for (i = temp_vector.begin(); i != i_end; ++i)
        {

             j_ctr = i_ctr + 1;
             
             j = i;
             ++j;

             if (*i == static_cast<C*>(0))
             {
                ++i_ctr;
                continue;
             }

             else
             {
                v.push_back(*i);
                ++ctr;

             }  /* |else|  */


@q ******** (8)@> 

             for (;j != temp_vector.end(); ++j)
             {
                if (*j == static_cast<C*>(0))
                ;
                else if ((**i).is_equal(**j, tolerance))
                {
                   delete temp_vector[j_ctr];
                   temp_vector[j_ctr] = 0;                
                }
                
                ++j_ctr;

             }  /* inner |for|  */

@q ******** (8)@>         
             
             ++i_ctr;


        }  /* outer |for|  */

@q ******* (7)@> 

   if (temp_vector.back() != static_cast<C*>(0))
   {
       v.push_back(temp_vector.back());
       ++ctr;
   }

@q ******* (7)@> 

    }  /* |if (comparison == Sorting::SORTING_EQUAL)|  */ 


@q ****** (6)@> 

#if DEBUG_COMPILE
   if (DEBUG)
   {
       cerr_strm << thread_name 
                 << "Exiting `Pointer_Vector::cull' "
                 << "successfully with return value 0.";

       log_message(cerr_strm);
       cerr_message(cerr_strm);
       cerr_strm.str("");

   }  /* |if (DEBUG)|  */

#endif /* |DEBUG_COMPILE|  */@; 

    return 0;

}  /* End of |Pointer_Vector<C, D>::cull| definition 
      (non-|const| version).  */

@q **** (4) |const| version.@> 
@*3 {\bf const} version.
@^\cfunc{Pointer\_Vector}{cull}@>
\cfunctexi{Pointer\_Vector}{cull}
\initials{LDF 2007.07.22.}

\LOG
\initials{LDF 2007.07.22.}
Added this function.
\ENDLOG

@q ***** (5) Declaration.@> 

@<Declare |Pointer_Vector| functions@>=
Pointer_Vector<C, D>*
cull(const unsigned short comparison = Sorting::SORTING_EQUAL,
     real tolerance = -1,
     Scanner_Node scanner_node = 0,
     C* c = 0) const;



@q ***** (5) Definition.@> 
@
@<Define |Pointer_Vector| functions@>=
template <class C, class D>
Pointer_Vector<C, D>*
Pointer_Vector<C, D>::cull(const unsigned short comparison,
                           real tolerance,  
                           Scanner_Node scanner_node,
                           C* c) const      
{

    /* START HERE!!  LDF 2007.07.22.  */ 

    return 0;

}  /* End of |Pointer_Vector<C, D>::cull| definition (|const| version).  */



@q *** (3) Reverse.@>
@*2 Reverse.
\initials{LDF 2007.08.14.}

\LOG
\initials{LDF 2007.08.14.}
Added this function.
\ENDLOG

@q **** (4) Declaration.@> 

@<Declare |Pointer_Vector| functions@>=
int 
reverse(Scanner_Node scanner_node = 0);

@q **** (4) Definition.@> 
@
@<Define |Pointer_Vector| functions@>=
template <class C, class D>
int 
Pointer_Vector<C, D>::reverse(Scanner_Node scanner_node)
{
   std::reverse(v.begin(), v.end());
   return 0;

}  /* End of |Pointer_Vector<C, D>::reverse| definition.  */

@q *** (3) Show.@>
@*2 Show.

The template parameter for a |Pointer_Vector| must be a class that 
defines a member function |show(string)|.
\initials{LDF 2004.08.25.}

\LOG
\initials{LDF 2004.08.25.}
Added this function.

\initials{LDF 2004.08.26.}
Minor additions.

\initials{LDF 2007.07.27.}
Added default for |string| argument (|""|).

\initials{LDF 2007.07.27.}
@:BUG FIX@> BUG FIX:  No longer showing null elements of |vector<C*> v|.

\initials{LDF 2007.07.27.}
Added optional |Scanner_Node scanner_node| argument 
with the default 0.
\ENDLOG 

@q **** (4) Declaration.@> 

@<Declare |Pointer_Vector| functions@>=
int 
show(string s = "", Scanner_Node scanner_node = 0) const;

@q **** (4) Definition.@> 
@
@<Define |Pointer_Vector| functions@>=
template <class C, class D>
int 
Pointer_Vector<C, D>::show(string s, Scanner_Node scanner_node) const
{

@q ***** (5) Preliminaries.@>   

#if DEBUG_COMPILE
   bool DEBUG = false; /* |true| */ @; 
#endif /* |DEBUG_COMPILE|  */@; 

   stringstream cerr_strm;

   bool error_stop_value   = true;
   bool warning_stop_value = true;
   string thread_name      = "";

   if (scanner_node)
      scanner_node->get_thread_name_and_stop_values(&thread_name,
                                                    &error_stop_value,
                                                    &warning_stop_value);

   using namespace Scan_Parse;


@q ***** (5)@> 

   stringstream ctr_strm;

   if (s == "")
      s = "Pointer_Vector:";

   cerr_strm << s << endl
             << "size of vector: " << ctr;

   log_message(cerr_strm); 
   cerr << cerr_strm.str() << endl;
   cerr_strm.str("");

   int i = 0;

   for (typename vector<C*>::const_iterator iter = v.begin();
        iter != v.end();
        iter++)
      {
         ctr_strm << i++ << ":";

         if (*iter != static_cast<C*>(0))
            (*iter)->show(ctr_strm.str());
         else 
            cerr_strm << " 0";

         ctr_strm.str(""); 

      }  /* |for|  */

   return 0;

} /* End of |Pointer_Vector<C, D>::show| definition.  */


@q *** (3) Specializations.@>
@*2 Specializations.
\initials{LDF 2007.07.20.}

\LOG
\initials{LDF 2007.07.20.}
Added this section.
\ENDLOG

@q **** (4) |Pointer_Vector<Point, Point>| specializations.@> 
@*3 {\bf Pointer\_Vector\<Point, Point>} specializations.
\initials{LDF 2007.07.20.}

\LOG
\initials{LDF 2007.07.20.}
Added this section.
\ENDLOG

@q ***** (5) Rectify.@>
@*4 Rectify.
\initials{LDF 2007.07.27.}

\LOG
\initials{LDF 2007.07.27.}
Added this function declaration.  
The function must be defined in \filename{pntrvcf0.web}, because
it requires types which are not fully defined when this file is compiled.

\initials{LDF 2007.08.06.}
Added optional |Transform* transform| argument.  The default is 0.

\initials{LDF 2007.08.06.}
Added optional |bool do_transform| argument with the default |true|.
\ENDLOG

@q ****** (6) Declaration.@> 

@<Declare |Pointer_Vector| functions@>=
int
rectify(Scanner_Node scanner_node = 0,
        bool do_test = true,
        bool do_cull = true,
        bool do_transform = true,
        real tolerance = -1,
        Transform* transform = 0,
        Point* p = 0);

@q ***** (5) Get |Conic_Section_Lattice|.@> 
@ Get {\bf Conic\_Section\_Lattice}.
\initials{LDF 2007.07.29.}

\LOG
\initials{LDF 2007.07.29.}
Added this function declaration.  
The function must be defined in \filename{pntrvcf0.web}, because
it requires |Conic_Section_Lattice|, which isn't fully defined 
when this file is compiled.
\ENDLOG

@<Declare |Pointer_Vector| functions@>=
Conic_Section_Lattice*
get_conic_section_lattice(Scanner_Node scanner_node = 0,
                          bool do_cull = false,
                          bool do_rectify = false,
                          real tolerance = -1,
                          bool do_test = false,
                          bool do_transform = false,
                          Transform* t = 0);



@q ****** (6)@> 

@q ***** (5)@>

@q **** (4)@>

@q *** (3)@>

@q ** (2)@> 

@q * (1) Putting |struct Pointer_Vector| together.@>
@* Putting {\bf struct Pointer\_Vector} together.

\immediate\write\functexifile{^^JEnd of file:  pntrvctr.web^^J}

@q ** This is what's compiled.@>
@ This is what's compiled.
@c
@<Include files@>@;
@<Utility classes@>@;
@<Define |Pointer_Vector| functions@>@;

@q ** This is what's written to \filename{pntrvctr.h}.@>
@ This is what's written to the \filename{pntrvctr.h}.
@(pntrvctr.h@>=
@<Utility classes@>@;
@<Define |Pointer_Vector| functions@>@;

@q * Emacs-Lisp code for use in indirect buffers when using the          @>
@q   GNU Emacs editor.  The local variable list is not evaluated when an @>
@q   indirect buffer is visited, so it's necessary to evaluate the       @>
@q   following s-expression in order to use the facilities normally      @>
@q   accessed via the local variables list.                              @>
@q   \initials{LDF 2004.02.12}.                                          @>
@q   (progn (cweb-mode) (outline-minor-mode t))                          @>

  
@q * Local variables for Emacs.@>
@q Local Variables: @>
@q mode:CWEB @>
@q eval:(display-time) @>
@q run-cweave-on-file:"3DLDFprg.web" @>
@q eval:(read-abbrev-file) @>
@q indent-tabs-mode:nil @>
@q eval:(outline-minor-mode) @>
@q fill-column:80 @>
@q End: @>