比特股ID


template<uint8_t SpaceID, uint8_t TypeID, typename T = object>
struct object_id
{
typedef T type;
static const uint8_t space_id = SpaceID;
static const uint8_t type_id = TypeID;

object_id(){}
object_id( unsigned_int i ):instance(i){}
explicit object_id( uint64_t i ):instance(i)
{
FC_ASSERT( (i >> 48) == 0 );
}
object_id( object_id_type id ):instance(id.instance())
{
}

friend object_id operator+(const object_id a, int64_t delta ) { return object_id( uint64_t(a.instance.value+delta) ); }
friend object_id operator+(const object_id a, int delta ) { return object_id( uint64_t(a.instance.value+delta) ); }

operator object_id_type()const { return object_id_type( SpaceID, TypeID, instance.value ); }
explicit operator uint64_t()const { return object_id_type( *this ).number; }

template<typename DB>
const T& operator()(const DB& db)const { return db.get(*this); }

friend bool operator == ( const object_id& a, const object_id& b ) { return a.instance == b.instance; }
friend bool operator != ( const object_id& a, const object_id& b ) { return a.instance != b.instance; }
friend bool operator == ( const object_id_type& a, const object_id& b ) { return a == object_id_type(b); }
friend bool operator != ( const object_id_type& a, const object_id& b ) { return a != object_id_type(b); }
friend bool operator == ( const object_id& b, const object_id_type& a ) { return a == object_id_type(b); }
friend bool operator != ( const object_id& b, const object_id_type& a ) { return a != object_id_type(b); }

friend bool operator < ( const object_id& a, const object_id& b ) { return a.instance.value < b.instance.value; }
friend bool operator > ( const object_id& a, const object_id& b ) { return a.instance.value > b.instance.value; }

friend size_t hash_value( object_id v ) { return std::hash<uint64_t>()(v.instance.value); }

unsigned_int instance;
};


object_id由space_id,type_id及unsigned_int组成,则这个unsigned_int实际上是一个结构体,它用于存储T


struct unsigned_int {
unsigned_int( uint32_t v = 0 ):value(v){}

template<typename T>
unsigned_int( T v ):value(v){}

//operator uint32_t()const { return value; }
//operator uint64_t()const { return value; }

template<typename T>
operator T()const { return static_cast<T>(value); }

unsigned_int& operator=( int32_t v ) { value = v; return *this; }

uint32_t value;

friend bool operator==( const unsigned_int& i, const uint32_t& v ) { return i.value == v; }
friend bool operator==( const uint32_t& i, const unsigned_int& v ) { return i == v.value; }
friend bool operator==( const unsigned_int& i, const unsigned_int& v ) { return i.value == v.value; }

friend bool operator!=( const unsigned_int& i, const uint32_t& v ) { return i.value != v; }
friend bool operator!=( const uint32_t& i, const unsigned_int& v ) { return i != v.value; }
friend bool operator!=( const unsigned_int& i, const unsigned_int& v ) { return i.value != v.value; }

friend bool operator<( const unsigned_int& i, const uint32_t& v ) { return i.value < v; }
friend bool operator<( const uint32_t& i, const unsigned_int& v ) { return i < v.value; }
friend bool operator<( const unsigned_int& i, const unsigned_int& v ) { return i.value < v.value; }

friend bool operator>=( const unsigned_int& i, const uint32_t& v ) { return i.value >= v; }
friend bool operator>=( const uint32_t& i, const unsigned_int& v ) { return i >= v.value; }
friend bool operator>=( const unsigned_int& i, const unsigned_int& v ) { return i.value >= v.value; }
};



object_id_type中的num由space_id(char),type_id(char),space_type(6bit)组成

space id:
relative_protocol_ids = 0,
protocol_ids = 1,
implementation_ids = 2

type id:
1.正常情况下的type id
enum object_type
{
null_object_type, 0
base_object_type,1
account_object_type,2
asset_object_type,3
force_settlement_object_type,4
committee_member_object_type,5
witness_object_type,6
limit_order_object_type,7
call_order_object_type,8
custom_object_type,9
proposal_object_type,10
operation_history_object_type,11
withdraw_permission_object_type,12
vesting_balance_object_type,13
worker_object_type,14
balance_object_type,15
OBJECT_TYPE_COUNT ///< Sentry value which contains the number of different object types
};

2.如果space_id为2(implementation_ids),则type_id
enum impl_object_type
{
impl_global_property_object_type, 0
impl_dynamic_global_property_object_type, 1
impl_reserved0_object_type, 2 // formerly index_meta_object_type, TODO: delete me
impl_asset_dynamic_data_type, 3
impl_asset_bitasset_data_type, 4
impl_account_balance_object_type, 5
impl_account_statistics_object_type, 6
impl_transaction_object_type, 7
impl_block_summary_object_type, 8
impl_account_transaction_history_object_type, 9
impl_blinded_balance_object_type, 10
impl_chain_property_object_type, 11
impl_witness_schedule_object_type, 12
impl_budget_record_object_type, 13
impl_special_authority_object_type, 14
impl_buyback_object_type, 15
impl_fba_accumulator_object_type, 16
impl_collateral_bid_object_type 17
};

3.数据对象基本都是由space_id,type_id来构建索引
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值