Safir SDK Core
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Array.h
Go to the documentation of this file.
1 /******************************************************************************
2 *
3 * Copyright Saab AB, 2009-2013 (http://safir.sourceforge.net)
4 *
5 * Created by: Anders Widén / stawi
6 *
7 *******************************************************************************
8 *
9 * This file is part of Safir SDK Core.
10 *
11 * Safir SDK Core is free software: you can redistribute it and/or modify
12 * it under the terms of version 3 of the GNU General Public License as
13 * published by the Free Software Foundation.
14 *
15 * Safir SDK Core is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with Safir SDK Core. If not, see <http://www.gnu.org/licenses/>.
22 *
23 ******************************************************************************/
24 #ifndef __DOSE_ARRAY_H__
25 #define __DOSE_ARRAY_H__
26 
27 #include <boost/utility.hpp>
28 
29 namespace Safir
30 {
31 namespace Utilities
32 {
40  template<typename T>
41  class Array : private boost::noncopyable
42  {
43  public:
44 
45  // type definitions
46  typedef T* ArrayPtr;
47 
48  typedef T value_type;
49  typedef ArrayPtr iterator;
50  typedef const ArrayPtr const_iterator;
51  typedef T& reference;
52  typedef const T& const_reference;
53  typedef size_t size_type;
54  typedef ptrdiff_t difference_type;
55 
56  // constructor
57  Array(const size_t size)
58  : arraySize(size),
59  arrayPtr(new T[size])
60  {
61  }
62 
63  // destructor
65  {
66  delete[] arrayPtr;
67  }
68 
69  // iterator support
70  iterator begin() {return arrayPtr;}
71  const_iterator begin() const {return arrayPtr;}
72  iterator end() {arrayPtr + arraySize;}
73 
74  // direct element access
75  reference operator[](size_t i) {return *(arrayPtr + i);}
76  const_reference operator[](size_t i) const {return *(arrayPtr + i);}
77 
78  // size
79  size_type size() const {return arraySize;}
80  size_type max_size() const {return arraySize;}
81 
82  private:
83  const size_t arraySize;
84  const ArrayPtr arrayPtr;
85  };
86 
87 }
88 }
89 
90 #endif
91 
const_iterator begin() const
Definition: Array.h:71
T & reference
Definition: Array.h:51
STL-like fixed size array.
Definition: Array.h:41
Array(const size_t size)
Definition: Array.h:57
size_t size_type
Definition: Array.h:53
T * ArrayPtr
Definition: Array.h:46
size_type max_size() const
Definition: Array.h:80
reference operator[](size_t i)
Definition: Array.h:75
size_type size() const
Definition: Array.h:79
const ArrayPtr const_iterator
Definition: Array.h:50
T value_type
Definition: Array.h:48
const T & const_reference
Definition: Array.h:52
ptrdiff_t difference_type
Definition: Array.h:54
~Array()
Definition: Array.h:64
const_reference operator[](size_t i) const
Definition: Array.h:76
iterator end()
Definition: Array.h:72
ArrayPtr iterator
Definition: Array.h:49
iterator begin()
Definition: Array.h:70