Loading...
Searching...
No Matches
Data Fields | Related Symbols
as_geojson Struct Reference

Detailed Description

Container for NULL-terminates GeoJSON string values.

Initialization

An as_geojson should be initialized via one of the provided function.

To initialize a stack allocated as_geojson, use as_geojson_init():

as_geojson_init(&s, "abc", false);
AS_EXTERN as_geojson * as_geojson_init(as_geojson *string, char *value, bool free)

The 3rd argument indicates whether the string value should be free()d when as_geojson is destroyed.

To create and initialize a heap allocated as_integer, use as_integer_new():

as_geojson * s = as_geojson_new("abc", false);
AS_EXTERN as_geojson * as_geojson_new(char *value, bool free)

Destruction

When the as_geojson instance is no longer required, then you should release the resources associated with it via as_geojson_destroy():

static void as_geojson_destroy(as_geojson *string)
Definition as_geojson.h:209

Usage

There are two functions for getting the boxed value contained by as_geojson:

as_geojson_get() returns the contained value. If an error occurred, then NULL is returned. Possible errors is the as_integer instance is NULL.

char * sval = as_geojson_get(i);
static char * as_geojson_get(const as_geojson *string)
Definition as_geojson.h:244

as_geojson_getorelse() allows you to return a default value if an error occurs:

char * sval = as_geojson_getorelse(i, "oops!");
static char * as_geojson_getorelse(const as_geojson *string, char *fallback)
Definition as_geojson.h:234

Conversions

as_geojson is derived from as_val, so it is generally safe to down cast:

as_val val = (as_val) s;

However, upcasting is more error prone. When doing so, you should use as_geojson_fromval(). If conversion fails, then the return value is NULL.

static as_geojson * as_geojson_fromval(const as_val *v)
Definition as_geojson.h:268

Definition at line 103 of file as_geojson.h.

#include "as_geojson.h"

+ Inheritance diagram for as_geojson:
+ Collaboration diagram for as_geojson:

Data Fields

bool free
 
size_t len
 
char * value
 
- Data Fields inherited from as_val
uint32_t count
 
bool free
 
as_val_t type
 

Related Symbols

(Note that these are not member symbols.)

static void as_geojson_destroy (as_geojson *string)
 
static as_geojsonas_geojson_fromval (const as_val *v)
 
static char * as_geojson_get (const as_geojson *string)
 
static char * as_geojson_getorelse (const as_geojson *string, char *fallback)
 
AS_EXTERN as_geojsonas_geojson_init (as_geojson *string, char *value, bool free)
 
AS_EXTERN as_geojsonas_geojson_init_wlen (as_geojson *string, char *value, size_t len, bool free)
 
AS_EXTERN size_t as_geojson_len (as_geojson *string)
 
AS_EXTERN as_geojsonas_geojson_new (char *value, bool free)
 
AS_EXTERN as_geojsonas_geojson_new_wlen (char *value, size_t len, bool free)
 
static as_valas_geojson_toval (const as_geojson *s)
 

Friends And Related Symbol Documentation

◆ as_geojson_destroy()

static void as_geojson_destroy ( as_geojson * string)
related

Destroy the as_geojson and associated resources.

Definition at line 209 of file as_geojson.h.

References as_val_destroy.

◆ as_geojson_fromval()

static as_geojson * as_geojson_fromval ( const as_val * v)
related

Convert from an as_val.

Definition at line 268 of file as_geojson.h.

References AS_GEOJSON, and as_util_fromval.

◆ as_geojson_get()

static char * as_geojson_get ( const as_geojson * string)
related

Get the string value.

Definition at line 244 of file as_geojson.h.

References as_geojson_getorelse().

◆ as_geojson_getorelse()

static char * as_geojson_getorelse ( const as_geojson * string,
char * fallback )
related

Get the string value. If string is NULL, then return the fallback value.

Definition at line 234 of file as_geojson.h.

◆ as_geojson_init()

AS_EXTERN as_geojson * as_geojson_init ( as_geojson * string,
char * value,
bool free )
related

Initialize a stack allocated as_geojson.

If free is true, then the string value will be freed when the as_geojson is destroyed.

Parameters
stringThe stack allocated as_geojson to initialize
valueThe NULL terminated string of character.
freeIf true, then the value will be freed when as_geojson is destroyed.
Returns
On success, the initialized string. Otherwise NULL.

◆ as_geojson_init_wlen()

AS_EXTERN as_geojson * as_geojson_init_wlen ( as_geojson * string,
char * value,
size_t len,
bool free )
related

Initialize a stack allocated as_geojson and its length.

If free is true, then the string value will be freed when the as_geojson is destroyed.

Parameters
stringThe stack allocated as_geojson to initialize
valueThe NULL terminated string of character.
lenThe length of the string.
freeIf true, then the value will be freed when as_geojson is destroyed.
Returns
On success, the initialized string. Otherwise NULL.

◆ as_geojson_len()

AS_EXTERN size_t as_geojson_len ( as_geojson * string)
related

The length of the string

Parameters
stringThe string to get the length of.
Returns
the length of the string in bytes.

◆ as_geojson_new()

AS_EXTERN as_geojson * as_geojson_new ( char * value,
bool free )
related

Create and initialize a new heap allocated as_geojson.

If free is true, then the string value will be freed when the as_geojson is destroyed.

Parameters
valueThe NULL terminated string of character.
freeIf true, then the value will be freed when as_geojson is destroyed.
Returns
On success, the new string. Otherwise NULL.

◆ as_geojson_new_wlen()

AS_EXTERN as_geojson * as_geojson_new_wlen ( char * value,
size_t len,
bool free )
related

Create and initialize a new heap allocated as_geojson and its length.

If free is true, then the string value will be freed when the as_geojson is destroyed.

Parameters
valueThe NULL terminated string of character.
lenThe length of the string.
freeIf true, then the value will be freed when as_geojson is destroyed.
Returns
On success, the new string. Otherwise NULL.

◆ as_geojson_toval()

static as_val * as_geojson_toval ( const as_geojson * s)
related

Convert to an as_val.

Definition at line 258 of file as_geojson.h.

Field Documentation

◆ free

bool as_geojson::free

If true, then as_geojson.value can be freed.

Definition at line 115 of file as_geojson.h.

◆ len

size_t as_geojson::len

The length of the string.

Definition at line 125 of file as_geojson.h.

◆ value

char* as_geojson::value

The string value.

Definition at line 120 of file as_geojson.h.


The documentation for this struct was generated from the following file: