跳到主要内容

eosio::indexed_by

Module: Contracts API / Multi Index Table

More...

#include <multi_index.hpp>

Public Types

Name
enumconstants { index_name = static_cast<uint64_t>(IndexName)}
typedef Extractorsecondary_extractor_type

Detailed Description

template <name::raw IndexName,
typename Extractor >
struct eosio::indexed_by;

Template Parameters:

  • IndexName - is the name of the index. The name must be provided as an EOSIO base32 encoded 64-bit integer and must conform to the EOSIO naming requirements of a maximum of 13 characters, the first twelve from the lowercase characters a-z, digits 1-5, and ".", and if there is a 13th character, it is restricted to lowercase characters a-p and ".".
  • Extractor - is a function call operator that takes a const reference to the table object type and returns either a secondary key type or a reference to a secondary key type. It is recommended to use the [eosio::const_mem_fun](/cdt/latest/reference/Classes/structeosio_1_1const__mem__fun) template, which is a type alias to the boost::multi_index::const_mem_fun. See the documentation for the Boost [const_mem_fun](/cdt/latest/reference/Classes/structeosio_1_1const__mem__fun) key extractor for more details.

The indexed_by struct is used to instantiate the indices for the Multi-Index table. In EOSIO, up to 16 secondary indices can be specified.

Example:

#include <eosiolib/eosio.hpp>
using namespace eosio;
class mycontract: eosio::contract {
struct record {
uint64_t primary;
uint128_t secondary;
uint64_t primary_key() const { return primary; }
uint128_t get_secondary() const { return secondary; }
};
public:
mycontract(name receiver, name code, datastream<const char*> ds):contract(receiver, code, ds){}
void myaction() {
auto code = _self;
auto scope = _self;
multi_index<"mytable"_n, record,
indexed_by< "bysecondary"_n, const_mem_fun<record, uint128_t, &record::get_secondary> > > table( code, scope);
}
}
EOSIO_DISPATCH( mycontract, (myaction) )

Public Types Documentation

enum constants

EnumeratorValueDescription
index_namestatic_cast<uint64_t>(IndexName)

typedef secondary_extractor_type

typedef Extractor eosio::indexed_by< IndexName, Extractor >::secondary_extractor_type;

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