"Fossies" - the Fresh Open Source Software Archive 
Member "qdiff-0.9.1/tvector.h" (21 Oct 2008, 2646 Bytes) of package /linux/privat/old/qdiff-0.9.1.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
For more information about "tvector.h" see the
Fossies "Dox" file reference documentation.
1 /*GPL*START*
2 *
3 * tvector<> class template -- improved stl vector<>
4 *
5 * Copyright (C) 2000-2001 by Johannes Overmann <Johannes.Overmann@gmx.de>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 * *GPL*END*/
21
22 #ifndef _ngw_tvector_h_
23 #define _ngw_tvector_h_
24
25
26 #ifdef DONT_USE_STL
27 #include "ttvector.h"
28 #define tvector_base ttvector
29 #else
30 # include <vector>
31 # define tvector_base vector
32 using namespace std;
33 #endif
34
35
36 #include "texception.h"
37
38 // history: start 08 Jul 2000
39 // 2000:
40 // 08 Jul: removing tarray and tassocarray, this should provide tmap and tvector
41 // 2001:
42 // 15 Sep: DONT_USE_STL feature added
43 // 16 Sep: splittet tstl.h into tvector.h and tmap.h
44 // 20 Sep: clear() added
45
46 template<class T>
47 class tvector: public tvector_base<T> {
48 public:
49 // 1:1 wrapper
50
51 /// create an empty vector
52 tvector():tvector_base<T>() {}
53 /// create a vector with n elements
54 tvector(size_t n):tvector_base<T>(n) {}
55 /// create a vector with n copies of t
56 tvector(size_t n, const T& t):tvector_base<T>(n, t) {}
57
58 // new functionality
59
60 /// append an element to the end
61 const tvector& operator += (const T& a) { push_back(a); return *this; }
62 /// append another tvector to the end
63 const tvector& operator += (const tvector& a) { insert(tvector_base<T>::end(), a.tvector_base<T>::begin(), a.tvector_base<T>::end()); return *this; }
64 /// direct read only access, safe
65 const T& operator[](size_t i) const { if(i < tvector_base<T>::size()) return tvector_base<T>::operator[](i); else throw TZeroBasedIndexOutOfRangeException(i, tvector_base<T>::size()); } // throw(TZeroBasedIndexOutOfRangeException);
66 /// direct read/write access, automatically create new elements
67 T& operator[](size_t i) { if(i >= tvector_base<T>::size()) operator+=(tvector(i - tvector_base<T>::size() + 1)); return tvector_base<T>::operator[](i); }
68 /// clear vector
69 void clear() { erase(tvector_base<T>::begin(), tvector_base<T>::end()); }
70 };
71
72
73 #endif /* _ngw_tvector_h_ */
74