/******************************************************************************* * BArray.h BEAM Array * T.Barnaby, BEAM Ltd, 2007-02-06 * Copyright (c) 2012 All Right Reserved, Beam Ltd, http://www.beam.ltd.uk ******************************************************************************* */ #ifndef BArray_H #define BArray_H 1 #include #include #include /// Template based Array class. /// This is based on the Standard C++ library vector class and has all of the /// functionality of that class. template class BArray : public std::vector { public: typedef int (*SortFunc)(T& a, T& b); ///< Prototype for sorting function BArray() : std::vector() {} BArray(BSize size, T value = T()) : std::vector(size, value) {} BArray(const BArray& array) : std::vector(array) {} #ifdef OLD_GXX T* data(){ return &(*std::vector::begin()); } #endif BUInt number() const { return std::vector::size(); } void append(const T& value){ std::vector::insert(std::vector::end(), value); } void append(const BArray& array); void insert(BUInt pos, const T& value){ std::vector::insert(typename std::vector::iterator(this->_M_impl._M_start + pos), value); } void del(BUInt pos, BUInt num = 1){ std::vector::erase(std::vector::begin() + pos, std::vector::begin() + pos + num); } T& rear(){ return std::vector::back(); } // void sort(SortFunc func){ std::sort(std::vector::begin(), std::vector::end(), func); } void sort(){ std::sort(std::vector::begin(), std::vector::end()); } private: }; template void BArray::append(const BArray& array){ BUInt l = BArray::size(); BArray::resize(l + array.size()); memcpy(&BArray::data()[l], array.data(), sizeof(T) * array.size()); } // Macros #define BArrayLoop(list, i) for(BUInt i = 0; i < list.number(); i++) #endif