rayzor
changeset 4:18bdbcbaee81
forgot to add stl/vector.h
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sun, 06 Apr 2014 01:12:50 +0300 |
parents | 9035507275d6 |
children | 5fcf72837b69 |
files | src/stl/vector.h util/fixcase |
diffstat | 2 files changed, 105 insertions(+), 1 deletions(-) [+] |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/stl/vector.h Sun Apr 06 01:12:50 2014 +0300 1.3 @@ -0,0 +1,103 @@ 1.4 +/* vi:set ft=cpp: */ 1.5 +#ifndef VECTOR_H_ 1.6 +#define VECTOR_H_ 1.7 + 1.8 +template <class T> 1.9 +class vector { 1.10 +private: 1.11 + T *data; 1.12 + size_t num_items, max_items; 1.13 + 1.14 +public: 1.15 + vector() 1.16 + { 1.17 + data = 0; 1.18 + num_items = max_items = 0; 1.19 + } 1.20 + 1.21 + vector(const vector &v) 1.22 + { 1.23 + data = 0; 1.24 + num_items = max_items = 0; 1.25 + resize(v.size()); 1.26 + 1.27 + for(size_t i=0; i<v.size(); i++) { 1.28 + data[i] = v.data[i]; 1.29 + } 1.30 + } 1.31 + 1.32 + vector &operator =(const vector &v) 1.33 + { 1.34 + if(&v != this) { 1.35 + clear(); 1.36 + resize(v.size()); 1.37 + 1.38 + for(size_t i=0; i<v.size(); i++) { 1.39 + data[i] = v.data[i]; 1.40 + } 1.41 + } 1.42 + return *this; 1.43 + } 1.44 + 1.45 + ~vector() 1.46 + { 1.47 + clear(); 1.48 + } 1.49 + 1.50 + void clear() 1.51 + { 1.52 + delete [] data; 1.53 + max_items = num_items = 0; 1.54 + } 1.55 + 1.56 + bool empty() const 1.57 + { 1.58 + return num_items == 0; 1.59 + } 1.60 + 1.61 + size_t size() const 1.62 + { 1.63 + return num_items; 1.64 + } 1.65 + 1.66 + void resize(size_t nsz) 1.67 + { 1.68 + if(nsz > 0) { 1.69 + T *newdata = new T[nsz]; 1.70 + if(!newdata) return; 1.71 + 1.72 + size_t num = num_items < nsz ? num_items : nsz; 1.73 + for(size_t i=0; i<num; i++) { 1.74 + newdata[i] = data[i]; 1.75 + } 1.76 + 1.77 + delete [] data; 1.78 + data = newdata; 1.79 + max_items = nsz; 1.80 + num_items = num; 1.81 + } else { 1.82 + delete [] data; 1.83 + max_items = num_items = 0; 1.84 + } 1.85 + } 1.86 + 1.87 + void push_back(const T &item) 1.88 + { 1.89 + if(num_items >= max_items) { 1.90 + resize(max_items > 0 ? max_items * 2 : 8); 1.91 + } 1.92 + data[num_items++] = item; 1.93 + } 1.94 + 1.95 + T &operator [](int idx) 1.96 + { 1.97 + return data[idx]; 1.98 + } 1.99 + 1.100 + const T &operator [](int idx) const 1.101 + { 1.102 + return data[idx]; 1.103 + } 1.104 +}; 1.105 + 1.106 +#endif // VECTOR_H_
2.1 --- a/util/fixcase Sat Apr 05 20:53:44 2014 +0300 2.2 +++ b/util/fixcase Sun Apr 06 01:12:50 2014 +0300 2.3 @@ -1,6 +1,7 @@ 2.4 #!/bin/sh 2.5 2.6 -for i in src/* util/*; do 2.7 +src=`find \( -iname '*.c' -o -iname '*.cc' -o -iname '*.h' -o -iname '*.inl' \)` 2.8 +for i in $src util/*; do 2.9 if echo $i | grep '[A-Z]' >/dev/null; then 2.10 fixed=`echo $i | tr '[:upper:]' '[:lower:]'` 2.11 echo "\"$i\" -> \"$fixed\""