PeriDyno 1.0.0
Loading...
Searching...
No Matches
RandomAccessContainer.h
Go to the documentation of this file.
1
16
17#ifndef RANDOM_ACCESS_CONTAINER_H
18#define RANDOM_ACCESS_CONTAINER_H
19
20#include "STLBuffer.h"
21#include "functional_base.h"
22#include "type_traits.h"
23#include "Platform.h"
24
54
55namespace dyno {
56 template <typename T>
58 {
61
62 public:
63 typedef T value_type;
64 typedef T* pointer;
65 typedef const T* const_pointer;
66 typedef T& reference;
67 typedef const T& const_reference;
68 typedef T* iterator;
69 typedef const T* const_iterator;
70 typedef long long difference_type;
71 typedef uint size_type;
72
73 public:
74 DYN_FUNC RandomAccessContainer() = default;
75
76 DYN_FUNC RandomAccessContainer(const this_type& c) :
77 m_size(c.m_size),
79 m_End(c.m_End),
81 this->reserve(c.m_startLoc, c.m_maxSize);
82 };
83
85 m_startLoc = nullptr;
86 m_Begin = nullptr;
87 m_End = nullptr;
88 m_bufferEnd = nullptr;
89 };
90
91 DYN_FUNC void assign(size_type n, const value_type& value);
92
93 template <typename InputIterator>
94 DYN_FUNC void assign(InputIterator first, InputIterator last);
95
96 DYN_FUNC inline iterator begin() noexcept { return m_Begin; }
97 DYN_FUNC inline const_iterator begin() const noexcept { return m_Begin; }
98
99 DYN_FUNC inline iterator end() noexcept {return m_End; }
100 DYN_FUNC inline const_iterator end() const noexcept { return m_End; }
101
102 DYN_FUNC inline bool empty() const noexcept {return m_startLoc == nullptr;} //different from std's
103 DYN_FUNC inline size_type size() const noexcept { return m_size; }
104 DYN_FUNC inline size_type capacity() const noexcept { return m_maxSize; }
105
106 DYN_FUNC void resize(size_type n);
107
108 DYN_FUNC inline void reserve(iterator beg, size_type buffer_size); //only and must call one time.
109 DYN_FUNC inline void reserve(iterator beg, iterator end, size_type buffer_size = 0);
110
111 DYN_FUNC inline pointer data() noexcept { return m_startLoc; }
112 DYN_FUNC inline const_pointer data() const noexcept {return m_startLoc; }
113
114 DYN_FUNC inline reference operator[](size_type n);
115 DYN_FUNC inline const_reference operator[](size_type n) const;
116
117 DYN_FUNC inline reference at(size_type n);
118 DYN_FUNC inline const_reference at(size_type n) const;
119
120 DYN_FUNC inline reference front();
121 DYN_FUNC inline const_reference front() const;
122
123 DYN_FUNC inline reference back();
124 DYN_FUNC inline const_reference back() const;
125
126 DYN_FUNC void push_back(const value_type& value);
127 DYN_FUNC void push_back(value_type&& value);
128 DYN_FUNC reference push_back();
129 DYN_FUNC void pop_back();
130
131 DYN_FUNC inline iterator find(iterator first, iterator last, const value_type& value); //O(n)
132
133 template<typename Predicate = dyno::predicate<value_type>>
134 DYN_FUNC inline iterator find(iterator first, iterator last, const value_type& value, Predicate pre); //O(n)
135
136 DYN_FUNC iterator insert(const_iterator position, const value_type& value);
137 DYN_FUNC iterator insert(const_iterator position, size_type n, const value_type& value);
138 DYN_FUNC iterator insert(const_iterator position, value_type&& value);
139
140 template <typename InputIterator>
141 DYN_FUNC iterator insert(const_iterator position, InputIterator first, InputIterator last);
142
143 DYN_FUNC iterator erase_first(const T& value);
144 DYN_FUNC iterator erase_first_unsorted(const T& value); // Same as erase, except it doesn't preserve order, but is faster because it simply copies the last item in the RandomAccessContainer over the erased position.
145
146 DYN_FUNC iterator erase(const_iterator position);
147 DYN_FUNC iterator erase(const_iterator first, const_iterator last);
148 DYN_FUNC iterator erase_unsorted(const_iterator position); // Same as erase, except it doesn't preserve order, but is faster because it simply copies the last item in the RandomAccessContainer over the erased position.
149
150 DYN_FUNC void clear() noexcept; //clear will not change m_Begin and capacity, only change size and m_End
151
152 private:
155 iterator m_End = nullptr;
156 iterator m_Begin = nullptr; //Logically, m_Begin is the iterator of the beginner of element, m_startLoc is the pointer to the container, though they will be equal in this implementation.
157
158 }; // class RandomAccessContainer
159
160}
161
162#include "RandomAccessContainer.inl"
163#endif // RANDOM_ACCESS_CONTAINER_H
DYN_FUNC size_type capacity() const noexcept
DYN_FUNC iterator erase(const_iterator position)
DYN_FUNC const_iterator begin() const noexcept
DYN_FUNC RandomAccessContainer()=default
DYN_FUNC iterator end() noexcept
DYN_FUNC iterator begin() noexcept
DYN_FUNC void reserve(iterator beg, size_type buffer_size)
DYN_FUNC iterator erase_first_unsorted(const T &value)
DYN_FUNC void resize(size_type n)
DYN_FUNC bool empty() const noexcept
DYN_FUNC iterator insert(const_iterator position, const value_type &value)
DYN_FUNC void assign(size_type n, const value_type &value)
DYN_FUNC iterator erase_unsorted(const_iterator position)
DYN_FUNC reference at(size_type n)
RandomAccessContainer< T > this_type
DYN_FUNC size_type size() const noexcept
DYN_FUNC const_pointer data() const noexcept
DYN_FUNC const_iterator end() const noexcept
DYN_FUNC reference operator[](size_type n)
DYN_FUNC iterator find(iterator first, iterator last, const value_type &value)
DYN_FUNC pointer data() noexcept
DYN_FUNC RandomAccessContainer(const this_type &c)
DYN_FUNC iterator erase_first(const T &value)
DYN_FUNC STLBuffer()
Definition STLBuffer.h:19
#define T(t)
This is an implementation of AdditiveCCD based on peridyno.
Definition Array.h:25
unsigned int uint
Definition VkProgram.h:14