00001 // Copyright (C) 2000, International Business Machines 00002 // Corporation and others. All Rights Reserved. 00003 00004 #include <cstring> 00005 00006 //############################################################################## 00007 00008 /* The methods that are commented out are sort of generic methods that do not 00009 need specialization. Their implementation is in BCP_vector_general.hpp */ 00010 00011 //############################################################################## 00012 00013 template<> inline void BCP_vec<short>::destroy(iterator pos) 00014 { 00015 } 00016 //------------------------------------------------------------------------------ 00017 template<> inline void BCP_vec<short>::destroy_range(iterator first, iterator last) 00018 { 00019 } 00020 //------------------------------------------------------------------------------ 00021 template<> inline void BCP_vec<short>::construct(iterator pos) 00022 { 00023 *pos = 0; 00024 } 00025 //------------------------------------------------------------------------------ 00026 template<> inline void BCP_vec<short>::construct(iterator pos, const_reference x) 00027 { 00028 *pos = x; 00029 } 00030 00031 //############################################################################## 00032 00033 // template<> inline void BCP_vec<short>::allocate(size_t len) 00034 //------------------------------------------------------------------------------ 00035 template<> inline void BCP_vec<short>::deallocate() { 00036 if (start) { 00037 ::operator delete(start); 00038 } 00039 } 00040 //------------------------------------------------------------------------------ 00041 template<> void BCP_vec<short>::insert_aux(iterator position, const_reference x); 00042 00043 //############################################################################## 00044 00045 // template<> void BCP_vec<short>::BCP_vec(); 00046 //------------------------------------------------------------------------------ 00047 // template<> void BCP_vec<short>::BCP_vec(const BCP_vec<short>& x); 00048 //------------------------------------------------------------------------------ 00049 template<> BCP_vec<short>::BCP_vec(const size_t n, const_reference value); 00050 //------------------------------------------------------------------------------ 00051 template<> BCP_vec<short>::BCP_vec(const_iterator first, const_iterator last); 00052 //------------------------------------------------------------------------------ 00053 template<> BCP_vec<short>::BCP_vec(const short* x, const size_t num); 00054 00055 //############################################################################## 00056 00057 template<> void BCP_vec<short>::reserve(const size_t n); 00058 //------------------------------------------------------------------------------ 00059 // template<> inline void BCP_vec<short>::swap(BCP_vec<short>& x); 00060 //------------------------------------------------------------------------------ 00061 template<> BCP_vec<short>& BCP_vec<short>::operator=(const BCP_vec<short>& x); 00062 00063 //############################################################################## 00064 // these two members serve to copy out entries from a buffer. 00065 00066 template<> void BCP_vec<short>::assign(const void* x, const size_t num); 00067 //------------------------------------------------------------------------------ 00068 template<> void BCP_vec<short>::insert(short* position, 00069 const void* first, const size_t n); 00070 //------------------------------------------------------------------------------ 00071 template<> void BCP_vec<short>::insert(iterator position, 00072 const_iterator first, 00073 const_iterator last); 00074 //------------------------------------------------------------------------------ 00075 template<> void BCP_vec<short>::insert(iterator position, const size_t n, 00076 const_reference x); 00077 //------------------------------------------------------------------------------ 00078 template<> inline BCP_vec<short>::iterator 00079 BCP_vec<short>::insert(iterator position, const_reference x) 00080 { 00081 const size_t n = position - start; 00082 if (finish != end_of_storage && position == finish) { 00083 *finish++ = x; 00084 } else 00085 insert_aux(position, x); 00086 return start + n; 00087 } 00088 00089 //############################################################################## 00090 00091 template<> inline void BCP_vec<short>::push_back(const_reference x) 00092 { 00093 if (finish != end_of_storage) 00094 *finish++ = x; 00095 else 00096 insert_aux(finish, x); 00097 } 00098 //------------------------------------------------------------------------------ 00099 template<> inline void BCP_vec<short>::unchecked_push_back(const_reference x) 00100 { 00101 *finish++ = x; 00102 } 00103 //------------------------------------------------------------------------------ 00104 template<> inline void BCP_vec<short>::pop_back() 00105 { 00106 --finish; 00107 } 00108 //------------------------------------------------------------------------------ 00109 // template<> inline void BCP_vec<short>::clear(); 00110 //------------------------------------------------------------------------------ 00111 template<> inline void 00112 BCP_vec<short>::unchecked_update(const BCP_vec<int>& positions, 00113 const BCP_vec<short>& values) 00114 { 00115 if (positions.size() == 0) 00116 return; 00117 const_iterator val = values.begin(); 00118 BCP_vec<int>::const_iterator pos = positions.begin(); 00119 const BCP_vec<int>::const_iterator lastpos = positions.end(); 00120 while (pos != lastpos) 00121 operator[](*pos++) = *val++; 00122 } 00123 //------------------------------------------------------------------------------ 00124 template<> inline void BCP_vec<short>::update(const BCP_vec<int>& positions, 00125 const BCP_vec<short>& values) 00126 { 00127 if (positions.size() != values.size()) 00128 throw BCP_fatal_error("BCP_vec::update() called with unequal sizes.\n"); 00129 BCP_vec_sanity_check(positions.begin(), positions.end(), size()); 00130 unchecked_update(positions, values); 00131 } 00132 00133 //############################################################################## 00134 00135 template<> inline void BCP_vec<short>::keep(iterator pos) 00136 { 00137 *start = *pos; 00138 finish = start + 1; 00139 } 00140 //------------------------------------------------------------------------------ 00141 template<> inline void BCP_vec<short>::keep(iterator first, iterator last) 00142 { 00143 const size_t len = last - first; 00144 std::memmove(start, first, len * sizeof(short)); 00145 finish = start + len; 00146 } 00147 //------------------------------------------------------------------------------ 00148 // template<> inline void 00149 // BCP_vec<short>::unchecked_keep_by_index(BCP_vec<int>::const_iterator firstpos, 00150 // BCP_vec<int>::const_iterator lastpos); 00151 //------------------------------------------------------------------------------ 00152 // template<> inline void 00153 // BCP_vec<short>::keep_by_index(BCP_vec<int>::const_iterator firstpos, 00154 // BCP_vec<int>::const_iterator lastpos); 00155 //------------------------------------------------------------------------------ 00156 // template<> inline void 00157 // BCP_vec<short>::keep_by_index(const BCP_vec<int>& positions); 00158 //------------------------------------------------------------------------------ 00159 // template<> inline void 00160 // BCP_vec<short>::unchecked_keep_by_index(const BCP_vec<int>& positions); 00161 00162 //############################################################################## 00163 00164 template<> inline void BCP_vec<short>::erase(iterator position) 00165 { 00166 if (position + 1 != finish) 00167 std::memmove(position, position + 1, ((finish-position) - 1) * sizeof(short)); 00168 --finish; 00169 } 00170 //------------------------------------------------------------------------------ 00171 template<> inline void BCP_vec<short>::erase(iterator first, iterator last) 00172 { 00173 if (first != last && last != finish) 00174 std::memmove(first, last, (finish - last) * sizeof(short)); 00175 finish -= (last - first); 00176 } 00177 //------------------------------------------------------------------------------ 00178 // template <class T> inline void 00179 // BCP_vec<T>::erase_by_index(const BCP_vec<int>& positions); 00180 //------------------------------------------------------------------------------ 00181 // template <class T> inline void 00182 // BCP_vec<T>::unchecked_erase_by_index(const BCP_vec<int>& positions); 00183 //------------------------------------------------------------------------------ 00184 // template <class T> inline void 00185 // BCP_vec<T>::erase_by_index(BCP_vec<int>::const_iterator firstpos, 00186 // BCP_vec<int>::const_iterator lastpos); 00187 //------------------------------------------------------------------------------ 00188 // template <class T> void 00189 // BCP_vec<T>::unchecked_erase_by_index(BCP_vec<int>::const_iterator firstpos, 00190 // BCP_vec<int>::const_iterator lastpos); 00191 00192 //############################################################################# 00193