| 1 | // | 
|---|
| 2 | // Array.h | 
|---|
| 3 | // | 
|---|
| 4 | // Library: Foundation | 
|---|
| 5 | // Package: Core | 
|---|
| 6 | // Module:  Array | 
|---|
| 7 | // | 
|---|
| 8 | // Definition of the Array class | 
|---|
| 9 | // | 
|---|
| 10 | // Copyright (c) 2004-2008, Applied Informatics Software Engineering GmbH. | 
|---|
| 11 | // and Contributors. | 
|---|
| 12 | // | 
|---|
| 13 | // SPDX-License-Identifier:	BSL-1.0 | 
|---|
| 14 | // | 
|---|
| 15 | // ------------------------------------------------------------------------------ | 
|---|
| 16 | // (C) Copyright Nicolai M. Josuttis 2001. | 
|---|
| 17 | // Permission to copy, use, modify, sell and distribute this software | 
|---|
| 18 | // is granted provided this copyright notice appears in all copies. | 
|---|
| 19 | // This software is provided "as is" without express or implied | 
|---|
| 20 | // warranty, and with no claim as to its suitability for any purpose. | 
|---|
| 21 | // ------------------------------------------------------------------------------ | 
|---|
| 22 |  | 
|---|
| 23 |  | 
|---|
| 24 | #ifndef Foundation_Array_INCLUDED | 
|---|
| 25 | #define Foundation_Array_INCLUDED | 
|---|
| 26 |  | 
|---|
| 27 |  | 
|---|
| 28 | #include "Poco/Exception.h" | 
|---|
| 29 | #include "Poco/Bugcheck.h" | 
|---|
| 30 | #include <algorithm> | 
|---|
| 31 | #include <array> | 
|---|
| 32 |  | 
|---|
| 33 |  | 
|---|
| 34 | namespace Poco { | 
|---|
| 35 |  | 
|---|
| 36 | template<class T, std::size_t N> | 
|---|
| 37 | class Array : public std::array<T, N> | 
|---|
| 38 | /// STL container like C-style array replacement class. | 
|---|
| 39 | /// | 
|---|
| 40 | /// This implementation is based on the idea of Nicolai Josuttis. | 
|---|
| 41 | /// His original implementation can be found at http://www.josuttis.com/cppcode/array.html . | 
|---|
| 42 | { | 
|---|
| 43 |  | 
|---|
| 44 | public: | 
|---|
| 45 |  | 
|---|
| 46 | Array() : std::array<T, N>() | 
|---|
| 47 | {} | 
|---|
| 48 |  | 
|---|
| 49 | template <typename... X> | 
|---|
| 50 | Array(T t, X... xs) : | 
|---|
| 51 | std::array<T, N>::array{ {t, xs...} } | 
|---|
| 52 | {} | 
|---|
| 53 |  | 
|---|
| 54 | Array(std::initializer_list<T> l) : | 
|---|
| 55 | std::array<T, N>::array() | 
|---|
| 56 | { | 
|---|
| 57 | std::copy(l.begin(), l.end(), this->begin()); | 
|---|
| 58 | } | 
|---|
| 59 |  | 
|---|
| 60 | enum { static_size = N }; | 
|---|
| 61 |  | 
|---|
| 62 | T* c_array() | 
|---|
| 63 | { | 
|---|
| 64 | /// Use array as C array (direct read/write access to data) | 
|---|
| 65 | return this->data(); | 
|---|
| 66 | } | 
|---|
| 67 |  | 
|---|
| 68 | template <typename Other> | 
|---|
| 69 | Array<T,N>& operator= (const Array<Other,N>& rhs) | 
|---|
| 70 | /// Assignment with type conversion | 
|---|
| 71 | { | 
|---|
| 72 | std::copy(rhs.begin(),rhs.end(), this->begin()); | 
|---|
| 73 | return *this; | 
|---|
| 74 | } | 
|---|
| 75 |  | 
|---|
| 76 | void assign (const T& value) | 
|---|
| 77 | /// Assign one value to all elements | 
|---|
| 78 | { | 
|---|
| 79 | std::fill_n(this->begin(),this->size(),value); | 
|---|
| 80 | } | 
|---|
| 81 |  | 
|---|
| 82 | }; | 
|---|
| 83 |  | 
|---|
| 84 |  | 
|---|
| 85 | } // namespace Poco | 
|---|
| 86 |  | 
|---|
| 87 | #endif // Foundation_Array_INCLUDED | 
|---|
| 88 |  | 
|---|
| 89 |  | 
|---|