BitShares-Core  5.0.0
BitShares blockchain implementation and command-line interface 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 ()
 
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 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 71 of file index.hpp.

Constructor & Destructor Documentation

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

Definition at line 74 of file index.hpp.

Member Function Documentation

virtual void graphene::db::index::add_observer ( const shared_ptr< index_observer > &  )
pure virtual
virtual const object& graphene::db::index::create ( const std::function< void(object &)> &  constructor)
pure virtual
virtual const object* graphene::db::index::find ( object_id_type  id) const
pure virtual
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 111 of file index.hpp.

virtual object_id_type graphene::db::index::get_next_id ( ) const
pure virtual
virtual const object& graphene::db::index::insert ( object &&  obj)
pure virtual
virtual void graphene::db::index::inspect_all_objects ( std::function< void(const object &)>  inspector) const
pure virtual
virtual const object& graphene::db::index::load ( const std::vector< char > &  data)
pure virtual
virtual void graphene::db::index::modify ( const object obj,
const std::function< void(object &)> &   
)
pure virtual
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 128 of file index.hpp.

virtual void graphene::db::index::object_default ( object obj) const
pure virtual
virtual void graphene::db::index::object_from_variant ( const fc::variant var,
object obj,
uint32_t  max_depth 
) const
pure virtual
virtual uint8_t graphene::db::index::object_space_id ( ) const
pure virtual
virtual uint8_t graphene::db::index::object_type_id ( ) const
pure virtual
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 >.

virtual void graphene::db::index::remove ( const object obj)
pure virtual
virtual void graphene::db::index::save ( const fc::path db)
pure virtual
virtual void graphene::db::index::set_next_id ( object_id_type  id)
pure virtual
virtual void graphene::db::index::use_next_id ( )
pure virtual

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