CatapultServer
v0.5.0.1 (Elephant)
|
Go to the documentation of this file.
27 namespace catapult {
namespace model {
30 template<
typename TEntity>
104 for (
auto offset : offsets)
110 std::memcpy(
m_buffer.data(), pData, dataSize);
127 auto pBufferShared = std::make_shared<decltype(m_buffer)>(std::move(
m_buffer));
130 for (
auto offset : offsets) {
131 auto pEntity = reinterpret_cast<TEntity*>(&(*pBufferShared)[offset]);
132 entities[i++] = std::shared_ptr<TEntity>(pEntity, [pBufferShared](
const auto*) {});
148 offsets[i++] = static_cast<size_t>(reinterpret_cast<const uint8_t*>(pEntity) -
data());
174 std::vector<std::shared_ptr<TEntity>>
entities(1);
200 for (
auto& entity : range)
206 std::vector<std::shared_ptr<TEntity>> allEntities;
210 auto rangeEntities = range.detachSubRangeEntities();
213 std::make_move_iterator(rangeEntities.begin()),
214 std::make_move_iterator(rangeEntities.end()));
222 std::vector<EntityRange> copyRanges;
224 copyRanges.push_back(range.copySubRange());
232 for (
const auto& range : ranges)
266 std::vector<size_t> offsets(numElements);
267 for (
auto i = 0u; i < numElements; ++i)
268 offsets[i] = i *
sizeof(TEntity);
270 auto range =
EntityRange(SingleBufferRange(numElements *
sizeof(TEntity), offsets));
272 *ppRangeData = range.m_singleBufferRange.data();
281 std::memcpy(pRangeData, pData, range.totalSize());
288 return EntityRange(SingleBufferRange(pData, dataSize, offsets));
293 return EntityRange(SingleEntityRange(std::move(pEntity)));
320 template<
typename TIterator,
typename TIteratorEntity>
342 return !(*
this == rhs);
398 template<
typename TIterator>
400 return iterator<TIterator, const value_type>(current);
403 template<
typename TIterator>
405 return iterator<TIterator, value_type>(current);
471 return range.detachSubRangeEntities();
476 return const_cast<EntityRange&>(*this).subRange();
491 auto entities =
subRange.detachEntities();
497 template<
typename TFunc>
499 return const_cast<EntityRange&>(*this).activeSubRangeAction(func);
502 template<
typename TFunc>
523 template<
typename TEntity>
525 auto lhsIter = lhs.
cbegin();
526 auto rhsIter = rhs.
cbegin();
529 while (lhs.
cend() != lhsIter && rhs.
cend() != rhsIter) {
530 if (*lhsIter != *rhsIter)
auto cbegin() const
Returns a const iterator that represents the first entity.
Definition: EntityRange.h:410
auto & entities()
Definition: EntityRange.h:78
MultiBufferRange copy() const
Definition: EntityRange.h:221
SubRange & operator=(SubRange &&rhs)
Definition: EntityRange.h:53
reference operator*() const
Returns a reference to the current entity.
Definition: EntityRange.h:374
MultiBufferRange()
Definition: EntityRange.h:193
void requireContiguousData() const
Definition: EntityRange.h:457
std::vector< uint8_t > m_buffer
Definition: EntityRange.h:154
static EntityRange FromEntity(std::unique_ptr< TEntity > &&pEntity)
Creates an entity range around a single entity (pEntity).
Definition: EntityRange.h:292
auto cend() const
Returns a const iterator that represents one past the last entity.
Definition: EntityRange.h:415
Definition: EntityRange.h:191
const SubRange & subRange() const
Definition: EntityRange.h:475
std::vector< std::shared_ptr< TEntity > > detachEntities()
Definition: EntityRange.h:124
constexpr auto & entities() const
Definition: EntityRange.h:73
size_t m_numBytes
Definition: EntityRange.h:88
static EntityRange CopyRange(const EntityRange &rhs)
Creates an entity range by making a copy of an existing range rhs.
Definition: EntityRange.h:464
auto detachSubRangeEntities()
Definition: EntityRange.h:489
EntityRange(SingleBufferRange &&subRange)
Definition: EntityRange.h:250
std::remove_const_t< TIteratorEntity > value_type
Definition: EntityRange.h:324
auto * data()
Definition: EntityRange.h:451
std::shared_ptr< TEntity > m_pSingleEntity
Definition: EntityRange.h:184
SubRange()
Definition: EntityRange.h:40
static std::vector< std::shared_ptr< TEntity > > ExtractEntitiesFromRange(EntityRange &&range)
Definition: EntityRange.h:470
pointer operator->() const
Returns a pointer to the current entity.
Definition: EntityRange.h:379
SingleBufferRange(size_t dataSize, const std::vector< size_t > &offsets)
Definition: EntityRange.h:101
std::vector< std::shared_ptr< TEntity > > detachEntities()
Definition: EntityRange.h:205
std::vector< std::shared_ptr< TEntity > > detachEntities()
Definition: EntityRange.h:173
Definition: EntityRange.h:38
bool empty() const
Gets a value indicating whether or not this range is empty.
Definition: EntityRange.h:303
KeyType value_type
Definition: EntityRange.h:33
friend class MultiBufferRange
Definition: EntityRange.h:514
reference operator*()
Returns a reference to the current entity.
Definition: EntityRange.h:384
std::bidirectional_iterator_tag iterator_category
Definition: EntityRange.h:327
auto end()
Returns an iterator that represents one past the last entity.
Definition: EntityRange.h:435
pointer operator->()
Returns a pointer to the current entity.
Definition: EntityRange.h:389
std::vector< EntityRange > m_ranges
Definition: EntityRange.h:239
Represents a range of entities.
Definition: EntityRange.h:31
iterator operator--(int)
Advances the iterator to the previous position.
Definition: EntityRange.h:366
std::vector< size_t > generateOffsets() const
Definition: EntityRange.h:144
auto end() const
Returns a const iterator that represents one past the last entity.
Definition: EntityRange.h:425
static EntityRange CopyFixed(const uint8_t *pData, size_t numElements)
Creates an entity range around numElements fixed size elements pointed to by pData.
Definition: EntityRange.h:278
auto begin() const
Returns a const iterator that represents the first entity.
Definition: EntityRange.h:420
SingleEntityRange(std::unique_ptr< TEntity > &&pEntity)
Definition: EntityRange.h:166
bool operator!=(const iterator &rhs) const
Returns true if this iterator and rhs are not equal.
Definition: EntityRange.h:341
SingleBufferRange copy() const
Definition: EntityRange.h:139
iterator & operator++()
Advances the iterator to the next position.
Definition: EntityRange.h:347
static auto make_const_iterator(TIterator current)
Definition: EntityRange.h:399
typename TIterator::difference_type difference_type
Definition: EntityRange.h:323
Definition: EntityRange.h:161
SubRange(size_t numBytes)
Definition: EntityRange.h:43
static EntityRange PrepareFixed(size_t numElements, uint8_t **ppRangeData=nullptr)
Definition: EntityRange.h:265
EntityRange(SingleEntityRange &&subRange)
Definition: EntityRange.h:254
static EntityRange CopyVariable(const uint8_t *pData, size_t dataSize, const std::vector< size_t > &offsets)
Definition: EntityRange.h:287
static EntityRange MergeRanges(std::vector< EntityRange > &&ranges)
Merges all ranges into a single range.
Definition: EntityRange.h:297
static auto make_iterator(TIterator current)
Definition: EntityRange.h:404
EntityRange()
Creates an empty entity range.
Definition: EntityRange.h:246
SubRange & subRange()
Definition: EntityRange.h:479
size_t size() const
Definition: EntityRange.h:65
auto begin()
Returns an iterator that represents the first entity.
Definition: EntityRange.h:430
SubRange(SubRange &&rhs)
Definition: EntityRange.h:46
bool operator==(const iterator &rhs) const
Returns true if this iterator and rhs are equal.
Definition: EntityRange.h:336
size_t size() const
Gets the size of this range.
Definition: EntityRange.h:308
const auto * data() const
Definition: EntityRange.h:444
size_t totalSize() const
Gets the total size of the range in bytes.
Definition: EntityRange.h:313
iterator(TIterator current)
Creates an iterator around current.
Definition: EntityRange.h:331
iterator & operator--()
Advances the iterator to the previous position.
Definition: EntityRange.h:360
A class that can be moved but not copied.
Definition: NonCopyable.h:43
iterator operator++(int)
Advances the iterator to the next position.
Definition: EntityRange.h:353
static size_t CalculateTotalSize(const std::vector< EntityRange > &ranges)
Definition: EntityRange.h:230
TIterator m_current
Definition: EntityRange.h:394
TIteratorEntity & reference
Definition: EntityRange.h:326
auto copySubRange() const
Definition: EntityRange.h:485
#define CATAPULT_THROW_RUNTIME_ERROR(MESSAGE)
Macro used to throw a catapult runtime error.
Definition: exceptions.h:167
uint8_t * data()
Definition: EntityRange.h:114
SingleBufferRange(const uint8_t *pData, size_t dataSize, const std::vector< size_t > &offsets)
Definition: EntityRange.h:108
Definition: EntityRange.h:96
MultiBufferRange(std::vector< EntityRange > &&ranges)
Definition: EntityRange.h:196
auto activeSubRangeAction(TFunc func) const
Definition: EntityRange.h:498
Entity range iterator.
Definition: EntityRange.h:321
size_t FindFirstDifferenceIndex(const EntityRange< TEntity > &lhs, const EntityRange< TEntity > &rhs)
Compares two entity ranges (lhs and rhs) and returns the index of the first non-equal element.
Definition: EntityRange.h:524
Definition: AddressExtractionExtension.cpp:28
void reset()
Definition: EntityRange.h:82
const uint8_t * data() const
Definition: EntityRange.h:119
constexpr size_t totalSize() const
Definition: EntityRange.h:69
SingleBufferRange()
Definition: EntityRange.h:98
SingleBufferRange copy() const
Definition: EntityRange.h:179
TIteratorEntity * pointer
Definition: EntityRange.h:325
EntityRange(MultiBufferRange &&subRange)
Definition: EntityRange.h:258
std::vector< TEntity * > m_entities
Definition: EntityRange.h:89
MultiBufferRange m_multiBufferRange
Definition: EntityRange.h:519
SingleBufferRange m_singleBufferRange
Definition: EntityRange.h:517
SingleEntityRange()
Definition: EntityRange.h:163
SingleEntityRange m_singleEntityRange
Definition: EntityRange.h:518
auto activeSubRangeAction(TFunc func)
Definition: EntityRange.h:503
constexpr bool empty() const
Definition: EntityRange.h:61