BDS Public
Beam-lib  2.16.3
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 #ifndef BArray_H
8 #define BArray_H 1
9 
10 #include <BTypes.h>
11 #include <vector>
12 #include <algorithm>
13 
17 template <class T> class BArray : public std::vector<T> {
18 public:
19  typedef int (*SortFunc)(T& a, T& b);
20 
21  BArray() : std::vector<T>() {}
22  BArray(BSize size, T value = T()) : std::vector<T>(size, value) {}
23  BArray(const BArray& array) : std::vector<T>(array) {}
24 #ifdef OLD_GXX
25  T* data(){
26  return &(*std::vector<T>::begin());
27  }
28 #endif
29  BUInt number() const { return std::vector<T>::size(); }
30  void append(const T& value){ std::vector<T>::insert(std::vector<T>::end(), value); }
31  void append(const BArray<T>& array);
32  void insert(BUInt pos, const T& value){ std::vector<T>::insert(typename std::vector<T>::iterator(this->_M_impl._M_start + pos), value); }
33  void del(BUInt pos, BUInt num = 1){ std::vector<T>::erase(std::vector<T>::begin() + pos, std::vector<T>::begin() + pos + num); }
34  T& rear(){ return std::vector<T>::back(); }
35 // void sort(SortFunc func){ std::sort(std::vector<T>::begin(), std::vector<T>::end(), func); }
36  void sort(){ std::sort(std::vector<T>::begin(), std::vector<T>::end()); }
37 private:
38 };
39 
40 template <class T> void BArray<T>::append(const BArray<T>& array){
41  BUInt l = BArray<T>::size();
42  BUInt i;
43 
44  BArray<T>::resize(l + array.size());
45  for(i = 0; i < array.size(); i++){
46  BArray<T>::data()[l + i] = array[i];
47  }
48 }
49 
50 // Macros
51 #define BArrayLoop(list, i) for(BUInt i = 0; i < list.number(); i++)
52 
53 #endif
void del(BUInt pos, BUInt num=1)
Definition: BArray.h:33
Definition: BArray.h:17
size_t BSize
Definition: BTypes.h:33
BUInt number() const
Definition: BArray.h:29
void sort()
Definition: BArray.h:36
void append(const T &value)
Definition: BArray.h:30
BArray(const BArray &array)
Definition: BArray.h:23
BArray(BSize size, T value=T())
Definition: BArray.h:22
BUInt32 BUInt
Definition: BTypes.h:30
int(* SortFunc)(T &a, T &b)
Prototype for sorting function.
Definition: BArray.h:19
char data[8]
Definition: BoapMc1.h:21
void insert(BUInt pos, const T &value)
Definition: BArray.h:32
BArray()
Definition: BArray.h:21
T & rear()
Definition: BArray.h:34