All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Data Fields | Related Functions
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);

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

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():

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);

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

double v = as_double_getorelse(i, -1.0);

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.

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 Functions

(Note that these are not member functions.)

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 Function Documentation

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.

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.

static double as_double_get ( const as_double value)
related

Get the double value.

Definition at line 199 of file as_double.h.

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.

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_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.
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

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: