| 9 | { |
| 10 | template<typename T> |
| 11 | class ArrayView |
| 12 | { |
| 13 | private: |
| 14 | T * _buffer; |
| 15 | int _count; |
| 16 | int stride; |
| 17 | public: |
| 18 | T* begin() const |
| 19 | { |
| 20 | return _buffer; |
| 21 | } |
| 22 | T* end() const |
| 23 | { |
| 24 | return (T*)((char*)_buffer + _count*stride); |
| 25 | } |
| 26 | public: |
| 27 | ArrayView() |
| 28 | { |
| 29 | _buffer = 0; |
| 30 | _count = 0; |
| 31 | } |
| 32 | ArrayView(const T & singleObj) |
| 33 | { |
| 34 | SetData((T*)&singleObj, 1, sizeof(T)); |
| 35 | } |
| 36 | ArrayView(T * buffer, int count) |
| 37 | { |
| 38 | SetData(buffer, count, sizeof(T)); |
| 39 | } |
| 40 | ArrayView(void * buffer, int count, int _stride) |
| 41 | { |
| 42 | SetData(buffer, count, _stride); |
| 43 | } |
| 44 | void SetData(void * buffer, int count, int _stride) |
| 45 | { |
| 46 | this->_buffer = (T*)buffer; |
| 47 | this->_count = count; |
| 48 | this->stride = _stride; |
| 49 | } |
| 50 | inline int GetCapacity() const |
| 51 | { |
| 52 | return _count; |
| 53 | } |
| 54 | inline int Count() const |
| 55 | { |
| 56 | return _count; |
| 57 | } |
| 58 | |
| 59 | inline T & operator [](int id) const |
| 60 | { |
| 61 | #if _DEBUG |
| 62 | if (id >= _count || id < 0) |
| 63 | throw IndexOutofRangeException("Operator[]: Index out of Range."); |
| 64 | #endif |
| 65 | return *(T*)((char*)_buffer+id*stride); |
| 66 | } |
| 67 | |
| 68 | inline T* Buffer() const |
nothing calls this directly
no test coverage detected