aboutsummaryrefslogtreecommitdiff
path: root/docs/references/utils/narray.md
diff options
context:
space:
mode:
authorKarel Kočí <cynerd@email.cz>2016-06-30 17:18:49 +0200
committerKarel Kočí <cynerd@email.cz>2016-06-30 17:18:49 +0200
commit4e1ce86af16307bf7d42657db07600867c7c4bbc (patch)
tree5d0dfddea221c91545a9bd57ac7face5842291d4 /docs/references/utils/narray.md
parent147cb7f0e67d1f3c3274effa5476607e24664182 (diff)
downloadavr-ioe-4e1ce86af16307bf7d42657db07600867c7c4bbc.tar.gz
avr-ioe-4e1ce86af16307bf7d42657db07600867c7c4bbc.tar.bz2
avr-ioe-4e1ce86af16307bf7d42657db07600867c7c4bbc.zip
Add some more progress and split non-core functionality to separate repo
More progress to implementation and some changes in project it self. This library will implement only drivers for features on chip but nothing else. Everything connected externally is now in separate repository.
Diffstat (limited to 'docs/references/utils/narray.md')
-rw-r--r--docs/references/utils/narray.md64
1 files changed, 64 insertions, 0 deletions
diff --git a/docs/references/utils/narray.md b/docs/references/utils/narray.md
new file mode 100644
index 0000000..3e64f67
--- /dev/null
+++ b/docs/references/utils/narray.md
@@ -0,0 +1,64 @@
+narray.h
+========
+This implements some helping functions for null terminated arrays. Null terminated
+arrays are used across whole project because they are simple and don't waste
+memory space. Their disadvantage is more complicated implementation of utility
+functions and much longer adding time (they are reallocated every time new data
+are added).
+
+This implementation is limited to only contains 255 elements(limited by uint8_t
+type). But it should be enough for basic usage. If you need store more than that,
+you should use different approach. Also only pointers can be stored.
+
+To define null terminated array just define pointer to you required pointer and set
+it to NULL. Such narray is handled as empty. Example:
+```C
+int **narray = 0;
+```
+After adding some data (in example case data of type `int*`) you can access them
+same as if you would working with simple array (`narray[i]`). Last element it such
+array is `NULL`. No more valid data are stored after `NULL` (This also means that
+`NULL` can't be stored to narray).
+
+All functions are taking as parameter `void ***array`, which is pointer to null
+terminated array. This parameter won't be described in functions.
+
+## Functions and macros
+### narray_add
+```C
+void narray_add(void ***array, void *data)
+```
+Add data to end of the array. This increases size of the array by one (two bytes).
+#### Parameters
+| data | data to be stored to array |
+
+### narray_remove
+```C
+void narray_remove(void ***array, void *data)
+```
+Remove specified data from array. This effectively decreases size of the array by
+one (two bytes).
+#### Parameters
+| data | data to be removed from array |
+
+### narray_size
+```C
+size_t narray_size(void ***array)
+```
+Returns size of array.
+
+### narray_free
+```C
+inline void narray_free(void ***array)
+```
+Frees whole array if allocated.
+
+### fornarray
+```C
+#define fornarray(array, i, data) for (i = 0; (data = array[i]) != 0; i++)
+```
+This is macro. It implements simple foreach cycle.
+#### Parameters
+| array | array it self (void ** not pointer) |
+| i | unsigned integer (uint8_t) |
+| data | variable which will be used to access data |