no-OS
Classes | Typedefs | Enumerations | Functions
no_os_list.h File Reference

List library header. More...

#include <stdint.h>
#include <stdbool.h>
Include dependency graph for no_os_list.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  no_os_list_desc
 Structure storing the list and function wrapper for usual list types. More...
 

Typedefs

typedef int32_t(* f_cmp) (void *data1, void *data2)
 Prototype of the compare function. More...
 
Generic functions

Each function interacting with the list have one of the following formats.
Aditionaly they may have one more parametere for specific functionalities.
In the Iterator functions, the list reference is replaced by the iterator's one.

typedef int32_t(* f_add) (struct no_os_list_desc *list_desc, void *data)
 Add an element in the list. More...
 
typedef int32_t(* f_edit) (struct no_os_list_desc *list_desc, void *new_data)
 Edit an element in the list. The content is replaced by new_data. More...
 
typedef int32_t(* f_read) (struct no_os_list_desc *list_desc, void **data)
 Read an element from the list. More...
 
typedef int32_t(* f_get) (struct no_os_list_desc *list_desc, void **data)
 Read and remove an element from the list. More...
 

Enumerations

enum  no_os_adapter_type {
  NO_OS_LIST_DEFAULT,
  NO_OS_LIST_QUEUE,
  NO_OS_LIST_STACK,
  NO_OS_LIST_PRIORITY_LIST
}
 Selects functionalities for functions in no_os_list_desc. More...
 

Functions

int32_t no_os_list_init (struct no_os_list_desc **list_desc, enum no_os_adapter_type type, f_cmp comparator)
 
int32_t no_os_list_remove (struct no_os_list_desc *list_desc)
 
int32_t no_os_list_get_size (struct no_os_list_desc *list_desc, uint32_t *out_size)
 
Iterator functions

An iterator is used to iterate through the list. For a list, any number of iterators can be created. All must be removed before removing a list.

int32_t no_os_iterator_init (struct no_os_iterator **iter, struct no_os_list_desc *list_desc, bool start)
 
int32_t no_os_iterator_remove (struct no_os_iterator *iter)
 
int32_t no_os_iterator_move (struct no_os_iterator *iter, int32_t steps)
 
int32_t no_os_iterator_move_to_idx (struct no_os_iterator *iter, int32_t idx)
 
int32_t no_os_iterator_find (struct no_os_iterator *iter, void *cmp_data)
 
int32_t no_os_iterator_insert (struct no_os_iterator *iter, void *data, bool after)
 
int32_t no_os_iterator_edit (struct no_os_iterator *iter, void *new_data)
 
int32_t no_os_iterator_read (struct no_os_iterator *iter, void **data)
 
int32_t no_os_iterator_get (struct no_os_iterator *iter, void **data)
 
Operations on the ends of the list

These functions will operate on the first or last element of the list

int32_t no_os_list_add_first (struct no_os_list_desc *list_desc, void *data)
 
int32_t no_os_list_edit_first (struct no_os_list_desc *list_desc, void *new_data)
 
int32_t no_os_list_read_first (struct no_os_list_desc *list_desc, void **data)
 
int32_t no_os_list_get_first (struct no_os_list_desc *list_desc, void **data)
 
int32_t no_os_list_add_last (struct no_os_list_desc *list_desc, void *data)
 
int32_t no_os_list_edit_last (struct no_os_list_desc *list_desc, void *new_data)
 
int32_t no_os_list_read_last (struct no_os_list_desc *list_desc, void **data)
 
int32_t no_os_list_get_last (struct no_os_list_desc *list_desc, void **data)
 
Operations by index

These functions use an index to identify the element in the list.

int32_t no_os_list_add_idx (struct no_os_list_desc *list_desc, void *data, uint32_t idx)
 
int32_t no_os_list_edit_idx (struct no_os_list_desc *list_desc, void *new_data, uint32_t idx)
 
int32_t no_os_list_read_idx (struct no_os_list_desc *list_desc, void **data, uint32_t idx)
 
int32_t no_os_list_get_idx (struct no_os_list_desc *list_desc, void **data, uint32_t idx)
 
Operations by comparation

These functions use the specified f_cmp at no_os_list_init to identify the element this will operate on.

int32_t no_os_list_add_find (struct no_os_list_desc *list_desc, void *data)
 
int32_t no_os_list_edit_find (struct no_os_list_desc *list_desc, void *new_data, void *cmp_data)
 
int32_t no_os_list_read_find (struct no_os_list_desc *list_desc, void **data, void *cmp_data)
 
int32_t no_os_list_get_find (struct no_os_list_desc *list_desc, void **data, void *cmp_data)
 

Detailed Description

List library header.

Author
Mihail Chindris (mihai.nosp@m.l.ch.nosp@m.indri.nosp@m.s@an.nosp@m.alog..nosp@m.com)

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  3. Neither the name of Analog Devices, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANALOG DEVICES, INC. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Library description

This library handles double linked lists and it expose inseart, read, get and delete functions.
It also can be accesed using it member functions which wrapp function for usual list types.

Sample code

// -- Use a generic list
struct no_os_list_desc *list1;
struct no_os_iterator *it;
uint32_t a;
// Create list list1
// Add items to the list
// Here the list will be: 1 -> 2 - > 3
printf("Last: %d\n", a);
// 3 will be printed
// Create an iterator on the end of the list
no_os_iterator_init(&it, list1, 0);
// Move the iterator backword with one position
// Read the data at the current position
printf("Current: %d\n", a);
// 2 will be printed
// -- Use a popular list
struct no_os_list_desc *stack;
// Create a FIFO list
// Put elements in the list
stack->push(stack, 1);
stack->push(stack, 2);
stack->push(stack, 3);
// Read from the stack
stack->pop(stack, &a);
printf("Last: %d\n", a);
// 3 will be printed

Typedef Documentation

◆ f_add

typedef int32_t(* f_add) (struct no_os_list_desc *list_desc, void *data)

Add an element in the list.

The element of the list is created and the data field is stored in it.

Parameters
list_desc- Reference to the list. Created by no_os_list_init.
data- Data to store in a list element
Returns
  • 0 : On success
  • -1 : Otherwise

◆ f_cmp

typedef int32_t(* f_cmp) (void *data1, void *data2)

Prototype of the compare function.

The function used to compare the elements of the liste when doing operations on an ordered list.

Parameters
data1- First element to be compared
data2- Second element to be compared
Returns
  • -1 - If data1 < data2
  • 0 - If data1 == data2
  • 1 - If data1 > data2

◆ f_edit

typedef int32_t(* f_edit) (struct no_os_list_desc *list_desc, void *new_data)

Edit an element in the list. The content is replaced by new_data.

Parameters
list_desc- Reference to the list. Created by no_os_list_init.
new_data- New data to replace the old one
Returns
  • 0 : On success
  • -1 : Otherwise

◆ f_get

typedef int32_t(* f_get) (struct no_os_list_desc *list_desc, void **data)

Read and remove an element from the list.

Parameters
list_desc- Reference to the list. Created by no_os_list_init.
result- If not null, result is filled with:
data- Content of the list element, NULL if some error occur.
Returns
  • 0 : On success
  • -1 : Otherwise

◆ f_read

typedef int32_t(* f_read) (struct no_os_list_desc *list_desc, void **data)

Read an element from the list.

Parameters
list_desc- Reference to the list. Created by no_os_list_init.
result- If not null, result is filled with:
data- Content of the list element, NULL if some error occur.
Returns

  • 0 : On success
  • -1 : Otherwise
Note
If the content of an element can be 0 then the result must be checked to see if the functions has succeded

Enumeration Type Documentation

◆ no_os_adapter_type

Selects functionalities for functions in no_os_list_desc.

Enumerator
NO_OS_LIST_DEFAULT 

Default type is NO_OS_LIST_STACK

NO_OS_LIST_QUEUE 

Functions for a FIFO list (First-in first-out). Elements are inserted in one end and extracted from the other end.

  • Push: Insert element
  • Pop: Get next element (Read and remove)
  • Top_next: Read next element
  • Back: Read first element
  • Swap: Edit the content of the next element
NO_OS_LIST_STACK 

Functions for a LIFO list (Last-in first-out). Elements are inserted and extracted only from the same end.

  • Push: Insert element
  • Pop: Get top element (Read and remove)
  • Top_next: Read top element
  • Back: Read bottom element
  • Swap: Edit the content of the top element
NO_OS_LIST_PRIORITY_LIST 

Functions for ordered list. The order of element is determinated usinge the f_cmp.

  • Push: Insert element
  • Pop: Get lowest element (Read and remove)
  • Top_next: Read lowest element
  • Back: Read the biggest element
  • Swap: Edit the lowest element

Function Documentation

◆ no_os_iterator_edit()

int32_t no_os_iterator_edit ( struct no_os_iterator *  iter,
void *  new_data 
)

◆ no_os_iterator_find()

int32_t no_os_iterator_find ( struct no_os_iterator *  iter,
void *  cmp_data 
)
Here is the caller graph for this function:

◆ no_os_iterator_get()

int32_t no_os_iterator_get ( struct no_os_iterator *  iter,
void **  data 
)

◆ no_os_iterator_init()

int32_t no_os_iterator_init ( struct no_os_iterator **  iter,
struct no_os_list_desc list_desc,
bool  start 
)

◆ no_os_iterator_insert()

int32_t no_os_iterator_insert ( struct no_os_iterator *  iter,
void *  data,
bool  after 
)

◆ no_os_iterator_move()

int32_t no_os_iterator_move ( struct no_os_iterator *  iter,
int32_t  steps 
)
Here is the caller graph for this function:

◆ no_os_iterator_move_to_idx()

int32_t no_os_iterator_move_to_idx ( struct no_os_iterator *  iter,
int32_t  idx 
)
Here is the caller graph for this function:

◆ no_os_iterator_read()

int32_t no_os_iterator_read ( struct no_os_iterator *  iter,
void **  data 
)
Here is the caller graph for this function:

◆ no_os_iterator_remove()

int32_t no_os_iterator_remove ( struct no_os_iterator *  iter)
Here is the caller graph for this function:

◆ no_os_list_add_find()

int32_t no_os_list_add_find ( struct no_os_list_desc list_desc,
void *  data 
)

◆ no_os_list_add_first()

int32_t no_os_list_add_first ( struct no_os_list_desc list_desc,
void *  data 
)

◆ no_os_list_add_idx()

int32_t no_os_list_add_idx ( struct no_os_list_desc list_desc,
void *  data,
uint32_t  idx 
)

◆ no_os_list_add_last()

int32_t no_os_list_add_last ( struct no_os_list_desc list_desc,
void *  data 
)
Here is the caller graph for this function:

◆ no_os_list_edit_find()

int32_t no_os_list_edit_find ( struct no_os_list_desc list_desc,
void *  new_data,
void *  cmp_data 
)

◆ no_os_list_edit_first()

int32_t no_os_list_edit_first ( struct no_os_list_desc list_desc,
void *  new_data 
)

◆ no_os_list_edit_idx()

int32_t no_os_list_edit_idx ( struct no_os_list_desc list_desc,
void *  new_data,
uint32_t  idx 
)

◆ no_os_list_edit_last()

int32_t no_os_list_edit_last ( struct no_os_list_desc list_desc,
void *  new_data 
)

◆ no_os_list_get_find()

int32_t no_os_list_get_find ( struct no_os_list_desc list_desc,
void **  data,
void *  cmp_data 
)
Here is the caller graph for this function:

◆ no_os_list_get_first()

int32_t no_os_list_get_first ( struct no_os_list_desc list_desc,
void **  data 
)
Here is the caller graph for this function:

◆ no_os_list_get_idx()

int32_t no_os_list_get_idx ( struct no_os_list_desc list_desc,
void **  data,
uint32_t  idx 
)

◆ no_os_list_get_last()

int32_t no_os_list_get_last ( struct no_os_list_desc list_desc,
void **  data 
)
Here is the caller graph for this function:

◆ no_os_list_get_size()

int32_t no_os_list_get_size ( struct no_os_list_desc list_desc,
uint32_t *  out_size 
)

◆ no_os_list_init()

int32_t no_os_list_init ( struct no_os_list_desc **  list_desc,
enum no_os_adapter_type  type,
f_cmp  comparator 
)
Here is the caller graph for this function:

◆ no_os_list_read_find()

int32_t no_os_list_read_find ( struct no_os_list_desc list_desc,
void **  data,
void *  cmp_data 
)
Here is the caller graph for this function:

◆ no_os_list_read_first()

int32_t no_os_list_read_first ( struct no_os_list_desc list_desc,
void **  data 
)

◆ no_os_list_read_idx()

int32_t no_os_list_read_idx ( struct no_os_list_desc list_desc,
void **  data,
uint32_t  idx 
)

◆ no_os_list_read_last()

int32_t no_os_list_read_last ( struct no_os_list_desc list_desc,
void **  data 
)
Here is the caller graph for this function:

◆ no_os_list_remove()

int32_t no_os_list_remove ( struct no_os_list_desc list_desc)
Here is the caller graph for this function:
no_os_list_read_last
int32_t no_os_list_read_last(struct no_os_list_desc *list_desc, void **data)
no_os_list_desc
Structure storing the list and function wrapper for usual list types.
Definition: no_os_list.h:228
NO_OS_LIST_DEFAULT
@ NO_OS_LIST_DEFAULT
Definition: no_os_list.h:195
no_os_list_desc::push
f_add push
Definition: no_os_list.h:230
NO_OS_LIST_STACK
@ NO_OS_LIST_STACK
Definition: no_os_list.h:215
no_os_iterator_move
int32_t no_os_iterator_move(struct no_os_iterator *iter, int32_t steps)
no_os_list_remove
int32_t no_os_list_remove(struct no_os_list_desc *list_desc)
no_os_list_desc::pop
f_get pop
Definition: no_os_list.h:232
no_os_iterator_remove
int32_t no_os_iterator_remove(struct no_os_iterator *iter)
NULL
#define NULL
Definition: wrapper.h:64
no_os_iterator_read
int32_t no_os_iterator_read(struct no_os_iterator *iter, void **data)
no_os_list_add_last
int32_t no_os_list_add_last(struct no_os_list_desc *list_desc, void *data)
no_os_list_init
int32_t no_os_list_init(struct no_os_list_desc **list_desc, enum no_os_adapter_type type, f_cmp comparator)
no_os_iterator_init
int32_t no_os_iterator_init(struct no_os_iterator **iter, struct no_os_list_desc *list_desc, bool start)