Skip to content

Commit

Permalink
Ref bitshares#1506: Add object_downcast_t
Browse files Browse the repository at this point in the history
Allows the more concise expression `object_downcast_t<xyz>` instead of
the old `typename object_downcast<xyz>::type`
  • Loading branch information
nathanielhourt committed Apr 26, 2019
1 parent 7609ff9 commit efa47d2
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
8 changes: 4 additions & 4 deletions libraries/db/include/graphene/db/object_database.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,13 @@ namespace graphene { namespace db {
}

template<uint8_t SpaceID, uint8_t TypeID>
auto find( object_id<SpaceID,TypeID> id )const -> const typename object_downcast<decltype(id)>::type* {
return find<typename object_downcast<decltype(id)>::type>(id);
auto find( object_id<SpaceID,TypeID> id )const -> const object_downcast_t<decltype(id)>* {
return find<object_downcast_t<decltype(id)>>(id);
}

template<uint8_t SpaceID, uint8_t TypeID>
auto get( object_id<SpaceID,TypeID> id )const -> const typename object_downcast<decltype(id)>::type& {
return get<typename object_downcast<decltype(id)>::type>(id);
auto get( object_id<SpaceID,TypeID> id )const -> const object_downcast_t<decltype(id)>& {
return get<object_downcast_t<decltype(id)>>(id);
}

template<typename IndexType>
Expand Down
2 changes: 2 additions & 0 deletions libraries/db/include/graphene/db/object_id.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ namespace graphene { namespace db {
template<> \
struct object_downcast<graphene::db::object_id<OBJECT::space_id, OBJECT::type_id>> { using type = OBJECT; }; \
} }
template<typename ObjectID>
using object_downcast_t = typename object_downcast<ObjectID>::type;

template<uint8_t SpaceID, uint8_t TypeID>
struct object_id
Expand Down
4 changes: 2 additions & 2 deletions libraries/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -533,10 +533,10 @@ class wallet_api_impl
}

template<typename ID>
typename graphene::db::object_downcast<ID>::type get_object(ID id)const
typename graphene::db::object_downcast_t<ID>get_object(ID id)const
{
auto ob = _remote_db->get_objects({id}).front();
return ob.template as<typename graphene::db::object_downcast<ID>::type>( GRAPHENE_MAX_NESTED_OBJECTS );
return ob.template as<graphene::db::object_downcast_t<ID>>( GRAPHENE_MAX_NESTED_OBJECTS );
}

void set_operation_fees( signed_transaction& tx, const fee_schedule& s )
Expand Down
2 changes: 1 addition & 1 deletion programs/js_operation_serializer/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ struct js_name<graphene::db::object_id<S,T> >
static std::string name(){
using namespace graphene::db;
return "protocol_id_type \"" +
remove_namespace(fc::get_typename<typename object_downcast<object_id<S,T>>::type>::name()) +
remove_namespace(fc::get_typename<object_downcast_t<object_id<S,T>>>::name()) +
"\"";
};
};
Expand Down

0 comments on commit efa47d2

Please sign in to comment.