All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Data Fields | Related Functions
as_integer Struct Reference

Detailed Description

Container for integer values.

Initialization

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

To initialize a stack allocated as_integer, use as_integer_init():

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

Destruction

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

Usage

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

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

int64_t ival = as_integer_get(i);

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

int64_t ival = as_integer_getorelse(i, -1);

Conversions

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

as_val val = (as_val) i;

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

Definition at line 100 of file as_integer.h.

#include "as_integer.h"

+ Inheritance diagram for as_integer:
+ Collaboration diagram for as_integer:

Data Fields

int64_t 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_integer_destroy (as_integer *integer)
 
static as_integeras_integer_fromval (const as_val *v)
 
static int64_t as_integer_get (const as_integer *integer)
 
static int64_t as_integer_getorelse (const as_integer *integer, int64_t fallback)
 
AS_EXTERN as_integeras_integer_init (as_integer *integer, int64_t value)
 
AS_EXTERN as_integeras_integer_new (int64_t value)
 
static int64_t as_integer_toint (const as_integer *integer)
 
static as_valas_integer_toval (const as_integer *i)
 

Friends And Related Function Documentation

static void as_integer_destroy ( as_integer integer)
related

Destroy the as_integer and release resources.

Parameters
integerThe integer to destroy.

Definition at line 172 of file as_integer.h.

static as_integer * as_integer_fromval ( const as_val v)
related

Convert from an as_val.

Definition at line 226 of file as_integer.h.

static int64_t as_integer_get ( const as_integer integer)
related

Get the int64_t value.

Definition at line 194 of file as_integer.h.

static int64_t as_integer_getorelse ( const as_integer integer,
int64_t  fallback 
)
related

Get the int64_t value. If integer is NULL, then return the fallback value.

Definition at line 185 of file as_integer.h.

AS_EXTERN as_integer * as_integer_init ( as_integer integer,
int64_t  value 
)
related

Initialize a stack allocated as_integer with the given integer value.

as_integer_destroy() is not required for a stack allocated as_integer.

Parameters
integerThe as_integer to initialize.
valueThe integer value.
Returns
On success, the initialized value. Otherwise NULL.
AS_EXTERN as_integer * as_integer_new ( int64_t  value)
related

Creates a new heap allocated as_integer.

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

Parameters
valueThe integer value.
Returns
On success, the initialized value. Otherwise NULL.
static int64_t as_integer_toint ( const as_integer integer)
related

Get the int64_t value.

Deprecated:
Use as_integer_get() instead.

Definition at line 204 of file as_integer.h.

static as_val * as_integer_toval ( const as_integer i)
related

Convert to an as_val.

Definition at line 217 of file as_integer.h.

Field Documentation

int64_t as_integer::value

The integer value

Definition at line 112 of file as_integer.h.


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