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

Detailed Description

Container for double values.

Initialization

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

To initialize a stack allocated as_double, use as_double_init():

as_double_init(&v, 100.0);
AS_EXTERN as_double * as_double_init(as_double *value_ptr, double value)

To create and initialize a heap allocated as_double, use as_double_new():

AS_EXTERN as_double * as_double_new(double value)

Destruction

When a heap allocated as_double instance is no longer required, then you should release the resources associated with it via as_double_destroy():

static void as_double_destroy(as_double *value)
Definition as_double.h:173

Usage

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

as_double_get() returns the contained value. If an error occurred, then 0 (zero) is returned. Possible errors is the as_double instance is NULL.

double v = as_double_get(i);
static double as_double_get(const as_double *value)
Definition as_double.h:199

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

double v = as_double_getorelse(i, -1.0);
static double as_double_getorelse(const as_double *value, double fallback)
Definition as_double.h:188

Conversions

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

as_val val = (as_val)v;

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

static as_double * as_double_fromval(const as_val *value)
Definition as_double.h:225

Definition at line 99 of file as_double.h.

#include "as_double.h"

+ Inheritance diagram for as_double:
+ Collaboration diagram for as_double:

Data Fields

double 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_double_destroy (as_double *value)
 
static as_doubleas_double_fromval (const as_val *value)
 
static double as_double_get (const as_double *value)
 
static double as_double_getorelse (const as_double *value, double fallback)
 
AS_EXTERN as_doubleas_double_init (as_double *value_ptr, double value)
 
AS_EXTERN as_doubleas_double_new (double value)
 
static as_valas_double_toval (const as_double *value)
 

Friends And Related Symbol Documentation

◆ as_double_destroy()

static void as_double_destroy ( as_double * value)
related

Destroy the as_double and release resources.

Parameters
valueThe double to destroy.

Definition at line 173 of file as_double.h.

References as_val_destroy.

◆ as_double_fromval()

static as_double * as_double_fromval ( const as_val * value)
related

Convert from an as_val.

Definition at line 225 of file as_double.h.

References AS_DOUBLE, and as_util_fromval.

◆ as_double_get()

static double as_double_get ( const as_double * value)
related

Get the double value.

Definition at line 199 of file as_double.h.

References as_double_getorelse().

◆ as_double_getorelse()

static double as_double_getorelse ( const as_double * value,
double fallback )
related

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

Definition at line 188 of file as_double.h.

References value.

◆ as_double_init()

AS_EXTERN as_double * as_double_init ( as_double * value_ptr,
double value )
related

Initialize a stack allocated as_double with the given double value.

as_double_init(&v, 123.45);

as_double_destroy() is not required for a stack allocated as_double.

Parameters
value_ptrThe as_double to initialize.
valueThe double value.
Returns
On success, the initialized value. Otherwise NULL.

◆ as_double_new()

AS_EXTERN as_double * as_double_new ( double value)
related

Creates a new heap allocated as_double.

as_double* v = as_double_new(123.45);

When the as_double is no longer needed, you should release it an it's resources:

Parameters
valueThe double value.
Returns
On success, the initialized value. Otherwise NULL.

◆ as_double_toval()

static as_val * as_double_toval ( const as_double * value)
related

Convert to an as_val.

Definition at line 214 of file as_double.h.

Field Documentation

◆ value

double as_double::value

The double value

Definition at line 110 of file as_double.h.


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