BitShares-Core  7.0.2
BitShares blockchain node software and command-line wallet software
Public Member Functions | List of all members
graphene::db::index Class Referenceabstract

abstract base class for accessing objects indexed in various ways. More...

#include <index.hpp>

Inheritance diagram for graphene::db::index:
graphene::db::generic_index< T, boost::multi_index_container< T, indexed_by< ordered_unique< tag< by_id >, member< object, object_id_type, &object::id > > > > > graphene::db::generic_index< ObjectType, MultiIndexType > graphene::db::simple_index< T > graphene::db::sparse_index< T > graphene::db::primary_index< graphene::db::generic_index >

Public Member Functions

virtual ~index ()=default
 
virtual uint8_t object_space_id () const =0
 
virtual uint8_t object_type_id () const =0
 
virtual object_id_type get_next_id () const =0
 
virtual void use_next_id ()=0
 
virtual void set_next_id (object_id_type id)=0
 
virtual const objectload (const std::vector< char > &data)=0
 
virtual const objectinsert (object &&obj)=0
 
virtual const objectcreate (const std::function< void(object &)> &constructor)=0
 
virtual void open (const fc::path &db)=0
 
virtual void save (const fc::path &db)=0
 
virtual const objectfind (object_id_type id) const =0
 
const objectget (object_id_type id) const
 
virtual void modify (const object &obj, const std::function< void(object &)> &)=0
 
virtual void remove (const object &obj)=0
 
template<typename Object , typename Lambda >
void modify (const Object &obj, const Lambda &l)
 
virtual void inspect_all_objects (std::function< void(const object &)> inspector) const =0
 
virtual void add_observer (const std::shared_ptr< index_observer > &)=0
 
virtual void object_from_variant (const fc::variant &var, object &obj, uint32_t max_depth) const =0
 
virtual void object_default (object &obj) const =0
 

Detailed Description

abstract base class for accessing objects indexed in various ways.

All indexes assume that there exists an object ID space that will grow forever in a seqential manner. These IDs are used to identify the index, type, and instance of the object.

Items in an index can only be modified via a call to modify and all references to objects outside of that callback are const references.

Most implementations will probably be some form of boost::multi_index_container which means that they can covnert a reference to an object to an iterator. When at all possible save a pointer/reference to your objects rather than constantly looking them up by ID.

Definition at line 70 of file index.hpp.

Constructor & Destructor Documentation

◆ ~index()

virtual graphene::db::index::~index ( )
virtualdefault

Member Function Documentation

◆ add_observer()

virtual void graphene::db::index::add_observer ( const std::shared_ptr< index_observer > &  )
pure virtual

◆ create()

virtual const object& graphene::db::index::create ( const std::function< void(object &)> &  constructor)
pure virtual

◆ find()

virtual const object* graphene::db::index::find ( object_id_type  id) const
pure virtual

◆ get()

const object& graphene::db::index::get ( object_id_type  id) const
inline

This version will automatically check for nullptr and throw an exception if the object ID could not be found.

Definition at line 110 of file index.hpp.

◆ get_next_id()

virtual object_id_type graphene::db::index::get_next_id ( ) const
pure virtual

◆ insert()

virtual const object& graphene::db::index::insert ( object &&  obj)
pure virtual

◆ inspect_all_objects()

virtual void graphene::db::index::inspect_all_objects ( std::function< void(const object &)>  inspector) const
pure virtual

◆ load()

virtual const object& graphene::db::index::load ( const std::vector< char > &  data)
pure virtual

◆ modify() [1/2]

template<typename Object , typename Lambda >
void graphene::db::index::modify ( const Object &  obj,
const Lambda &  l 
)
inline

When forming your lambda to modify obj, it is natural to have Object& be the signature, but that is not compatible with the type erasue required by the virtual method. This method provides a helper to wrap the lambda in a form compatible with the virtual modify call.

Note
Lambda should have the signature: void(Object&)

Definition at line 127 of file index.hpp.

◆ modify() [2/2]

virtual void graphene::db::index::modify ( const object obj,
const std::function< void(object &)> &   
)
pure virtual

◆ object_default()

virtual void graphene::db::index::object_default ( object obj) const
pure virtual

◆ object_from_variant()

virtual void graphene::db::index::object_from_variant ( const fc::variant var,
object obj,
uint32_t  max_depth 
) const
pure virtual

◆ object_space_id()

virtual uint8_t graphene::db::index::object_space_id ( ) const
pure virtual

◆ object_type_id()

virtual uint8_t graphene::db::index::object_type_id ( ) const
pure virtual

◆ open()

virtual void graphene::db::index::open ( const fc::path db)
pure virtual

Opens the index loading objects from a file

Implemented in graphene::db::primary_index< graphene::db::generic_index >.

◆ remove()

virtual void graphene::db::index::remove ( const object obj)
pure virtual

◆ save()

virtual void graphene::db::index::save ( const fc::path db)
pure virtual

◆ set_next_id()

virtual void graphene::db::index::set_next_id ( object_id_type  id)
pure virtual

◆ use_next_id()

virtual void graphene::db::index::use_next_id ( )
pure virtual

The documentation for this class was generated from the following file: