Skip to content

Commit a5c56c2

Browse files
committed
First Commit
0 parents  commit a5c56c2

36 files changed

+1721
-0
lines changed

.vscode/settings.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"cSpell.words": [
3+
"Duino",
4+
"tparam"
5+
]
6+
}

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 cMard
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<img src='docs/assets/logo.png'>
2+
<h1>Dynamic Array-duino</h1>
3+
4+
5+
![Static Badge](https://img.shields.io/badge/Language-C++(Arduino)-blue)
6+
![GitHub all releases](https://img.shields.io/github/downloads/cMardc/Dynamic_Arrayduino/total)
7+
![GitHub](https://img.shields.io/github/license/cMardc/Dynamic_Arrayduino)
8+
9+
<h3>A dynamic array library for arduino</h3>
10+
11+
<img src='docs/assets/example.png'>
12+
13+
<hr>
14+
<h2>Installation</h2>
15+
<img src='docs/assets/install.png'>
16+
17+
<hr>
18+
<h3>Thanks for selecting us!</h3>
19+
<h4>Made by ~cM</h4>
20+
<h5>More Info: </h5>
21+
22+
![GitHub repo size](https://img.shields.io/github/repo-size/cMardc/Dynamic_Arrayduino)
23+
![GitHub Repo stars](https://img.shields.io/github/stars/cMardc/Dynamic_Arrayduino)
24+
25+
26+
27+
<h5>Other links : </h5>
28+
<a href="https://discord.gg/5W4XtHkc6g">Discord</a>
29+
<a href="https://github.com/cMardc">Github</a>
30+
<a href="https://stackoverflow.com/users/21458468/merd-ceferzade">Stack Overflow</a>
31+
32+
33+
![Discord](https://img.shields.io/discord/1051030547402588170)
34+

docs/DynamicArray.h

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
// DynamicArray.h
2+
3+
/*
4+
* @file DynamicArray.h
5+
* @brief This library is a dynamic array demo for Arduino boards using C++.
6+
* @note I must warn you about errors, since Arduino doesn't react to exceptions.
7+
* If a user tries to reach an index that isn't available, the output will be a bunch of useless data.
8+
* This can harm your board if used too much or used wrong, so make sure to check your code at least twice.
9+
*/
10+
11+
/*
12+
* @brief A dynamic array class that allows you to add and/or remove elements and resize the array dynamically.
13+
* @tparam T The type that will be stored in the dynamic array.
14+
*/
15+
template <typename T>
16+
class DynamicArray {
17+
private:
18+
T* data; ///< Pointer to the dynamic array data.
19+
size_t size; ///< Current number of elements in the array.
20+
size_t capacity; ///< Current capacity of the array.
21+
22+
public:
23+
/*
24+
* @brief Default constructor for the dynamic array.
25+
*/
26+
DynamicArray() : data(nullptr), size(0), capacity(0) {}
27+
28+
/*
29+
* @brief Destructor for the dynamic array.
30+
*/
31+
~DynamicArray() {
32+
delete[] data;
33+
}
34+
35+
/*
36+
* @brief Adds an element to the end of the dynamic array.
37+
* @param value The value to be added.
38+
*/
39+
void push_back(const T& value) {
40+
if (size == capacity) {
41+
resize();
42+
}
43+
data[size] = value;
44+
size++;
45+
}
46+
47+
/*
48+
* @brief Removes the last element from the end of the dynamic array.
49+
*/
50+
void pop_back() {
51+
if (size > 0) {
52+
size--;
53+
}
54+
}
55+
56+
/*
57+
* @brief Removes an element from the dynamic array at the specified index.
58+
* @param index The index of the element to be removed.
59+
*/
60+
void remove(size_t index) {
61+
if (index < size) {
62+
for (size_t i = index; i < size - 1; i++) {
63+
data[i] = data[i + 1];
64+
}
65+
size--;
66+
}
67+
}
68+
69+
/*
70+
* @brief Overloaded operator to access elements in the dynamic array.
71+
* @param index The index of the element to access.
72+
* @return A reference to the element at the specified index.
73+
*/
74+
T& operator[](size_t index) {
75+
if (index < size) {
76+
return data[index];
77+
}
78+
// Handle out of range index
79+
}
80+
81+
/*
82+
* @brief Gets the current number of elements in the dynamic array.
83+
* @return The size of the dynamic array.
84+
*/
85+
size_t getSize() const {
86+
return size;
87+
}
88+
89+
private:
90+
/*
91+
* @brief Resizes the dynamic array by creating a new array with increased capacity and copying elements.
92+
*/
93+
void resize() {
94+
size_t newCapacity = (capacity == 0) ? 1 : capacity * 2;
95+
T* newData = new T[newCapacity];
96+
for (size_t i = 0; i < size; i++) {
97+
newData[i] = data[i];
98+
}
99+
delete[] data;
100+
data = newData;
101+
capacity = newCapacity;
102+
}
103+
};

docs/assets/ard.png

45.2 KB
Loading

docs/assets/ard2.png

64.3 KB
Loading

docs/assets/array.png

2.18 KB
Loading

docs/assets/class.png

166 KB
Loading

docs/assets/consruct.png

54.9 KB
Loading

docs/assets/cppLogo.png

110 KB
Loading

docs/assets/destucter.png

47.9 KB
Loading

docs/assets/example.png

233 KB
Loading

docs/assets/example_circuit.png

102 KB
Loading

docs/assets/getSize.png

68.7 KB
Loading

docs/assets/install.png

59.9 KB
Loading

docs/assets/logo.png

69.5 KB
Loading

docs/assets/operator.png

107 KB
Loading

docs/assets/pop_back.png

63.8 KB
Loading

docs/assets/push_back.png

89.5 KB
Loading

docs/assets/remove.png

103 KB
Loading

docs/assets/rezize.png

136 KB
Loading

docs/class.html

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>class DynamicArray</title>
7+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.4.1/dist/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
8+
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
9+
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
10+
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.4.1/dist/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
11+
<link rel="preconnect" href="https://fonts.googleapis.com">
12+
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
13+
<link href="https://fonts.googleapis.com/css2?family=Oswald:wght@200&display=swap" rel="stylesheet">
14+
<link rel="stylesheet" href="stylesheet.css">
15+
<script src="https://kit.fontawesome.com/d2ec37db1e.js" crossorigin="anonymous"></script>
16+
<link rel="stylesheet" href="doc.css">
17+
</head>
18+
<body>
19+
<nav class="navbar navbar-light" style="background-color: #e3f2fd;">
20+
<a class="navbar-brand" href="#">
21+
<img src="assets/logo.png" width="100" height="75">
22+
Dynamic Array - Arduino
23+
</a>
24+
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
25+
<span class="navbar-toggler-icon"></span>
26+
</button>
27+
28+
<div class="collapse navbar-collapse" id="navbarSupportedContent">
29+
<ul class="navbar-nav mr-auto">
30+
<li class="nav-item active">
31+
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
32+
</li>
33+
<li class="nav-item">
34+
<a class="nav-link" href="https://github.com/cMardc/Dynamic_Arrayduino">Github</a>
35+
</li>
36+
<li class="nav-item dropdown">
37+
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
38+
Documentation
39+
</a>
40+
<div class="dropdown-menu" aria-labelledby="navbarDropdown" style="background-color: #e3f2fd;">
41+
<a class="dropdown-item" href="class.html">template &lt;typename T&gt; class DynamicArray</a>
42+
<a class="dropdown-item" href="constuctor.html">DynamicArray()</a>
43+
<a class="dropdown-item" href="destructer.html">~DynamicArray()</a>
44+
<a class="dropdown-item" href="push_back.html">void push_back(const T& value)</a>
45+
<a class="dropdown-item" href="pop_back.html">void pop_back()</a>
46+
<a class="dropdown-item" href="remove.html">void remove(size_t index)</a>
47+
<a class="dropdown-item" href="operator_T.html">T& operator[](size_t index)</a>
48+
<a class="dropdown-item" href="getSize.html">size_t getSize() const</a>
49+
<div class="dropdown-divider"></div>
50+
<a class="dropdown-item" href="resize.html">void resize()</a>
51+
</div>
52+
</li>
53+
</ul>
54+
<a href="DynamicArray.h" class="btn btn-primary my-2 my-sm-0" type="submit" style="color: white;" download>Download</a>
55+
</div>
56+
</nav>
57+
58+
59+
60+
61+
<div class="container">
62+
<div id="code">
63+
<div class="text-center">
64+
<h1 class="codeH">template &lt;typename T&gt; class DynamicArray</h1>
65+
<br>
66+
<p class="codeP">A dynamic array class that allows you to add and/or remove elements and resize the array dynamically.</p>
67+
<p class="codeP">T - The type that will be stored in the dynamic array.</p>
68+
<img src="assets/class.png" style="width: 60vw; height: 70vh;">
69+
</div>
70+
</div>
71+
</div>
72+
73+
74+
75+
76+
77+
78+
<nav class="navbar navbar-light" style="background-color: #e3f2fd;">
79+
<a class="navbar-brand" href="#">
80+
<img src="assets/logo.png" width="100" height="75">
81+
Dynamic Array - Arduino
82+
</a>
83+
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
84+
<span class="navbar-toggler-icon"></span>
85+
</button>
86+
87+
<div class="collapse navbar-collapse" id="navbarSupportedContent">
88+
<ul class="navbar-nav mr-auto">
89+
<li class="nav-item active">
90+
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
91+
</li>
92+
<li class="nav-item">
93+
<a class="nav-link" href="https://github.com/cMardc/Dynamic_Arrayduino">Github</a>
94+
</li>
95+
<li class="nav-item dropdown">
96+
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
97+
Documentation
98+
</a>
99+
<div class="dropdown-menu" aria-labelledby="navbarDropdown" style="background-color: #e3f2fd;">
100+
<a class="dropdown-item" href="class.html">template &lt;typename T&gt; class DynamicArray</a>
101+
<a class="dropdown-item" href="constuctor.html">DynamicArray()</a>
102+
<a class="dropdown-item" href="destructer.html">~DynamicArray()</a>
103+
<a class="dropdown-item" href="push_back.html">void push_back(const T& value)</a>
104+
<a class="dropdown-item" href="pop_back.html">void pop_back()</a>
105+
<a class="dropdown-item" href="remove.html">void remove(size_t index)</a>
106+
<a class="dropdown-item" href="operator_T.html">T& operator[](size_t index)</a>
107+
<a class="dropdown-item" href="getSize.html">size_t getSize() const</a>
108+
<div class="dropdown-divider"></div>
109+
<a class="dropdown-item" href="resize.html">void resize()</a>
110+
</div>
111+
</li>
112+
</ul>
113+
<a href="DynamicArray.h" class="btn btn-primary my-2 my-sm-0" type="submit" style="color: white;" download>Download</a>
114+
</div>
115+
</nav>
116+
</body>
117+
</html>

0 commit comments

Comments
 (0)