Beamlib 3.5.3
This is the Beam C++ class library.
Loading...
Searching...
No Matches
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
23template <class T> class BArray : public std::vector<T> {
24public:
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(BSize size, T* data) : std::vector<T>(data, data + size) {}
30 BArray(const BArray& array) : std::vector<T>(array) {}
31#ifdef OLD_GXX
32 T* data(){
33 return &(*std::vector<T>::begin());
34 }
35#endif
36 BUInt number() const { return std::vector<T>::size(); }
37 void append(const T& value){ std::vector<T>::insert(std::vector<T>::end(), value); }
38 void append(const BArray<T>& array);
39 void insert(BUInt pos, const T& value){ std::vector<T>::insert(typename std::vector<T>::iterator(this->_M_impl._M_start + pos), value); }
40 void del(BUInt pos, BUInt num = 1){ std::vector<T>::erase(std::vector<T>::begin() + pos, std::vector<T>::begin() + pos + num); }
41 T& rear(){ return std::vector<T>::back(); }
42// void sort(SortFunc func){ std::sort(std::vector<T>::begin(), std::vector<T>::end(), func); }
43 void sort(){ std::sort(std::vector<T>::begin(), std::vector<T>::end()); }
44private:
45};
46
47template <class T> void BArray<T>::append(const BArray<T>& array){
49 BUInt i;
50
51 BArray<T>::resize(l + array.size());
52 for(i = 0; i < array.size(); i++){
53 BArray<T>::data()[l + i] = array[i];
54 }
55}
56
57// Macros
58#define BArrayLoop(list, i) for(BUInt i = 0; i < list.number(); i++)
59
60#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:40
BArray(BSize size, T value=T())
Definition BArray.h:28
void sort()
Definition BArray.h:43
BArray()
Definition BArray.h:27
void insert(BUInt pos, const T &value)
Definition BArray.h:39
BArray(const BArray &array)
Definition BArray.h:30
int(*) SortFunc(T &a, T &b)
Prototype for sorting function.
Definition BArray.h:25
BArray(BSize size, T *data)
Definition BArray.h:29
void append(const BArray< T > &array)
Definition BArray.h:47
BUInt number() const
Definition BArray.h:36
T & rear()
Definition BArray.h:41
void append(const T &value)
Definition BArray.h:37