Skip to content

File notation_plpath.h

File List > note-plpath > src > notation_plpath.h

Go to the documentation of this file

#ifndef NOTATION_PLPATH_H
#define NOTATION_PLPATH_H

/******************************************************************************/
/*******************************Includes***************************************/
/******************************************************************************/
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>

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

#define NOTE_PLPATH_DECODE_MAX_SEGMENTS    (UTIL_TANG_DEFS_MAX_CROSSINGNUM + 1)

#define NOTE_PLPATH_DECODE_MAX_CHILDREN    (UTIL_TANG_DEFS_MAX_CROSSINGNUM)

#define NOTE_PLPATH_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_PLPATH_DECODE_EMPTY_STR        (0x01u << 0x01u)

#define NOTE_PLPATH_DECODE_NULL_DEST        (0x01u << 0x02u)

#define NOTE_PLPATH_DECODE_BAD_STR          (0x01u << 0x03u)

#define NOTE_PLPATH_DECODE_BUFFER_ERROR     (0x01u << 0x04u)

#define NOTE_PLPATH_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 plpath Error       | 0   | 0   | 0   | 0   | 0   | 1   | 0   | 0   |
 | Over/Underflow Error       | 0   | 0   | 0   | 0   | 1   | 0   | 0   | 0   |
 | `
 |
 */

#define NOTE_PLPATH_ENCODE_STR_BUF          (0x01u << 0x01u)

#define NOTE_PLPATH_ENCODE_MALFORMED        (0x01u << 0x02u)

#define NOTE_PLPATH_ENCODE_OVRUNDR_ERROR    (0x01u << 0x03u)

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

#ifdef __cplusplus
extern "C"
{
#endif

typedef struct note_plpath_point_t {
    double                      x;
    double                      y;
    double                      z;
    struct note_plpath_point_t *next_point;
} note_plpath_point_t;
#ifdef __cplusplus
}
#endif

/******************************************************************************/

#ifdef __cplusplus
extern "C"
{
#endif

typedef struct note_plpath_point_buffer_t {
    note_plpath_point_t *buffer;
    size_t               size;
    size_t               idx;
} note_plpath_point_buffer_t;
#ifdef __cplusplus
}
#endif

/******************************************************************************/

#ifdef __cplusplus
extern "C"
{
#endif

typedef struct {
    note_plpath_point_t *       segments[NOTE_PLPATH_DECODE_MAX_SEGMENTS];
    size_t                      segment_count;
    note_plpath_point_buffer_t *buffer;
} note_plpath_t;
#ifdef __cplusplus
}
#endif

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

#ifdef __cplusplus
extern "C"
{
#endif

uint8_t note_plpath_decode(char *str, note_plpath_t *path);

#ifdef __cplusplus
}
#endif

#ifdef __cplusplus
extern "C"
{
#endif

uint8_t note_plpath_encode(note_plpath_t path, char *str, size_t buffer_size);

#ifdef __cplusplus
}
#endif

#endif /* end NOTATION_PLPATH_H */