Commit 72c25d97ea1c1b47909f8d3e0d7a75c72044f69e

henry 2002-06-22T23:35:02

Made FTVector a template

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
diff --git a/include/FTVector.h b/include/FTVector.h
index 4203e3e..96c59c4 100644
--- a/include/FTVector.h
+++ b/include/FTVector.h
@@ -1,261 +1,168 @@
-/*
-  Provides a non-STL alternative to the STL vector<...>
-  used inside FTvectorizer and FTGlyphContainer.
-  
-  Implementation:
-    - Dynamically resizable container.
-    - Try to mimic the calls made to the STL vector API.
-
-  Caveats:
-    - No templates, use poor macro substition where :
-      FT_VECTOR_CLASS_NAME: is the name of the class
-      FT_VECTOR_ITEM_TYPE: is the type of the object to store
-*/
-
-#define FT_VECTOR_CLASS_DEBUG 0
-
 #include "FTGL.h"
 
-class FTGL_EXPORT FT_VECTOR_CLASS_NAME
+template <typename FT_VECTOR_ITEM_TYPE>
+class FTGL_EXPORT FTVector
 {
-public:
-  
-  typedef FT_VECTOR_ITEM_TYPE value_type;
-  typedef value_type& reference;
-  typedef const value_type& const_reference;
-  typedef value_type* iterator;
-  typedef const value_type* const_iterator;
-  typedef size_t size_type;
-
-  FT_VECTOR_CLASS_NAME();
-
-  virtual ~FT_VECTOR_CLASS_NAME();
-
-  FT_VECTOR_CLASS_NAME& operator =(const FT_VECTOR_CLASS_NAME& v);
+    public:
   
-  size_type size() const;
-  size_type capacity() const;
-  iterator begin();
-  iterator end();
-  const_iterator begin() const;
-  const_iterator end() const;
-  bool empty() const;
-
-  reference operator [](size_type pos);
-  const_reference operator [](size_type pos) const;
-
-  void clear();
-  void reserve(size_type);
-  void push_back(const value_type&);
-  void resize(size_type, value_type);
-
-protected:
+        typedef FT_VECTOR_ITEM_TYPE value_type;
+        typedef value_type& reference;
+        typedef const value_type& const_reference;
+        typedef value_type* iterator;
+        typedef const value_type* const_iterator;
+        typedef size_t size_type;
+
+        FTVector()
+        {
+            Size = NumberOfItems = 0;
+            Items = 0;
+        }
+
+        virtual ~FTVector()
+        {
+            clear();
+        }
+
+        FTVector& operator = ( const FTVector& v)
+        {
+            // Warning: the vector is not cleared and resized to v capacity for
+            // efficiency reasons.
+            // clear();
+            reserve(v.capacity());
   
-  void expand(size_type = 0);
-
-private:
-
-  size_type Size;
-  size_type NumberOfItems;
-  value_type* Items;
+            iterator ptr = begin();
+            const_iterator vbegin = v.begin();
+            const_iterator vend = v.end();
+
+            while (vbegin != vend)
+            {
+                *ptr++ = *vbegin++;
+            }
+            NumberOfItems = v.size();
+            return *this;
+        }
+
+        size_type size() const
+        {
+            return NumberOfItems; 
+        }
+        
+        size_type capacity() const
+        { 
+            return Size; 
+        }
+
+        iterator begin()
+        { 
+            return Items; 
+        }
+
+        iterator end()
+        { 
+            return begin() + size(); 
+        }
+
+        const_iterator begin() const
+        { 
+          return Items; 
+        }
+
+        const_iterator end() const
+        { 
+            return begin() + size(); 
+        }
+
+        bool empty() const
+        { 
+            return size() == 0; 
+        }
+
+        reference operator []( size_type pos)
+        { 
+            return (*(begin() + pos)); 
+        }
+
+        const_reference operator []( size_type pos) const
+        { 
+            return (*(begin() + pos)); 
+        }
+
+
+        void clear()
+        {
+            if (Size)
+            {
+                delete [] Items;
+                Size = NumberOfItems = 0;
+                Items = 0;
+            }
+        }
+
+        void reserve( size_type n)
+        {
+            if( capacity() < n)
+            {
+                expand(n);
+            }
+        }
+
+        void push_back( const value_type& x)
+        {
+            if( size() == capacity())
+            {
+                expand();
+            }
+            
+            (*this)[size()] = x;
+            NumberOfItems++;
+        }
+
+        void resize( size_type, value_type)
+        {
+            reserve(n);
+            iterator end = end();
+            iterator end_capacity = begin() + capacity();
+        
+            while (end != end_capacity)
+            {
+                *end++ = x;
+            }
+        }
+
+
+    protected:
+        void expand( size_type size_hint = 0)
+        {
+            // Allocate new vector (size doubles)
+            size_type new_size = (size() == 0) ? 256 : size() * 2;
+            if( size_hint)
+            {
+                while( new_size < size_hint)
+                {
+                    new_size *= 2;
+                }
+            }
+          
+            value_type *ptr = new value_type[new_size];
+        
+            // Copy values to new vector
+            iterator begin = this->begin();
+            iterator end = this->end();
+            while( begin != end)
+            {
+                *ptr++ = *begin++;
+            }
+        
+            // Deallocate old vector and use new vector
+            delete [] Items;
+            Items = ptr;
+            Size = new_size;
+        }
+
+
+    private:
+        size_type Size;
+        size_type NumberOfItems;
+        value_type* Items;
 };
 
-
-inline 
-FT_VECTOR_CLASS_NAME::FT_VECTOR_CLASS_NAME()
-{
-  this->Size = this->NumberOfItems = 0;
-  this->Items = 0;
-}
-
-
-inline 
-FT_VECTOR_CLASS_NAME::~FT_VECTOR_CLASS_NAME()
-{
-  this->clear();
-}
-
-
-inline 
-FT_VECTOR_CLASS_NAME& FT_VECTOR_CLASS_NAME::operator =(const FT_VECTOR_CLASS_NAME& v)
-{
-  // Warning: the vector is not cleared and resized to v capacity for
-  // efficiency reasons.
-  // this->clear();
-  this->reserve(v.capacity());
-  
-  iterator ptr = this->begin();
-  const_iterator vbegin = v.begin();
-  const_iterator vend = v.end();
-
-  while (vbegin != vend)
-    {
-    *ptr++ = *vbegin++;
-    }
-  this->NumberOfItems = v.size();
-  return *this;
-}
-
-
-inline 
-FT_VECTOR_CLASS_NAME::size_type FT_VECTOR_CLASS_NAME::size() const 
-{ 
-  return this->NumberOfItems; 
-}
-
-
-inline 
-FT_VECTOR_CLASS_NAME::size_type FT_VECTOR_CLASS_NAME::capacity() const 
-{ 
-  return this->Size; 
-}
-
-
-inline 
-FT_VECTOR_CLASS_NAME::iterator FT_VECTOR_CLASS_NAME::begin() 
-{ 
-  return this->Items; 
-}
-
-
-inline 
-FT_VECTOR_CLASS_NAME::iterator FT_VECTOR_CLASS_NAME::end() 
-{ 
-  return this->begin() + this->size(); 
-}
-
-
-inline 
-FT_VECTOR_CLASS_NAME::const_iterator FT_VECTOR_CLASS_NAME::begin() const 
-{ 
-  return this->Items; 
-}
-
-
-inline 
-FT_VECTOR_CLASS_NAME::const_iterator FT_VECTOR_CLASS_NAME::end() const 
-{ 
-  return this->begin() + this->size(); 
-}
-
-
-inline 
-bool FT_VECTOR_CLASS_NAME::empty() const 
-{ 
-  return this->size() == 0; 
-}
-
-
-inline 
-FT_VECTOR_CLASS_NAME::reference FT_VECTOR_CLASS_NAME::operator [](FT_VECTOR_CLASS_NAME::size_type pos) 
-{ 
-  return (*(begin() + pos)); 
-}
-
-
-inline 
-FT_VECTOR_CLASS_NAME::const_reference FT_VECTOR_CLASS_NAME::operator [](FT_VECTOR_CLASS_NAME::size_type pos) const 
-{ 
-  return (*(begin() + pos)); 
-}
-
-
-inline 
-void FT_VECTOR_CLASS_NAME::clear()
-{
-  if (this->Size)
-    {
-#if FT_VECTOR_CLASS_DEBUG    
-    printf("FT_VECTOR_CLASS_NAME: clear() (%d / %d)\n", 
-           this->size(), this->capacity());
-#endif
-    delete [] this->Items;
-    this->Size = this->NumberOfItems = 0;
-    this->Items = 0;
-    }
-}
-
-
-inline 
-void FT_VECTOR_CLASS_NAME::expand(size_type size_hint)
-{
-#if FT_VECTOR_CLASS_DEBUG    
-  printf("FT_VECTOR_CLASS_NAME: expand() (%d / %d) hint: %d\n", 
-         this->size(), this->capacity(), size_hint);
-#endif
-
-  // Allocate new vector (size doubles)
-
-  size_type new_size = (this->size() == 0) ? 256 : this->size() * 2;
-  if (size_hint)
-    {
-    while (new_size < size_hint)
-      {
-      new_size *= 2;
-      }
-    }
-  
-  value_type *ptr = new value_type[new_size];
-
-  // Copy values to new vector
-
-  iterator begin = this->begin();
-  iterator end = this->end();
-  while (begin != end)
-    {
-    *ptr++ = *begin++;
-    }
-
-  // Deallocate old vector and use new vector
-
-  delete [] this->Items;
-  this->Items = ptr;
-  this->Size = new_size;
-}
-
-
-inline 
-void FT_VECTOR_CLASS_NAME::reserve(size_type n)
-{
-#if FT_VECTOR_CLASS_DEBUG    
-  printf("FT_VECTOR_CLASS_NAME: reserve() (%d / %d) n: %d\n", 
-         this->size(), this->capacity(), n);
-#endif
-  if (this->capacity() < n)
-    {
-    this->expand(n);
-    }
-}
-
-
-inline 
-void FT_VECTOR_CLASS_NAME::push_back(const value_type& x)
-{
-#if FT_VECTOR_CLASS_DEBUG    
-  printf("FT_VECTOR_CLASS_NAME: push_back() (%d / %d)\n", 
-         this->size(), this->capacity());
-#endif
-  if (this->size() == this->capacity())
-    {
-    this->expand();
-    }
-  (*this)[this->size()] = x;
-  this->NumberOfItems++;
-}
-
-
-inline 
-void FT_VECTOR_CLASS_NAME::resize(size_type n, value_type x)
-{
-#if FT_VECTOR_CLASS_DEBUG    
-  printf("FT_VECTOR_CLASS_NAME: resize() (%d / %d) n: %d\n", 
-         this->size(), this->capacity(), n);
-#endif
-  this->reserve(n);
-  iterator end = this->end();
-  iterator end_capacity = this->begin() + this->capacity();
-  while (end != end_capacity)
-    {
-    *end++ = x;
-    }
-}
diff --git a/include/FTVectoriser.h b/include/FTVectoriser.h
index a3231a7..5077bb4 100644
--- a/include/FTVectoriser.h
+++ b/include/FTVectoriser.h
@@ -8,6 +8,8 @@
 #include FT_GLYPH_H
 
 #include "FTGL.h"
+
+#include "FTVector.h"
 #include "FTGlyph.h"
 
 #ifndef CALLBACK
@@ -70,9 +72,6 @@ class FTGL_EXPORT ftPoint
 };
 
 
-#include "FTPointVector.h"
-
-
 /**
  * FTContour class is a container of points that describe an outline
  * point data.
@@ -132,7 +131,7 @@ class FTGL_EXPORT FTContour
         /**
          *  The list of points in this contour
          */
-        typedef FTPointVector PointVector;
+        typedef FTVector<ftPoint> PointVector;
         PointVector pointList;
         
     private:
@@ -168,7 +167,7 @@ class FTGL_EXPORT FTTesselation
         size_t size() const { return pointList.size();}
 
         GLenum meshType;
-        typedef FTPointVector PointVector;
+        typedef FTVector<ftPoint> PointVector;
         PointVector pointList;
         
     private:
@@ -176,9 +175,6 @@ class FTGL_EXPORT FTTesselation
 };
 
 
-#include "FTTesselationVector.h"
-
-
 class FTGL_EXPORT FTMesh
 {
     public:
@@ -195,10 +191,10 @@ class FTGL_EXPORT FTMesh
         void Error( GLenum e) { err = e;}
         GLenum Error() const { return err;}
 
-        typedef FTPointVector PointVector;
+        typedef FTVector<ftPoint> PointVector;
         PointVector tempPool;
         
-        typedef FTTesselationVector TesselationVector;
+        typedef FTVector<FTTesselation*> TesselationVector;
         TesselationVector tess;
         
     protected:
@@ -213,8 +209,6 @@ class FTGL_EXPORT FTMesh
 };
 
 
-#include "FTContourVector.h"
-
 
 /**
  * FTVectoriser class is a helper class that converts font outlines into
@@ -345,7 +339,7 @@ class FTGL_EXPORT FTVectoriser
         /**
          * The list of contours in this outline
          */
-        typedef FTContourVector ContourVector;
+        typedef FTVector<FTContour*> ContourVector;
         ContourVector contourList;
             
         /**