Loading...
Searching...
No Matches
Data Fields | Related Symbols
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():

as_integer_init(&i, 100);
AS_EXTERN as_integer * as_integer_init(as_integer *integer, int64_t value)

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

AS_EXTERN as_integer * as_integer_new(int64_t value)

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

static void as_integer_destroy(as_integer *integer)
Definition as_integer.h:172

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);
static int64_t as_integer_get(const as_integer *integer)
Definition as_integer.h:194

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

int64_t ival = as_integer_getorelse(i, -1);
static int64_t as_integer_getorelse(const as_integer *integer, int64_t fallback)
Definition as_integer.h:185

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.

static as_integer * as_integer_fromval(const as_val *v)
Definition as_integer.h:226

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 Symbols

(Note that these are not member symbols.)

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

◆ as_integer_destroy()

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.

References as_val_destroy.

◆ as_integer_fromval()

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.

References AS_INTEGER, and as_util_fromval.

◆ as_integer_get()

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.

References as_integer_getorelse().

◆ as_integer_getorelse()

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.

References value.

◆ as_integer_init()

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

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.

◆ as_integer_toint()

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.

References as_integer_getorelse().

◆ as_integer_toval()

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

◆ value

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: