Beamlib  3.0.1
This is the Beam C++ class library.
BArray.h
Go to the documentation of this file.
1 /*******************************************************************************
2  * BArray.h BEAM Array
3  * T.Barnaby, BEAM Ltd, 2007-02-06
4  * Copyright (c) 2012 All Right Reserved, Beam Ltd, http://www.beam.ltd.uk
5  *******************************************************************************
6  *
7  * For license see LICENSE.txt at the root of the beamlib source tree.
8  */
15 #ifndef BArray_H
16 #define BArray_H 1
17 
18 #include <BTypes.h>
19 #include <vector>
20 #include <algorithm>
21 
23 template <class T> class BArray : public std::vector<T> {
24 public:
25  typedef int (*SortFunc)(T& a, T& b);
26 
27  BArray() : std::vector<T>() {}
28  BArray(BSize size, T value = T()) : std::vector<T>(size, value) {}
29  BArray(const BArray& array) : std::vector<T>(array) {}
30 #ifdef OLD_GXX
31  T* data(){
32  return &(*std::vector<T>::begin());
33  }
34 #endif
35  BUInt number() const { return std::vector<T>::size(); }
36  void append(const T& value){ std::vector<T>::insert(std::vector<T>::end(), value); }
37  void append(const BArray<T>& array);
38  void insert(BUInt pos, const T& value){ std::vector<T>::insert(typename std::vector<T>::iterator(this->_M_impl._M_start + pos), value); }
39  void del(BUInt pos, BUInt num = 1){ std::vector<T>::erase(std::vector<T>::begin() + pos, std::vector<T>::begin() + pos + num); }
40  T& rear(){ return std::vector<T>::back(); }
41 // void sort(SortFunc func){ std::sort(std::vector<T>::begin(), std::vector<T>::end(), func); }
42  void sort(){ std::sort(std::vector<T>::begin(), std::vector<T>::end()); }
43 private:
44 };
45 
46 template <class T> void BArray<T>::append(const BArray<T>& array){
47  BUInt l = BArray<T>::size();
48  BUInt i;
49 
50  BArray<T>::resize(l + array.size());
51  for(i = 0; i < array.size(); i++){
52  BArray<T>::data()[l + i] = array[i];
53  }
54 }
55 
56 // Macros
57 #define BArrayLoop(list, i) for(BUInt i = 0; i < list.number(); i++)
58 
59 #endif
size_t BSize
Definition: BTypes.h:36
BUInt32 BUInt
Definition: BTypes.h:33
char data[8]
Definition: BoapMc1.h:2
Template based Array class.
Definition: BArray.h:23
void del(BUInt pos, BUInt num=1)
Definition: BArray.h:39
BArray(BSize size, T value=T())
Definition: BArray.h:28
void sort()
Definition: BArray.h:42
BArray()
Definition: BArray.h:27
void insert(BUInt pos, const T &value)
Definition: BArray.h:38
BArray(const BArray &array)
Definition: BArray.h:29
int(* SortFunc)(T &a, T &b)
Prototype for sorting function.
Definition: BArray.h:25
void append(const BArray< T > &array)
Definition: BArray.h:46
BUInt number() const
Definition: BArray.h:35
T & rear()
Definition: BArray.h:40
void append(const T &value)
Definition: BArray.h:36