pavi  0.0
Map Path Viewer
parser_gpx.bas File Reference

Parser that reads points from *.GPX file context. More...

#include "Gir/GLib-2.0.bi"
#include "parser_gpx.bi"
#include "datetime.bi"
Include dependency graph for parser_gpx.bas:

Go to the source code of this file.

Macros

#define NL   /* !"\n" & */
 The new line charater[s]. More...
 
#define NL   /* !"\r\n" & */
 The new line charater[s]. More...
 
#define fetch(_T_)   /* find_value(_T_, AttNams, AttVals) */
 Macro to read data from parser context. More...
 
#define _START_PARSER(_N_)
 Macro to start a parser. More...
 
#define _END_PARSER(_N_)
 Macro to complete a start parser and open an end parser. More...
 
#define _NEW_PARSER(_N_, _T_)
 Macro to complete an end parser and initialize the GMarkupParser UDT. More...
 

Functions

*FUNCTION_AS_INTEGER isnum (BYVAL_AS_DOUBLE N)
 Check if floating point number is valid. More...
 
SUB_CDECL skip_parser ()
 This GMarkupParser parser does nothing, used for skipping unused XML-tags. More...
 
FUNCTION_AS_CONST_gchar_PTR find_value (BYVAL_AS_CONST_gchar_PTR Nam, BYVAL_AS_CONST_gchar_PTR_PTR AttNams, BYVAL_AS_CONST_gchar_PTR_PTR AttVals)
 Find an attribute by its name. More...
 
SUB_CDECL text_content (BYVAL_AS_GMarkupParseContext_PTR Ctx, BYVAL_AS_CONST_gchar_PTR Text, BYVAL_AS_gsize Size, BYVAL_AS_gpointer UserData, BYVAL_AS_GError_PTR_PTR Error_)
 Grep content between start and end tag. More...
 
SUB_CDECL EXT_parser ()
 The GMarkupParser for <extension> tags. More...
 
SUB_CDECL PNT_parser ()
 The GMarkupParser for <trkpt> tags. More...
 
SUB_CDECL SEG_parser ()
 The GMarkupParser for <trkseg> tags. More...
 
SUB_CDECL TRK_parser ()
 The GMarkupParser for <trk> tags. More...
 
SUB_CDECL GPX_parser ()
 The GMarkupParser for *.GPX files. More...
 

Detailed Description

Parser that reads points from *.GPX file context.

Code for a TYPE (class/UDT) that evaluates the context of a *.GPX file, creating an array of TrP entries.

Since
0.0

Definition in file parser_gpx.bas.

Macro Definition Documentation

◆ NL [1/2]

#define NL   /* !"\n" & */

The new line charater[s].

Definition at line 18 of file parser_gpx.bas.

◆ NL [2/2]

#define NL   /* !"\r\n" & */

The new line charater[s].

Definition at line 18 of file parser_gpx.bas.

◆ fetch

#define fetch (   _T_)    /* find_value(_T_, AttNams, AttVals) */

Macro to read data from parser context.

This is an essential macro to find and read data in the parser GPX data.

Since
0.0

Definition at line 47 of file parser_gpx.bas.

◆ _START_PARSER

#define _START_PARSER (   _N_)
Value:
/* (multi line FreeBASIC #MACRO)
SUB start_##_N_ CDECL( _
BYVAL ctx AS GMarkupParseContext PTR, _
BYVAL element_name AS CONST gchar PTR, _
BYVAL AttNams AS CONST gchar PTR PTR, _
BYVAL AttVals AS CONST gchar PTR PTR, _
BYVAL UserData AS gpointer, _
BYVAL error_ AS GError PTR PTR)
WITH PEEK(GPX, UserData)
#ENDMACRO */

Macro to start a parser.

Each parser uses the same parameter list for the start function. This macro generates the code for such a procedure (SUB) and opens a WITH block to support access to the GPX data.

It's designed to be used in combination with the _END_PARSER() macro.

Definition at line 58 of file parser_gpx.bas.

◆ _END_PARSER

#define _END_PARSER (   _N_)
Value:
/* (multi line FreeBASIC #MACRO)
CASE ELSE
'PRINT NL "--> " & __FUNCTION__ & " Skipping " & *element_name
g_markup_parse_context_push(ctx, @Skip_parser, UserData) '& skip_parser();
END SELECT
END WITH
END SUB
SUB end_##_N_ CDECL( _
BYVAL ctx AS GMarkupParseContext PTR, _
BYVAL element_name AS CONST gchar PTR, _
BYVAL UserData AS gpointer, _
BYVAL error_ AS GError PTR PTR)
WITH PEEK(GPX, UserData)
#ENDMACRO */

Macro to complete a start parser and open an end parser.

Each parser uses the same code for ending a start function and the same parameter list for the end function. This macro generates the code to finish the start procedure (END WITH/END SUB), open an end procedure (SUB with constant parameter list) and opens a WITH block to support access to the GPX data.

It's designed to be used after the _START_PARSER() macro and in combination with the _NEW_PARSER() macro.

Definition at line 72 of file parser_gpx.bas.

◆ _NEW_PARSER

#define _NEW_PARSER (   _N_,
  _T_ 
)
Value:
/* (multi line FreeBASIC #MACRO)
CASE ELSE
g_markup_parse_context_pop(ctx)
END SELECT
END WITH
END SUB
STATIC SHARED AS GMarkupParser _N_##_parser = TYPE(@start_##_N_, @end_##_N_, _T_, NULL, NULL)
#ENDMACRO */

Macro to complete an end parser and initialize the GMarkupParser UDT.

Each parser uses the same code for ending an end procedure. This macro generates the code to finish the end procedure and generates a structure (TYPE) to use the parser. This TYPE contains two functions (procedures for start and end of a XML tag).

The second argument is used for the text function, called for character data. Pass NULL if you don't need any text from tags, or a function to fetch the text.

It's designed to be used after the _END_PARSER() macro.

Definition at line 88 of file parser_gpx.bas.

Function Documentation

◆ isnum()

* FUNCTION_AS_INTEGER isnum ( BYVAL_AS_DOUBLE  N)

Check if floating point number is valid.

Parameters
NNumber to check
Returns
TRUE if valid, FALSE when invalid

The file content parser marks missing or error entries as NaN. This function identifies an input failure.

Since
0.0

Definition at line 32 of file parser_gpx.bas.

◆ skip_parser()

SUB_CDECL skip_parser ( )

This GMarkupParser parser does nothing, used for skipping unused XML-tags.

Definition at line 92 of file parser_gpx.bas.

◆ find_value()

FUNCTION_AS_CONST_gchar_PTR find_value ( BYVAL_AS_CONST_gchar_PTR  Nam,
BYVAL_AS_CONST_gchar_PTR_PTR  AttNams,
BYVAL_AS_CONST_gchar_PTR_PTR  AttVals 
)

Find an attribute by its name.

Parameters
NamThe attribute name
AttNamsThe GLib array of attribute names (zero terminated)
AttValsThe GLib array of attribute values
Returns
A pointer to the attribute value (or zero)

The GLib XML parser lists all attributes found in a tag and their values in the arrays AttNams and AttVals. This function finds an attribute by its name and returns its value. Otherwise it returns zero if the specified attribute isn't present.

Definition at line 108 of file parser_gpx.bas.

◆ text_content()

SUB_CDECL text_content ( BYVAL_AS_GMarkupParseContext_PTR  Ctx,
BYVAL_AS_CONST_gchar_PTR  Text,
BYVAL_AS_gsize  Size,
BYVAL_AS_gpointer  UserData,
BYVAL_AS_GError_PTR_PTR  Error_ 
)

Grep content between start and end tag.

Parameters
Ctxthe parser context
Texttext read from tag
Sizetext length (not null terminated)
UserDataour instance
Error_pointer for error message

If there's text between the opening and closing tag like <a>text</a>, this function greps the context in member variable GPX.Cont.

Since
0.0

Definition at line 133 of file parser_gpx.bas.

◆ EXT_parser()

SUB_CDECL EXT_parser ( )

The GMarkupParser for <extension> tags.

Definition at line 144 of file parser_gpx.bas.

◆ PNT_parser()

SUB_CDECL PNT_parser ( )

The GMarkupParser for <trkpt> tags.

Definition at line 167 of file parser_gpx.bas.

◆ SEG_parser()

SUB_CDECL SEG_parser ( )

The GMarkupParser for <trkseg> tags.

< Date / Time

< Latitude

< Longitude

< Elevation [m]

< Speed over ground [km/h]

< Direction Angle

Definition at line 203 of file parser_gpx.bas.

◆ TRK_parser()

SUB_CDECL TRK_parser ( )

The GMarkupParser for <trk> tags.

Definition at line 243 of file parser_gpx.bas.

◆ GPX_parser()

SUB_CDECL GPX_parser ( )

The GMarkupParser for *.GPX files.

Definition at line 267 of file parser_gpx.bas.