1 | // Copyright (C) 2014 ChaosForge Ltd
|
---|
2 | // http://chaosforge.org/
|
---|
3 | //
|
---|
4 | // This file is part of NV Libraries.
|
---|
5 | // For conditions of distribution and use, see copyright notice in nv.hh
|
---|
6 |
|
---|
7 | /**
|
---|
8 | * @file array.hh
|
---|
9 | * @author Kornel Kisielewicz epyon@chaosforge.org
|
---|
10 | * @brief exception free array classes
|
---|
11 | */
|
---|
12 |
|
---|
13 | #ifndef NV_CORE_ARRAY_HH
|
---|
14 | #define NV_CORE_ARRAY_HH
|
---|
15 |
|
---|
16 | #include <nv/core/common.hh>
|
---|
17 | #include <nv/stl/memory.hh>
|
---|
18 | #include <nv/stl/iterator.hh>
|
---|
19 | #include <nv/stl/utility.hh>
|
---|
20 | #include <vector>
|
---|
21 | #include <algorithm>
|
---|
22 | #include <array>
|
---|
23 |
|
---|
24 | namespace nv
|
---|
25 | {
|
---|
26 | using ::std::vector;
|
---|
27 |
|
---|
28 | template < typename ContainerAllocator >
|
---|
29 | using array_base = detail::add_random_access< detail::add_iterators < ContainerAllocator > >;
|
---|
30 |
|
---|
31 |
|
---|
32 | template< typename T, size_t N >
|
---|
33 | using array = array_base < fixed_container_allocator < fixed_static_storage< T, N > > >;
|
---|
34 |
|
---|
35 | template< typename T >
|
---|
36 | using dynamic_array = array_base < sized_container_allocator< resizable_dynamic_storage< T > > >;
|
---|
37 |
|
---|
38 | // template < typename T, typename ContainerAllocator >
|
---|
39 | // class vector_base
|
---|
40 | // {
|
---|
41 | // public:
|
---|
42 | // typedef T value_type;
|
---|
43 | // typedef size_t size_type;
|
---|
44 | // typedef ptrdiff_t difference_type;
|
---|
45 | // typedef T* pointer;
|
---|
46 | // typedef const T* const_pointer;
|
---|
47 | // typedef T* iterator;
|
---|
48 | // typedef const T* const_iterator;
|
---|
49 | // typedef T& reference;
|
---|
50 | // typedef const T& const_reference;
|
---|
51 | //
|
---|
52 | // protected:
|
---|
53 | // ContainerAllocator m_storage;
|
---|
54 | // };
|
---|
55 |
|
---|
56 | // template< typename T, size_t N >
|
---|
57 | // class static_vector : public detail::pointer_iterators < static_vector< T, N >, T, false >
|
---|
58 | // {
|
---|
59 | // public:
|
---|
60 | // typedef T value_type;
|
---|
61 | // typedef size_t size_type;
|
---|
62 | // typedef ptrdiff_t difference_type;
|
---|
63 | // typedef T* pointer;
|
---|
64 | // typedef const T* const_pointer;
|
---|
65 | // typedef T* iterator;
|
---|
66 | // typedef const T* const_iterator;
|
---|
67 | // typedef T& reference;
|
---|
68 | // typedef const T& const_reference;
|
---|
69 | // typedef nv::reverse_iterator<iterator> reverse_iterator;
|
---|
70 | // typedef nv::reverse_iterator<const_iterator> const_reverse_iterator;
|
---|
71 | //
|
---|
72 | // static_vector() : m_size(0) {}
|
---|
73 | //
|
---|
74 | // inline const_pointer data() const { return m_data; }
|
---|
75 | // inline pointer data() { return m_data; }
|
---|
76 | // inline size_type size() const { return m_size; }
|
---|
77 | // inline bool empty() const { return !m_size; }
|
---|
78 | // inline size_type raw_size() const { return N * sizeof( T ); }
|
---|
79 | // inline const char* raw_data() const { return (const char*)m_data; }
|
---|
80 | // inline char* raw_data() { return (char*)m_data; }
|
---|
81 | //
|
---|
82 | // inline reference front() { NV_ASSERT( !empty(), "front() called on empty data!" ); return m_data[0]; }
|
---|
83 | // inline const_reference front() const { NV_ASSERT( !empty(), "front() called on empty data!" ); return m_data[0]; }
|
---|
84 | // inline reference back() { NV_ASSERT( !empty(), "front() called on empty data!" ); return m_data[m_size - 1]; }
|
---|
85 | // inline const_reference back() const { NV_ASSERT( !empty(), "front() called on empty data!" ); return m_data[m_size - 1]; }
|
---|
86 | // protected:
|
---|
87 | // value_type m_data[N];
|
---|
88 | // size_type m_size;
|
---|
89 | // };
|
---|
90 |
|
---|
91 | }
|
---|
92 |
|
---|
93 | #endif // NV_CORE_ARRAY_HH |
---|