source: trunk/poppler/mypoppler/goo/GooVector.h @ 27

Last change on this file since 27 was 27, checked in by Eugene Romanenko, 16 years ago

poppler updated to version 0.5.2, also needed changes to be compatible with new poppler

File size: 1.2 KB
Line 
1#ifndef _VECTOR_H
2#define _VECTOR_H
3#include "goo/gtypes.h"
4
5
6template<class T>
7class GooVector{
8private:
9   
10   int _size;
11   T*  last;
12   T*  storage; 
13 
14   void resize(){
15     if (_size==0) _size=2;else _size=2*_size;
16      T *tmp=new T[_size];
17     if (storage){
18       last=copy(storage,last,tmp);
19       delete [] storage;
20      }
21     else last=tmp; 
22     storage=tmp;
23    }
24
25   T* copy(T* src1,T* src2,T* dest){
26     T* tmp=src1;
27     T* d=dest;
28      while(tmp!=src2){
29        *d=*tmp;
30         d++;tmp++;
31       }
32      return d;
33   }
34
35public:
36 typedef T* iterator;
37
38 GooVector(){
39  _size=0;
40  last=0;
41  storage=0;
42}
43
44
45
46virtual ~GooVector(){
47  delete[] storage ;
48} 
49
50void reset(){
51  last=storage;
52}
53
54int size(){
55  return (last-storage);
56}   
57void push_back(const T& elem){
58  if (!storage||(size() >=_size)) resize();
59        *last=elem;
60         last++;
61 
62     
63} 
64
65
66T pop_back() {
67    if (last!=storage) last--;
68
69    return *last;
70} 
71
72
73T operator[](unsigned int i){
74 return *(storage+i);
75}
76 
77
78GBool isEmpty() const{
79 return !_size || (last==storage) ;
80}
81
82
83
84iterator begin() const{
85 return storage;
86}
87
88iterator end() const {
89  return last;
90}
91};
92#endif
93
94
95
96   
97 
98 
99
100
101
Note: See TracBrowser for help on using the repository browser.