26 #include <boost/multi_index_container.hpp> 27 #include <boost/multi_index/member.hpp> 28 #include <boost/multi_index/ordered_index.hpp> 29 #include <boost/multi_index/mem_fun.hpp> 33 using boost::multi_index_container;
42 template<
typename ObjectType,
typename MultiIndexType>
49 const object&
insert(
object&& obj )
override 51 assert(
nullptr != dynamic_cast<ObjectType*>(&obj) );
52 auto insert_result = _indices.insert( std::move( static_cast<ObjectType&>(obj) ) );
54 "Could not insert object, most likely a uniqueness constraint was violated" );
55 return *insert_result.first;
58 const object&
create(
const std::function<
void(
object&)>& constructor )
override 61 item.
id = get_next_id();
63 auto insert_result = _indices.insert( std::move(item) );
65 "Could not create object! Most likely a uniqueness constraint is violated.");
67 return *insert_result.first;
70 void modify(
const object& obj,
const std::function<
void(
object&)>& m )
override 72 assert(
nullptr != dynamic_cast<const ObjectType*>(&obj));
74 auto ok = _indices.modify(_indices.iterator_to(static_cast<const ObjectType&>(obj)),
75 [&m, &exc](ObjectType& o)
mutable {
79 exc = std::current_exception();
80 elog(
"Exception while modifying object: ${e} -- object may be corrupted",
83 exc = std::current_exception();
84 elog(
"Unknown exception while modifying object");
89 std::rethrow_exception(exc);
90 FC_ASSERT(ok,
"Could not modify object, most likely an index constraint was violated");
93 void remove(
const object& obj )
override 95 _indices.erase( _indices.iterator_to( static_cast<const ObjectType&>(obj) ) );
100 static_assert(std::is_same<typename MultiIndexType::key_type, object_id_type>::value,
101 "First index of MultiIndexType MUST be object_id_type!");
102 auto itr = _indices.find(
id );
103 if( itr == _indices.end() )
return nullptr;
110 for(
const auto& ptr : _indices )
132 member<object, object_id_type, &object::id>
void inspect_all_objects(std::function< void(const object &)> inspector) const override
const object * find(object_id_type id) const override
const index_type & indices() const
Used to generate a useful error report when an exception is thrown.At each level in the stack where t...
const object & create(const std::function< void(object &)> &constructor) override
An index type for objects which may be deleted.
void modify(const object &obj, const std::function< void(object &)> &m) override
MultiIndexType index_type
std::shared_ptr< exception > exception_ptr
#define FC_CAPTURE_AND_RETHROW(...)
#define FC_ASSERT(TEST,...)
Checks a condition and throws an assert_exception if the test is FALSE.
const object & insert(object &&obj) override
abstract base class for accessing objects indexed in various ways.