All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Data Fields | Private Attributes | 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():

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

Destruction

When the 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 98 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
cf_atomic32 count
 
bool free
 
enum as_val_t type
 

Private Attributes

as_val _
 

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_doubleas_double_init (as_double *value_ptr, double value)
 
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 177 of file as_double.h.

static as_double * as_double_fromval ( const as_val value)
related

Convert from an as_val.

Definition at line 229 of file as_double.h.

static double as_double_get ( const as_double value)
related

Get the double value.

Definition at line 203 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 192 of file as_double.h.

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

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

Parameters
value_ptrThe as_double to initialize.
valueThe double value.
Returns
On success, the initialized value. Otherwise NULL.
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 218 of file as_double.h.

Field Documentation

as_val as_double::_
private

as_double is a subtype of as_val.

Definition at line 104 of file as_double.h.

double as_double::value

The double value

Definition at line 109 of file as_double.h.


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