Class List > eosio :: singleton

Classes

Type Name
struct row
Structure of data inside the singleton table.

Public Functions

Type Name
singleton (name code, uint64_t scope)
Construct a new singleton object.
bool exists ()
Check if the singleton table exists.
T get ()
Get the value stored inside the singleton table.
T get_or_default (const T & def = T())
Get the value stored inside the singleton table or return the specified default value if it doesn't exist.
T get_or_create (name bill_to_account, const T & def = T())
Get the value stored inside the singleton table or create a new one with the specified default value if it doesn't exist.
void set (const T & value, name bill_to_account)
Set new value to the singleton table.
void remove ()
Remove the only data inside singleton table.

Detailed Description

This wrapper uses a single table to store named objects various types.

Template parameters:

  • SingletonName - the name of this singleton variable
  • T - the type of the singleton

Public Functions Documentation

function singleton

eosio::singleton< SingletonName, T >::singleton(
    name code,
    uint64_t scope
)

Construct a new singleton object.

Construct a new singleton object given the table's owner and the scope

Parameters:

  • code - The table's owner
  • scope - The scope of the table

function exists

bool eosio::singleton< SingletonName, T >::exists()

Check if the singleton table exists.

Check if the singleton table exists

Returns:

true - if exists

Returns:

false - otherwise

function get

T eosio::singleton< SingletonName, T >::get()

Get the value stored inside the singleton table.

Get the value stored inside the singleton table. Will throw an exception if it doesn't exist

Returns:

T - The value stored

function get_or_default

T eosio::singleton< SingletonName, T >::get_or_default(
    const T & def = T()
)

Get the value stored inside the singleton table or return the specified default value if it doesn't exist.

Get the value stored inside the singleton table. If it doesn't exist, it will return the specified default value

Parameters:

  • def - The default value to be returned in case the data doesn't exist

Returns:

T - The value stored

function get_or_create

T eosio::singleton< SingletonName, T >::get_or_create(
    name bill_to_account,
    const T & def = T()
)

Get the value stored inside the singleton table or create a new one with the specified default value if it doesn't exist.

Get the value stored inside the singleton table. If it doesn't exist, it will create a new one with the specified default value

Parameters:

  • bill_to_account - The account to bill for the newly created data if the data doesn't exist
  • def - The default value to be created in case the data doesn't exist

Returns:

T - The value stored

function set

void eosio::singleton< SingletonName, T >::set(
    const T & value,
    name bill_to_account
)

Set new value to the singleton table.

Set new value to the singleton table

Parameters:

  • value - New value to be set
  • bill_to_account - Account to pay for the new value

function remove

void eosio::singleton< SingletonName, T >::remove()

Remove the only data inside singleton table.

Remove the only data inside singleton table


The documentation for this class was generated from the following file: libraries/eosiolib/singleton.hpp