Skip to content

Commit

Permalink
Fix build for SPS branch with MIRA Runtime Adapter. Currently failing…
Browse files Browse the repository at this point in the history
… one test.
  • Loading branch information
mvandeberg committed May 15, 2019
1 parent 696e8a1 commit ca1b343
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 52 deletions.
13 changes: 13 additions & 0 deletions libraries/chain/include/steem/chain/multi_index_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ using boost::multi_index::member;
using boost::multi_index::composite_key;
using boost::multi_index::composite_key_compare;
using boost::multi_index::const_mem_fun;

template< class Iterator >
inline boost::reverse_iterator< Iterator > make_reverse_iterator( Iterator iterator )
{
return boost::reverse_iterator< Iterator >( iterator );
}

#else
template< typename... Args >
using multi_index_container = mira::multi_index_adapter< Args... >;
Expand All @@ -59,6 +66,12 @@ class mira_type : public ::mira::multi_index_container< T1, T2, T3 >
using mira::multi_index_container< T1, T2, T3 >::multi_index_container;
};

template< class Iterator >
inline Iterator make_reverse_iterator( Iterator iterator )
{
return iterator.reverse();
}

#endif

} } // steem::chain
6 changes: 5 additions & 1 deletion libraries/chain/include/steem/chain/util/sps_helper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ class sps_helper

calc();

return obj_perf.done ? end() : proposalIndex. template erase< ByProposalType >( proposal );
//return obj_perf.done ? end() : proposalIndex. template erase< ByProposalType >( proposal );
if( obj_perf.done )
return end();

return proposalIndex. template erase< ByProposalType >( proposal );
}
}

Expand Down
15 changes: 12 additions & 3 deletions libraries/chainbase/include/chainbase/chainbase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,12 +261,21 @@ namespace chainbase {
_indices.erase( _indices.iterator_to( obj ) );
}

template < typename IndexedBy >
typename MultiIndexType::template index_iterator<IndexedBy>::type erase(typename MultiIndexType::template index_iterator<IndexedBy>::type objI) {
auto& idx = _indices.template get< IndexedBy >();
#ifdef ENABLE_MIRA
//((bip::managed_mapped_file*)nullptr)
template< typename ByIndex, typename IterType >
IterType erase( IterType objI ) {
on_remove( *objI );
return _indices.template mutable_get< ByIndex >().erase( objI );
}
#else
template< typename ByIndex >
typename MultiIndexType::template index_iterator<ByIndex>::type erase(typename MultiIndexType::template index_iterator<ByIndex>::type objI) {
auto& idx = _indices.template get< ByIndex >();
on_remove(*objI);
return idx.erase(objI);
}
#endif

template<typename CompatibleKey>
const value_type* find( CompatibleKey&& key )const {
Expand Down
68 changes: 39 additions & 29 deletions libraries/mira/include/mira/index_adapter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,38 @@ struct index_adapter
(((typename MultiIndexAdapterType::mira_type*)nullptr)->template get<IndexedBy>()) ) >::type mira_type;
typedef typename std::remove_reference< decltype(
(((typename MultiIndexAdapterType::bmic_type*)nullptr)->template get<IndexedBy>()) ) >::type bmic_type;

typedef decltype( (((mira_type*)nullptr)->begin()) ) mira_iter_type;
typedef decltype( (((bmic_type*)nullptr)->begin()) ) bmic_iter_type;

typedef iterator_adapter<
value_type,
decltype( (((mira_type*)nullptr)->begin()) ),
decltype( (((mira_type*)nullptr)->rbegin()) ),
decltype( (((bmic_type*)nullptr)->begin()) ),
decltype( (((bmic_type*)nullptr)->rbegin()) ) > iter_type;
typedef iter_type rev_iter_type;
mira_iter_type,
bmic_iter_type > iter_type;
typedef boost::reverse_iterator< iter_type > rev_iter_type;

typedef boost::variant< mira_type*, bmic_type* > index_variant;

private:
index_adapter() {}

struct erase_visitor : public boost::static_visitor< iter_type >
{
iter_type& _pos;

erase_visitor( iter_type& pos ) : _pos( pos ) {}

iter_type operator()( mira_type* idx_ptr ) const
{
return iter_type( idx_ptr->erase( _pos.template get< mira_iter_type >() ) );
}

iter_type operator()( bmic_type* idx_ptr ) const
{
return iter_type( idx_ptr->erase( _pos.template get< bmic_iter_type >() ) );
}
};

public:
index_adapter( const mira_type& mira_index )
{
Expand All @@ -50,12 +69,17 @@ struct index_adapter
_index( std::move( other._index ) )
{}

iter_type erase( iter_type position )
{
return boost::apply_visitor( erase_visitor( position ), _index );
}

iter_type iterator_to( const value_type& v )const
{
return boost::apply_visitor(
[&]( auto* index ){ return iter_type( index->iterator_to( v ) ); },
_index
);
[&]( auto* index ){ return iter_type( index->iterator_to( v ) ); },
_index
);
}

template< typename CompatibleKey >
Expand Down Expand Up @@ -118,18 +142,12 @@ struct index_adapter

rev_iter_type rbegin()const
{
return boost::apply_visitor(
[]( auto* index ){ return rev_iter_type( index->rbegin() ); },
_index
);
return boost::make_reverse_iterator( end() );
}

rev_iter_type rend()const
{
return boost::apply_visitor(
[]( auto* index ){ return rev_iter_type( index->rend() ); },
_index
);
return boost::make_reverse_iterator( begin() );
}

bool empty()const
Expand Down Expand Up @@ -163,11 +181,9 @@ struct multi_index_adapter

typedef iterator_adapter<
value_type,
decltype( (((mira_type*)nullptr)->begin()) ),
decltype( (((mira_type*)nullptr)->rbegin()) ),
decltype( (((bmic_type*)nullptr)->begin()) ),
decltype( (((bmic_type*)nullptr)->rbegin()) ) > iter_type;
typedef iter_type rev_iter_type;
mira_iter_type,
bmic_iter_type > iter_type;
typedef boost::reverse_iterator< iter_type > rev_iter_type;

typedef typename bmic_type::allocator_type allocator_type;

Expand Down Expand Up @@ -429,18 +445,12 @@ struct multi_index_adapter

rev_iter_type rbegin()const
{
return boost::apply_visitor(
[]( auto& index ){ return rev_iter_type( index.rbegin() ); },
_index
);
return boost::make_reverse_iterator( end() );
}

rev_iter_type rend()const
{
return boost::apply_visitor(
[]( auto& index ){ return rev_iter_type( index.rend() ); },
_index
);
return boost::make_reverse_iterator( begin() );
}

bool open( const boost::filesystem::path& p, const boost::any& o )
Expand Down
26 changes: 14 additions & 12 deletions libraries/mira/include/mira/iterator_adapter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ class iterator_adapter :

template< typename t > struct type {};

iter_variant _itr;

public:
iter_variant _itr;

iterator_adapter() {}

template< typename T >
Expand Down Expand Up @@ -90,16 +90,6 @@ class iterator_adapter :
);
}

bool operator ==( const iterator_adapter& other )
{
return _itr == other._itr;
}

bool operator !=( const iterator_adapter& other )
{
return _itr != other._itr;
}

template< typename T >
iterator_adapter& operator =( T& rhs )
{
Expand Down Expand Up @@ -162,4 +152,16 @@ class iterator_adapter :
}
};

template< typename ValueType, typename... Iters >
bool operator ==( const iterator_adapter< ValueType, Iters... >& lhs, const iterator_adapter< ValueType, Iters... >& rhs )
{
return lhs._itr == rhs._itr;
}

template< typename ValueType, typename... Iters >
bool operator !=( const iterator_adapter< ValueType, Iters... >& lhs, const iterator_adapter< ValueType, Iters... >& rhs )
{
return !( lhs == rhs );
}

} // mira
8 changes: 1 addition & 7 deletions libraries/plugins/apis/database_api/database_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,6 @@ class database_api_impl
template< typename ValueType >
static bool filter_default( const ValueType& r ) { return true; }

template< class Iterator >
inline boost::reverse_iterator< Iterator > make_reverse_iterator( Iterator iterator )
{
return boost::reverse_iterator< Iterator >( iterator );
}

template<typename IndexType, typename OrderType, typename StartType, typename ResultType, typename OnPushType, typename FilterType>
void iterate_results(
StartType start,
Expand All @@ -123,7 +117,7 @@ class database_api_impl
}
else if( direction == descending )
{
auto itr = make_reverse_iterator( idx.lower_bound( start ) );
auto itr = boost::make_reverse_iterator( idx.lower_bound( start ) );
auto end = idx.rend();

while( result.size() < limit && itr != end )
Expand Down

0 comments on commit ca1b343

Please sign in to comment.