struct eosio::indexed_by

Class List > eosio :: indexed_by

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. More...

Public Types

Type Name
enum index_name { index_name = static_cast<uint64_t>(IndexName) }
typedef Extractor secondary_extractor_type

Detailed Description

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.

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 template, which is a type alias to the `boost::multi_index::const_mem_fun`. See the documentation for the Boost key extractor for more details.

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; }
     uint64_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

enum eosio::indexed_by::constants {
    index_name = static_cast<uint64_t>(IndexName),
};

typedef secondary_extractor_type

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

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