Skip to content

Commit 68a0708

Browse files
committed
Added data method.
1 parent 034e7c4 commit 68a0708

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

Array.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class Array
5151
size_t max_size();
5252
bool empty();
5353
bool full();
54+
T* data();
5455

5556
private:
5657
T values_[MAX_SIZE];

ArrayDefinitions.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ template <typename T, size_t MAX_SIZE>
8989
template <typename U, size_t N>
9090
void Array<T, MAX_SIZE>::fill(const Array<U,N> &values)
9191
{
92-
assign(N,values);
92+
assign(values.size(),values);
9393
}
9494

9595
template <typename T, size_t MAX_SIZE>
@@ -172,4 +172,10 @@ bool Array<T, MAX_SIZE>::full()
172172
return size_ == MAX_SIZE;
173173
}
174174

175+
template <typename T, size_t MAX_SIZE>
176+
T* Array<T, MAX_SIZE>::data()
177+
{
178+
return values_;
179+
}
180+
175181
#endif

examples/ArrayTester/ArrayTester.ino

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,14 @@ void setup()
108108
Serial << "array_copy3.max_size():" << endl;
109109
Serial << array_copy3.max_size() << endl;
110110

111+
// get pointer to raw data
112+
size_t *array_copy3_ptr = array_copy3.data();
113+
size_t index = 2;
114+
if (index < array_copy3.size())
115+
{
116+
Serial << "array_copy3_ptr[index]:" << endl;
117+
Serial << array_copy3_ptr[index] << endl;
118+
}
111119
}
112120

113121

0 commit comments

Comments
 (0)