跳到主要内容

eosio::singleton

Module: Contracts API / Singleton Table

More...

#include <singleton.hpp>

Public Functions

Name
singleton(name code, uint64_t scope)
boolexists()
Tget()
Get the value stored inside the singleton table.
Tget_or_default(const T & def =T())
Tget_or_create(name bill_to_account, const T & def =T())
voidset(const T & value, name bill_to_account)
voidremove()

Detailed Description

template <name::raw SingletonName,
typename T >
class eosio::singleton;

Template Parameters:

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

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

Public Functions Documentation

function singleton

inline singleton(
name code,
uint64_t scope
)

Parameters:

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

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

function exists

inline bool exists()

Return:

  • true - if exists
  • false - otherwise

Check if the singleton table exists

function get

inline T get()

Get the value stored inside the singleton table.

Return: T - The value stored

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

function get_or_default

inline T get_or_default(
const T & def =T()
)

Parameters:

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

Return: T - The value stored

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

function get_or_create

inline T get_or_create(
name bill_to_account,
const T & def =T()
)

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

Return: T - The value stored

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

function set

inline void set(
const T & value,
name bill_to_account
)

Parameters:

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

Set new value to the singleton table

function remove

inline void remove()

Remove the only data inside singleton table


Updated on 2022-12-05 at 15:38:07 +0000