Skip to content

File notation_wptt.h

File List > note-wptt > src > notation_wptt.h

Go to the documentation of this file

#ifndef NOTATION_WPTT_H
#define NOTATION_WPTT_H

/******************************************************************************/
/*******************************Includes***************************************/
/******************************************************************************/
#include "notation_defs.h"
#include "stdbool.h"
#include "stdint.h"
#include "stdlib.h"
#include "string.h"

/******************************************************************************/
/*******************************Defines ***************************************/
/******************************************************************************/

#define NOTE_WPTT_DECODE_MAX_WEIGHTS     (UTIL_TANG_DEFS_MAX_CROSSINGNUM + 1)

#define NOTE_WPTT_DECODE_MAX_CHILDREN    (UTIL_TANG_DEFS_MAX_CROSSINGNUM)

#define NOTE_WPTT_MAX_STR_LEN            ((UTIL_TANG_DEFS_MAX_CROSSINGNUM + 1) * 5u)

/*******************************Decode Flags***********************************/

/*
 *
 | Flag\bit               | 7   | 6   | 5   | 4   | 3   | 2   | 1   | 0   |
 | ---------------------- | --- | --- | --- | --- | --- | --- | --- | --- |
 | Success                | 0   | 0   | 0   | 0   | 0   | 0   | 0   | 0   |
 | Decode String Error    | 0   | 0   | 0   | 0   | 0   | 0   | 1   | 0   |
 | Decode Dest Error      | 0   | 0   | 0   | 0   | 0   | 1   | 0   | 0   |
 | Malformed String Error | 0   | 0   | 0   | 0   | 1   | 0   | 0   | 0   |
 | Buffer Error           | 0   | 0   | 0   | 1   | 0   | 0   | 0   | 0   |
 | Over/Underflow Error   | 0   | 0   | 1   | 0   | 0   | 0   | 0   | 0   |
 */

#define NOTE_WPTT_DECODE_EMPTY_STR        (0x01u << 0x01u)

#define NOTE_WPTT_DECODE_NULL_DEST        (0x01u << 0x02u)

#define NOTE_WPTT_DECODE_BAD_STR          (0x01u << 0x03u)

#define NOTE_WPTT_DECODE_BUFFER_ERROR     (0x01u << 0x04u)

#define NOTE_WPTT_DECODE_OVRUNDR_ERROR    (0x01u << 0x05u)

/*******************************Decode Flags***********************************/

/*
 *
 | Flag\bit                   | 7   | 6   | 5   | 4   | 3   | 2   | 1   | 0   |
 | -------------------------- | --- | --- | --- | --- | --- | --- | --- | --- |
 | Success                    | 0   | 0   | 0   | 0   | 0   | 0   | 0   | 0   |
 | Encode String Buf Error    | 0   | 0   | 0   | 0   | 0   | 0   | 1   | 0   |
 | Malformed wptt Error       | 0   | 0   | 0   | 0   | 0   | 1   | 0   | 0   |
 | Over/Underflow Error       | 0   | 0   | 0   | 0   | 1   | 0   | 0   | 0   |
 | `
 |
 */

#define NOTE_WPTT_ENCODE_STR_BUF          (0x01u << 0x01u)

#define NOTE_WPTT_ENCODE_MALFORMED        (0x01u << 0x02u)

#define NOTE_WPTT_ENCODE_OVRUNDR_ERROR    (0x01u << 0x03u)

/******************************************************************************/
/*******************************Typedefs***************************************/
/******************************************************************************/

#ifdef __cplusplus
extern "C"
{
#endif

typedef enum note_wptt_V4_label_e {
    NOTE_WPTT_V4_LABEL_UNINIT,
    NOTE_WPTT_V4_LABEL_NONE,
    NOTE_WPTT_V4_LABEL_I,
    NOTE_WPTT_V4_LABEL_X,
    NOTE_WPTT_V4_LABEL_Y,
    NOTE_WPTT_V4_LABEL_Z
} note_wptt_V4_label_e;
#ifdef __cplusplus
}
#endif

#ifdef __cplusplus
extern "C"
{
#endif

typedef enum note_wptt_order_e {
    NOTE_WPTT_ORDER_UNINIT,
    NOTE_WPTT_ORDER_FORWARD,
    NOTE_WPTT_ORDER_REVERSE
} note_wptt_order_e;
#ifdef __cplusplus
}
#endif

#ifdef __cplusplus
extern "C"
{
#endif

typedef struct note_wptt_node_t {
    struct note_wptt_node_t *children[NOTE_WPTT_DECODE_MAX_CHILDREN];
    int8_t                   weights[NOTE_WPTT_DECODE_MAX_WEIGHTS];
    size_t                   number_of_children;
    uint8_t                  number_of_rings;
    note_wptt_order_e        order;
} note_wptt_node_t;
#ifdef __cplusplus
}
#endif

#ifdef __cplusplus
extern "C"
{
#endif

typedef struct note_wptt_node_buffer_t {
    note_wptt_node_t *buffer;
    size_t            size;
    size_t            idx;
} note_wptt_node_buffer_t;
#ifdef __cplusplus
}
#endif

#ifdef __cplusplus
extern "C"
{
#endif

typedef struct {
    note_wptt_node_t *       root;
    note_wptt_node_buffer_t *node_buffer;
    note_wptt_V4_label_e     label;
} note_wptt_t;
#ifdef __cplusplus
}
#endif

/******************************************************************************/
/***************************Function Declarations******************************/
/******************************************************************************/

#ifdef __cplusplus
extern "C"
{
#endif

uint8_t note_wptt_decode(char *str, note_wptt_t *wptt);

#ifdef __cplusplus
}
#endif

#ifdef __cplusplus
extern "C"
{
#endif

uint8_t note_wptt_encode(note_wptt_t wptt, char *str, size_t buffer_size);

#ifdef __cplusplus
}
#endif

#endif /* end NOTATION_WPTT_H */