INET Framework for OMNeT++/OMNEST
inet::SequenceChunk Class Reference

This class represents data with an ordered list of consecutive chunks. More...

#include <SequenceChunk.h>

Inheritance diagram for inet::SequenceChunk:
inet::Chunk inet::IPrintableObject inet::IRegionTaggedObject

Public Member Functions

Constructors, destructors and duplication related functions
 SequenceChunk ()
 
 SequenceChunk (const SequenceChunk &other)
 
 SequenceChunk (const std::deque< Ptr< const Chunk >> &chunks)
 
virtual SequenceChunkdup () const override
 
virtual const Ptr< ChunkdupShared () const override
 Returns a mutable copy of this chunk in a shared pointer. More...
 
virtual void parsimPack (cCommBuffer *buffer) const override
 
virtual void parsimUnpack (cCommBuffer *buffer) override
 
virtual void forEachChild (cVisitor *v) override
 
virtual bool containsSameData (const Chunk &other) const override
 Returns true if the two chunks represent the same binary data. More...
 
Field accessor functions
const std::deque< Ptr< const Chunk > > & getChunks () const
 
void setChunks (const std::deque< Ptr< const Chunk >> &chunks)
 
Overridden flag functions
virtual bool isComplete () const override
 
virtual bool isIncomplete () const override
 
virtual bool isCorrect () const override
 
virtual bool isIncorrect () const override
 
virtual bool isProperlyRepresented () const override
 
virtual bool isImproperlyRepresented () const override
 
Iteration related functions
virtual void moveIterator (Iterator &iterator, b length) const override
 
virtual void seekIterator (Iterator &iterator, b offset) const override
 
Filling with data related functions
virtual bool canInsertAtFront (const Ptr< const Chunk > &chunk) const override
 Returns true if this chunk is capable of representing the result. More...
 
virtual bool canInsertAtBack (const Ptr< const Chunk > &chunk) const override
 Returns true if this chunk is capable of representing the result. More...
 
Removing data related functions
virtual bool canRemoveAtFront (b length) const override
 Returns true if this chunk is capable of representing the result. More...
 
virtual bool canRemoveAtBack (b length) const override
 Returns true if this chunk is capable of representing the result. More...
 
Querying data related functions
virtual ChunkType getChunkType () const override
 Returns the type of this chunk as an enum member. More...
 
virtual b getChunkLength () const override
 Returns the length of data represented by this chunk. More...
 
virtual bool isEmpty () const override
 Returns true if this chunk contains no data. More...
 
virtual std::ostream & printToStream (std::ostream &stream, int level, int evFlags=0) const override
 Prints an optinally formatted human readable string representation of the data present in this chunk to the given stream. More...
 
- Public Member Functions inherited from inet::Chunk
 Chunk ()
 
 Chunk (const Chunk &other)
 
virtual bool isMutable () const
 
virtual bool isImmutable () const
 
virtual void markImmutable ()
 
void markMutableIfExclusivelyOwned ()
 
virtual void markIncomplete ()
 
virtual void markIncorrect ()
 
virtual void markImproperlyRepresented ()
 
virtual bool canInsertAt (const Ptr< const Chunk > &chunk, b offset) const
 Returns true if this chunk is capable of representing the result. More...
 
void insertAtFront (const Ptr< const Chunk > &chunk)
 Inserts the provided chunk at the beginning of this chunk. More...
 
void insertAtBack (const Ptr< const Chunk > &chunk)
 Inserts the provided chunk at the end of this chunk. More...
 
void insertAt (const Ptr< const Chunk > &chunk, b offset)
 Inserts the provided chunk into this chunk. More...
 
virtual bool canRemoveAt (b offset, b length) const
 Returns true if this chunk is capable of representing the result. More...
 
void removeAtFront (b length)
 Removes the requested part from the beginning of this chunk. More...
 
void removeAtBack (b length)
 Removes the requested part from the end of this chunk. More...
 
void removeAt (b offset, b length)
 Removes the requested part from this chunk. More...
 
int getChunkId () const
 Returns the sequentially assigned id. More...
 
const Ptr< Chunksimplify () const
 Returns the simplified representation of this chunk eliminating all potential redundancies. More...
 
const Ptr< Chunkpeek (const Iterator &iterator, b length=unspecifiedLength, int flags=0) const
 Returns the designated part of the data represented by this chunk in its default representation. More...
 
template<typename T >
bool has (const Iterator &iterator, b length=unspecifiedLength) const
 Returns whether if the designated part of the data is available in the requested representation. More...
 
template<typename T >
const Ptr< Tpeek (const Iterator &iterator, b length=unspecifiedLength, int flags=0) const
 Returns the designated part of the data represented by this chunk in the requested representation. More...
 
virtual SharingRegionTagSetgetRegionTags () override
 Returns all region tags. More...
 
int getNumTags () const
 Returns the number of chunk tags. More...
 
const Ptr< const TagBasegetTag (int index) const
 Returns the chunk tag at the given index. More...
 
void clearTags (b offset=b(0), b length=b(-1))
 Clears the set of chunk tags in the given region. More...
 
void copyTags (const Chunk &source, b sourceOffset=b(0), b offset=b(0), b length=b(-1))
 Copies the set of chunk tags from the source region to the provided region. More...
 
template<typename T >
const Ptr< const TfindTag (b offset=b(0), b length=b(-1)) const
 Returns the chunk tag for the provided type and range, or returns nullptr if no such chunk tag is found. More...
 
template<typename T >
const Ptr< const TgetTag (b offset=b(0), b length=b(-1)) const
 Returns the chunk tag for the provided type and range, or throws an exception if no such chunk tag is found. More...
 
template<typename T >
void mapAllTags (b offset, b length, std::function< void(b, b, const Ptr< const T > &)> f) const
 Maps all tags in the provided range to to the function. More...
 
template<typename T >
void mapAllTagsForUpdate (b offset, b length, std::function< void(b, b, const Ptr< T > &)> f)
 Maps all tags in the provided range to to the function. More...
 
template<typename T >
std::vector< SharingRegionTagSet::RegionTag< const T > > getAllTags (b offset=b(0), b length=b(-1)) const
 Returns all chunk tags for the provided type and range in a detached vector of region tags. More...
 
template<typename T >
std::vector< SharingRegionTagSet::RegionTag< T > > getAllTagsForUpdate (b offset=b(0), b length=b(-1))
 Returns all chunk tags for the provided type and range in a detached vector of region tags. More...
 
template<typename T >
const Ptr< TaddTag (b offset=b(0), b length=b(-1))
 Returns a newly added chunk tag for the provided type and range, or throws an exception if such a chunk tag is already present. More...
 
template<typename T >
const Ptr< TaddTagIfAbsent (b offset=b(0), b length=b(-1))
 Returns a newly added chunk tag for the provided type and range if absent, or returns the chunk tag that is already present. More...
 
template<typename T >
std::vector< SharingRegionTagSet::RegionTag< T > > addTagsWhereAbsent (b offset=b(0), b length=b(-1))
 Returns the newly added chunk tags for the provided type and range where the tag is absent. More...
 
template<typename T >
const Ptr< TremoveTag (b offset, b length)
 Removes the chunk tag for the provided type and range, or throws an exception if no such chunk tag is found. More...
 
template<typename T >
const Ptr< TremoveTagIfPresent (b offset, b length)
 Removes the chunk tag for the provided type and range if present, or returns nullptr if no such chunk tag is found. More...
 
template<typename T >
std::vector< SharingRegionTagSet::RegionTag< T > > removeTagsWherePresent (b offset, b length)
 Removes and returns all chunk tags for the provided type and range. More...
 
virtual std::ostream & printFieldsToStream (std::ostream &stream, int level, int evFlags=0) const
 Prints an optinally formatted human readable string representation of the feilds of this chunk to the given stream. More...
 
virtual std::string str () const override
 Returns a human readable string representation of the data present in this chunk. More...
 
- Public Member Functions inherited from inet::IPrintableObject
virtual ~IPrintableObject ()
 
virtual std::string printToString () const
 
virtual std::string printToString (int level, int evFlags=0) const
 
virtual std::string getInfoStringRepresentation (int evFlags=0) const
 
virtual std::string getDetailStringRepresentation (int evFlags=0) const
 
virtual std::string getDebugStringRepresentation (int evFlags=0) const
 
virtual std::string getTraceStringRepresentation (int evFlags=0) const
 
virtual std::string getCompleteStringRepresentation (int evFlags=0) const
 

Protected Member Functions

int getNumChunks () const
 
const ChunkgetChunk (int i) const
 
int getElementIndex (bool isForward, int index) const
 
const Ptr< const Chunk > & getElementChunk (const Iterator &iterator) const
 
void doInsertChunkAtFront (const Ptr< const Chunk > &chunk)
 
void doInsertSliceChunkAtFront (const Ptr< const SliceChunk > &chunk)
 
void doInsertSequenceChunkAtFront (const Ptr< const SequenceChunk > &chunk)
 
void doInsertChunkAtBack (const Ptr< const Chunk > &chunk)
 
void doInsertSliceChunkAtBack (const Ptr< const SliceChunk > &chunk)
 
void doInsertSequenceChunkAtBack (const Ptr< const SequenceChunk > &chunk)
 
std::deque< Ptr< const Chunk > > dupChunks () const
 
virtual const Ptr< ChunkpeekUnchecked (PeekPredicate predicate, PeekConverter converter, const Iterator &iterator, b length, int flags) const override
 
virtual void doInsertAtFront (const Ptr< const Chunk > &chunk) override
 
virtual void doInsertAtBack (const Ptr< const Chunk > &chunk) override
 
virtual void doRemoveAtFront (b length) override
 
virtual void doRemoveAtBack (b length) override
 
- Protected Member Functions inherited from inet::Chunk
int getBinDumpNumLines () const
 
int getHexDumpNumLines () const
 
const char * getBinDumpLine (int index)
 
const char * getHexDumpLine (int index)
 
const SharingRegionTagSet::RegionTag< TagBase > & _getTag (int index) const
 
void checkMutable () const
 
virtual void handleChange ()
 
virtual void doInsertAt (const Ptr< const Chunk > &chunk, b offset)
 
virtual void doRemoveAt (b offset, b length)
 
template<typename T >
const Ptr< TpeekConverted (const Iterator &iterator, b length, int flags) const
 
template<typename T >
const Ptr< TcheckPeekResult (const Ptr< T > &chunk, int flags) const
 

Static Protected Member Functions

static const Ptr< ChunkconvertChunk (const std::type_info &typeInfo, const Ptr< Chunk > &chunk, b offset, b length, int flags)
 
- Static Protected Member Functions inherited from inet::Chunk
static const Ptr< ChunkconvertChunk (const std::type_info &typeInfo, const Ptr< Chunk > &chunk, b offset, b length, int flags)
 Creates a new chunk of the given type that represents the designated part of the provided chunk. More...
 

Protected Attributes

std::deque< Ptr< const Chunk > > chunks
 The list of chunks that make up this chunk. More...
 
- Protected Attributes inherited from inet::Chunk
int id
 The id is automatically assigned sequentially during construction. More...
 
int flags
 The boolean chunk flags are merged into a single integer. More...
 
SharingRegionTagSet regionTags
 The set of region tags attached to the data represented by this chunk. More...
 
const typedef Ptr< Chunk >(* PeekConverter )(const Ptr< Chunk > &chunk, const Chunk::Iterator &iterator, b length, int flags)
 

Friends

class Chunk
 
class SequenceChunkDescriptor
 

Additional Inherited Members

- Public Types inherited from inet::Chunk
enum  ChunkType {
  CT_EMPTY, CT_BITCOUNT, CT_BITS, CT_BYTECOUNT,
  CT_BYTES, CT_SLICE, CT_ENCRYPTED, CT_CPACKET,
  CT_SEQUENCE, CT_FIELDS
}
 This enum is used to avoid std::dynamic_cast and dynamicPtrCast. More...
 
enum  PeekFlag {
  PF_ALLOW_NULLPTR = (1 << 0), PF_ALLOW_EMPTY = (1 << 1), PF_ALLOW_INCOMPLETE = (1 << 2), PF_ALLOW_INCORRECT = (1 << 3),
  PF_ALLOW_IMPROPERLY_REPRESENTED = (1 << 4), PF_ALLOW_SERIALIZATION = (1 << 5), PF_ALLOW_ALL = -1
}
 This enum specifies bitmasks for the flags argument of various peek functions. More...
 
- Public Types inherited from inet::IPrintableObject
enum  PrintLevel {
  PRINT_LEVEL_TRACE, PRINT_LEVEL_DEBUG, PRINT_LEVEL_DETAIL, PRINT_LEVEL_INFO,
  PRINT_LEVEL_COMPLETE = INT_MIN
}
 
enum  PrintFlag { PRINT_FLAG_FORMATTED = (1 << 0), PRINT_FLAG_MULTILINE = (1 << 1) }
 
- Static Public Member Functions inherited from inet::Chunk
static void serialize (MemoryOutputStream &stream, const Ptr< const Chunk > &chunk, b offset=b(0), b length=b(-1))
 Serializes a chunk into the given stream. More...
 
static const Ptr< Chunkdeserialize (MemoryInputStream &stream, const std::type_info &typeInfo)
 Deserializes a chunk from the given stream. More...
 
- Static Public Attributes inherited from inet::Chunk
static const b unspecifiedLength = b(-std::numeric_limits<int64_t>::max())
 
static bool enableImplicitChunkSerialization = false
 Peeking some part into a chunk that requires automatic serialization will throw an exception when implicit chunk serialization is disabled. More...
 
static int nextId = 0
 
- Protected Types inherited from inet::Chunk
enum  ChunkFlag { CF_IMMUTABLE = (1 << 0), CF_INCOMPLETE = (1 << 1), CF_INCORRECT = (1 << 2), CF_IMPROPERLY_REPRESENTED = (1 << 3) }
 This enum specifies bitmasks for the flags field of Chunk. More...
 
typedef bool(* PeekPredicate) (const Ptr< Chunk > &)
 

Detailed Description

This class represents data with an ordered list of consecutive chunks.

It's used by the Chunk API implementation internally to manage compound data. User code should not directly instantiate this class.

Constructor & Destructor Documentation

◆ SequenceChunk() [1/3]

inet::SequenceChunk::SequenceChunk ( )
16  :
17  Chunk()
18 {
19 }

◆ SequenceChunk() [2/3]

inet::SequenceChunk::SequenceChunk ( const SequenceChunk other)
21  :
22  Chunk(other),
23  chunks(other.isImmutable() ? other.chunks : other.dupChunks())
24 {
25 }

◆ SequenceChunk() [3/3]

inet::SequenceChunk::SequenceChunk ( const std::deque< Ptr< const Chunk >> &  chunks)
27  :
28  Chunk(),
29  chunks(chunks)
30 {
31 }

Member Function Documentation

◆ canInsertAtBack()

virtual bool inet::SequenceChunk::canInsertAtBack ( const Ptr< const Chunk > &  chunk) const
inlineoverridevirtual

Returns true if this chunk is capable of representing the result.

Reimplemented from inet::Chunk.

104 { return true; }

◆ canInsertAtFront()

virtual bool inet::SequenceChunk::canInsertAtFront ( const Ptr< const Chunk > &  chunk) const
inlineoverridevirtual

Returns true if this chunk is capable of representing the result.

Reimplemented from inet::Chunk.

103 { return true; }

◆ canRemoveAtBack()

virtual bool inet::SequenceChunk::canRemoveAtBack ( b  length) const
inlineoverridevirtual

Returns true if this chunk is capable of representing the result.

Reimplemented from inet::Chunk.

110 { return true; }

◆ canRemoveAtFront()

virtual bool inet::SequenceChunk::canRemoveAtFront ( b  length) const
inlineoverridevirtual

Returns true if this chunk is capable of representing the result.

Reimplemented from inet::Chunk.

109 { return true; }

◆ containsSameData()

bool inet::SequenceChunk::containsSameData ( const Chunk other) const
overridevirtual

Returns true if the two chunks represent the same binary data.

The two chunks are compared without serialization, and the method is allowed to return false if the result cannot be determined correctly. Tags and other metadata are ignored in the comparison.

Reimplemented from inet::Chunk.

61 {
62  if (&other == this)
63  return true;
64  else if (!Chunk::containsSameData(other))
65  return false;
66  else {
67  auto otherSequence = static_cast<const SequenceChunk *>(&other);
68  if (chunks.size() != otherSequence->chunks.size())
69  return false;
70  else {
71  for (auto i = 0; i < (int)chunks.size(); i++)
72  if (!chunks[i]->containsSameData(*otherSequence->chunks[i].get()))
73  return false;
74  return true;
75  }
76  }
77 }

◆ convertChunk()

const Ptr< Chunk > inet::SequenceChunk::convertChunk ( const std::type_info &  typeInfo,
const Ptr< Chunk > &  chunk,
b  offset,
b  length,
int  flags 
)
staticprotected
129 {
130  auto chunkLength = chunk->getChunkLength();
131  CHUNK_CHECK_IMPLEMENTATION(b(0) <= offset && offset <= chunkLength);
132  CHUNK_CHECK_IMPLEMENTATION(length <= chunkLength - offset);
133  auto sequenceChunk = makeShared<SequenceChunk>();
134  auto sliceChunk = makeShared<SliceChunk>(chunk, offset, length < b(0) ? std::min(-length, chunkLength - offset) : length);
135  sliceChunk->markImmutable();
136  sequenceChunk->insertAtBack(sliceChunk);
137  return sequenceChunk;
138 }

◆ doInsertAtBack()

void inet::SequenceChunk::doInsertAtBack ( const Ptr< const Chunk > &  chunk)
overrideprotectedvirtual

Reimplemented from inet::Chunk.

342 {
343  if (chunk->getChunkType() == CT_SLICE)
344  doInsertSliceChunkAtBack(staticPtrCast<const SliceChunk>(chunk));
345  else if (chunk->getChunkType() == CT_SEQUENCE)
346  doInsertSequenceChunkAtBack(staticPtrCast<const SequenceChunk>(chunk));
347  else
348  doInsertChunkAtBack(chunk);
349 }

◆ doInsertAtFront()

void inet::SequenceChunk::doInsertAtFront ( const Ptr< const Chunk > &  chunk)
overrideprotectedvirtual

Reimplemented from inet::Chunk.

281 {
282  if (chunk->getChunkType() == CT_SLICE)
283  doInsertSliceChunkAtFront(staticPtrCast<const SliceChunk>(chunk));
284  else if (chunk->getChunkType() == CT_SEQUENCE)
285  doInsertSequenceChunkAtFront(staticPtrCast<const SequenceChunk>(chunk));
286  else
287  doInsertChunkAtFront(chunk);
288 }

◆ doInsertChunkAtBack()

void inet::SequenceChunk::doInsertChunkAtBack ( const Ptr< const Chunk > &  chunk)
protected
291 {
292  CHUNK_CHECK_USAGE(chunk->isImmutable(), "chunk is mutable");
293  CHUNK_CHECK_USAGE(chunk->getChunkLength() > b(0), "chunk is empty");
294  if (chunks.empty())
295  chunks.push_back(chunk);
296  else {
297  const auto& lastChunk = chunks.back();
298  if (!lastChunk->canInsertAtBack(chunk))
299  chunks.push_back(chunk);
300  else {
301  const auto& mutableLastChunk = makeExclusivelyOwnedMutableChunk(lastChunk);
302  mutableLastChunk->insertAtBack(chunk);
303  mutableLastChunk->markImmutable();
304  chunks.back() = mutableLastChunk->simplify();
305  }
306  }
307 }

Referenced by doInsertAtBack(), doInsertSequenceChunkAtBack(), and doInsertSliceChunkAtBack().

◆ doInsertChunkAtFront()

void inet::SequenceChunk::doInsertChunkAtFront ( const Ptr< const Chunk > &  chunk)
protected
229 {
230  CHUNK_CHECK_USAGE(chunk->isImmutable(), "chunk is mutable");
231  CHUNK_CHECK_USAGE(chunk->getChunkLength() > b(0), "chunk is empty");
232  if (chunks.empty())
233  chunks.push_front(chunk);
234  else {
235  const auto& firstChunk = chunks.front();
236  if (!firstChunk->canInsertAtFront(chunk))
237  chunks.push_front(chunk);
238  else {
239  const auto& mutableFirstChunk = makeExclusivelyOwnedMutableChunk(firstChunk);
240  mutableFirstChunk->insertAtFront(chunk);
241  mutableFirstChunk->markImmutable();
242  chunks.front() = mutableFirstChunk->simplify();
243  }
244  }
245 }

Referenced by doInsertAtFront(), doInsertSequenceChunkAtFront(), and doInsertSliceChunkAtFront().

◆ doInsertSequenceChunkAtBack()

void inet::SequenceChunk::doInsertSequenceChunkAtBack ( const Ptr< const SequenceChunk > &  chunk)
protected
336 {
337  for (const auto& elementChunk : chunk->chunks)
338  doInsertChunkAtBack(elementChunk);
339 }

Referenced by doInsertAtBack().

◆ doInsertSequenceChunkAtFront()

void inet::SequenceChunk::doInsertSequenceChunkAtFront ( const Ptr< const SequenceChunk > &  chunk)
protected
275 {
276  for (auto it = chunk->chunks.rbegin(); it != chunk->chunks.rend(); it++)
278 }

Referenced by doInsertAtFront().

◆ doInsertSliceChunkAtBack()

void inet::SequenceChunk::doInsertSliceChunkAtBack ( const Ptr< const SliceChunk > &  chunk)
protected
310 {
311  if (sliceChunk->getChunk()->getChunkType() == CT_SEQUENCE) {
312  auto sequenceChunk = staticPtrCast<SequenceChunk>(sliceChunk->getChunk());
313  b offset = b(0);
314  b sliceChunkBegin = sliceChunk->getOffset();
315  b sliceChunkEnd = sliceChunk->getOffset() + sliceChunk->getChunkLength();
316  for (const auto& elementChunk : sequenceChunk->chunks) {
317  b chunkBegin = offset;
318  b chunkEnd = offset + elementChunk->getChunkLength();
319  if (sliceChunkBegin <= chunkBegin && chunkEnd <= sliceChunkEnd)
320  doInsertChunkAtBack(elementChunk);
321  else if (chunkBegin < sliceChunkBegin && sliceChunkEnd < chunkEnd)
322  doInsertChunkAtBack(staticPtrCast<const Chunk>(elementChunk->peek(sliceChunkBegin - chunkBegin, sliceChunkEnd - sliceChunkBegin)));
323  else if (chunkBegin < sliceChunkBegin && sliceChunkBegin < chunkEnd)
324  doInsertChunkAtBack(staticPtrCast<const Chunk>(elementChunk->peek(sliceChunkBegin - chunkBegin, chunkEnd - sliceChunkBegin)));
325  else if (chunkBegin < sliceChunkEnd && sliceChunkEnd < chunkEnd)
326  doInsertChunkAtBack(staticPtrCast<const Chunk>(elementChunk->peek(b(0), sliceChunkEnd - chunkBegin)));
327  // otherwise the element chunk is out of the slice, therefore it's ignored
328  offset += elementChunk->getChunkLength();
329  }
330  }
331  else
332  doInsertChunkAtBack(staticPtrCast<const Chunk>(sliceChunk));
333 }

Referenced by doInsertAtBack().

◆ doInsertSliceChunkAtFront()

void inet::SequenceChunk::doInsertSliceChunkAtFront ( const Ptr< const SliceChunk > &  chunk)
protected
248 {
249  if (sliceChunk->getChunk()->getChunkType() == CT_SEQUENCE) {
250  auto sequenceChunk = staticPtrCast<SequenceChunk>(sliceChunk->getChunk());
251  b offset = sequenceChunk->getChunkLength();
252  b sliceChunkBegin = sliceChunk->getOffset();
253  b sliceChunkEnd = sliceChunk->getOffset() + sliceChunk->getChunkLength();
254  for (auto it = sequenceChunk->chunks.rbegin(); it != sequenceChunk->chunks.rend(); it++) {
255  const auto& elementChunk = *it;
256  offset -= elementChunk->getChunkLength();
257  b chunkBegin = offset;
258  b chunkEnd = offset + elementChunk->getChunkLength();
259  if (sliceChunkBegin <= chunkBegin && chunkEnd <= sliceChunkEnd)
260  doInsertChunkAtFront(elementChunk);
261  else if (chunkBegin < sliceChunkBegin && sliceChunkEnd < chunkEnd)
262  doInsertChunkAtFront(staticPtrCast<const Chunk>(elementChunk->peek(sliceChunkBegin - chunkBegin, sliceChunkEnd - sliceChunkBegin)));
263  else if (chunkBegin < sliceChunkBegin && sliceChunkBegin < chunkEnd)
264  doInsertChunkAtFront(staticPtrCast<const Chunk>(elementChunk->peek(sliceChunkBegin - chunkBegin, chunkEnd - sliceChunkBegin)));
265  else if (chunkBegin < sliceChunkEnd && sliceChunkEnd < chunkEnd)
266  doInsertChunkAtFront(staticPtrCast<const Chunk>(elementChunk->peek(b(0), sliceChunkEnd - chunkBegin)));
267  // otherwise the element chunk is out of the slice, therefore it's ignored
268  }
269  }
270  else
271  doInsertChunkAtFront(staticPtrCast<const Chunk>(sliceChunk));
272 }

Referenced by doInsertAtFront().

◆ doRemoveAtBack()

void inet::SequenceChunk::doRemoveAtBack ( b  length)
overrideprotectedvirtual

Reimplemented from inet::Chunk.

372 {
373  auto it = chunks.rbegin();
374  while (it != chunks.rend()) {
375  auto chunk = *it;
376  b chunkLength = chunk->getChunkLength();
377  if (chunkLength <= length) {
378  it++;
379  length -= chunkLength;
380  if (length == b(0))
381  break;
382  }
383  else {
384  *it = chunk->peek(b(0), chunkLength - length);
385  break;
386  }
387  }
388  chunks.erase(it.base(), chunks.end());
389 }

◆ doRemoveAtFront()

void inet::SequenceChunk::doRemoveAtFront ( b  length)
overrideprotectedvirtual

Reimplemented from inet::Chunk.

352 {
353  auto it = chunks.begin();
354  while (it != chunks.end()) {
355  auto chunk = *it;
356  b chunkLength = chunk->getChunkLength();
357  if (chunkLength <= length) {
358  it++;
359  length -= chunkLength;
360  if (length == b(0))
361  break;
362  }
363  else {
364  *it = chunk->peek(length, chunkLength - length);
365  break;
366  }
367  }
368  chunks.erase(chunks.begin(), it);
369 }

◆ dup()

virtual SequenceChunk* inet::SequenceChunk::dup ( ) const
inlineoverridevirtual
67 { return new SequenceChunk(*this); }

◆ dupChunks()

std::deque< Ptr< const Chunk > > inet::SequenceChunk::dupChunks ( ) const
protected
141 {
142  std::deque<Ptr<const Chunk>> copies;
143  for (const auto& chunk : chunks)
144  copies.push_back(chunk->isImmutable() ? chunk : staticPtrCast<const Chunk>(chunk->dupShared()));
145  return copies;
146 }

◆ dupShared()

virtual const Ptr<Chunk> inet::SequenceChunk::dupShared ( ) const
inlineoverridevirtual

Returns a mutable copy of this chunk in a shared pointer.

Reimplemented from inet::Chunk.

68 { return makeShared<SequenceChunk>(*this); }

◆ forEachChild()

void inet::SequenceChunk::forEachChild ( cVisitor *  v)
overridevirtual

Reimplemented from inet::Chunk.

54 {
56  for (const auto& chunk : chunks)
57  v->visit(const_cast<Chunk *>(chunk.get()));
58 }

◆ getChunk()

const Chunk* inet::SequenceChunk::getChunk ( int  i) const
inlineprotected
35 { return chunks[i].get(); } // only for class descriptor

◆ getChunkLength()

b inet::SequenceChunk::getChunkLength ( ) const
overridevirtual

Returns the length of data represented by this chunk.

Implements inet::Chunk.

185 {
186  b length = b(0);
187  for (const auto& chunk : chunks) {
188  auto chunkLength = chunk->getChunkLength();
189  CHUNK_CHECK_IMPLEMENTATION(chunkLength > b(0));
190  length += chunkLength;
191  }
192  return length;
193 }

Referenced by moveIterator(), peekUnchecked(), and seekIterator().

◆ getChunks()

const std::deque<Ptr<const Chunk> >& inet::SequenceChunk::getChunks ( ) const
inline
79 { return chunks; }

◆ getChunkType()

virtual ChunkType inet::SequenceChunk::getChunkType ( ) const
inlineoverridevirtual

Returns the type of this chunk as an enum member.

This can be used to avoid expensive std::dynamic_cast and dynamicPtrCast operators.

Implements inet::Chunk.

115 { return CT_SEQUENCE; }

◆ getElementChunk()

const Ptr<const Chunk>& inet::SequenceChunk::getElementChunk ( const Iterator iterator) const
inlineprotected
38 { return chunks[getElementIndex(iterator.isForward(), iterator.getIndex())]; }

Referenced by moveIterator(), and peekUnchecked().

◆ getElementIndex()

int inet::SequenceChunk::getElementIndex ( bool  isForward,
int  index 
) const
inlineprotected
37 { return isForward ? index : chunks.size() - index - 1; }

Referenced by peekUnchecked(), and seekIterator().

◆ getNumChunks()

int inet::SequenceChunk::getNumChunks ( ) const
inlineprotected
34 { return chunks.size(); } // only for class descriptor

◆ isComplete()

virtual bool inet::SequenceChunk::isComplete ( ) const
inlineoverridevirtual

Reimplemented from inet::Chunk.

85 { return !isIncomplete(); }

◆ isCorrect()

virtual bool inet::SequenceChunk::isCorrect ( ) const
inlineoverridevirtual

Reimplemented from inet::Chunk.

88 { return !isIncorrect(); }

◆ isEmpty()

virtual bool inet::SequenceChunk::isEmpty ( ) const
inlineoverridevirtual

Returns true if this chunk contains no data.

Reimplemented from inet::Chunk.

117 { return chunks.size() != 0; }

◆ isImproperlyRepresented()

bool inet::SequenceChunk::isImproperlyRepresented ( ) const
overridevirtual

Reimplemented from inet::Chunk.

175 {
177  return true;
178  for (const auto& chunk : chunks)
179  if (chunk->isImproperlyRepresented())
180  return true;
181  return false;
182 }

◆ isIncomplete()

bool inet::SequenceChunk::isIncomplete ( ) const
overridevirtual

Reimplemented from inet::Chunk.

155 {
156  if (Chunk::isIncomplete())
157  return true;
158  for (const auto& chunk : chunks)
159  if (chunk->isIncomplete())
160  return true;
161  return false;
162 }

◆ isIncorrect()

bool inet::SequenceChunk::isIncorrect ( ) const
overridevirtual

Reimplemented from inet::Chunk.

165 {
166  if (Chunk::isIncorrect())
167  return true;
168  for (const auto& chunk : chunks)
169  if (chunk->isIncorrect())
170  return true;
171  return false;
172 }

◆ isProperlyRepresented()

virtual bool inet::SequenceChunk::isProperlyRepresented ( ) const
inlineoverridevirtual

Reimplemented from inet::Chunk.

91 { return !isImproperlyRepresented(); }

◆ moveIterator()

void inet::SequenceChunk::moveIterator ( Iterator iterator,
b  length 
) const
overridevirtual

Reimplemented from inet::Chunk.

220 {
221  iterator.setPosition(iterator.getPosition() + length);
222  if (iterator.getIndex() != -1 && iterator.getIndex() != (int)chunks.size() && getElementChunk(iterator)->getChunkLength() == length)
223  iterator.setIndex(iterator.getIndex() + 1);
224  else
225  iterator.setIndex(-1);
226 }

◆ parsimPack()

void inet::SequenceChunk::parsimPack ( cCommBuffer *  buffer) const
overridevirtual

Reimplemented from inet::Chunk.

34 {
35  Chunk::parsimPack(buffer);
36  buffer->pack(chunks.size());
37  for (const auto& chunk : chunks)
38  buffer->packObject(const_cast<Chunk *>(chunk.get()));
39 }

◆ parsimUnpack()

void inet::SequenceChunk::parsimUnpack ( cCommBuffer *  buffer)
overridevirtual

Reimplemented from inet::Chunk.

42 {
43  Chunk::parsimUnpack(buffer);
44  size_t size;
45  buffer->unpack(size);
46  chunks.clear();
47  for (size_t i = 0; i < size; i++) {
48  const auto& chunk = check_and_cast<Chunk *>(buffer->unpackObject())->shared_from_this();
49  chunks.push_back(chunk);
50  }
51 }

◆ peekUnchecked()

const Ptr< Chunk > inet::SequenceChunk::peekUnchecked ( PeekPredicate  predicate,
PeekConverter  converter,
const Iterator iterator,
b  length,
int  flags 
) const
overrideprotectedvirtual

Implements inet::Chunk.

80 {
81  b chunkLength = getChunkLength();
82  CHUNK_CHECK_USAGE(b(0) <= iterator.getPosition() && iterator.getPosition() <= chunkLength, "iterator is out of range");
83  // 1. peeking an empty part returns nullptr
84  if (length == b(0) || (iterator.getPosition() == chunkLength && length < b(0))) {
85  if (predicate == nullptr || predicate(nullptr))
87  }
88  // 2. peeking the whole part returns this chunk only if length is also specified
89  if (iterator.getPosition() == b(0) && length == chunkLength) {
90  auto result = const_cast<SequenceChunk *>(this)->shared_from_this();
91  if (predicate == nullptr || predicate(result))
92  return result;
93  }
94  // 3. peeking a part represented by an element chunk with its index returns that element chunk
95  if (iterator.getIndex() != -1 && iterator.getIndex() != (int)chunks.size()) {
96  // KLUDGE constPtrCast<Chunk>
97  const auto& chunk = constPtrCast<Chunk>(getElementChunk(iterator));
98  auto chunkLength = chunk->getChunkLength();
99  if (-length >= chunkLength || length == chunkLength) {
100  if (predicate == nullptr || predicate(chunk))
101  return chunk;
102  }
103  }
104  // 4. peeking a part represented by an element chunk returns part of that element chunk
105  b position = b(0);
106  for (size_t i = 0; i < chunks.size(); i++) {
107  // KLUDGE constPtrCast<Chunk>
108  const auto& chunk = constPtrCast<Chunk>(chunks[getElementIndex(iterator.isForward(), i)]);
109  b elementChunkLength = chunk->getChunkLength();
110  // 4.1 peeking the whole part of an element chunk returns that element chunk
111  if (iterator.getPosition() == position && (-length >= elementChunkLength || length == elementChunkLength)) {
112  if (predicate == nullptr || predicate(chunk))
113  return chunk;
114  }
115  // 4.2 peeking a part of an element chunk returns the part of that element chunk
116  if (position <= iterator.getPosition() && iterator.getPosition() < position + elementChunkLength &&
117  (-length >= elementChunkLength || iterator.getPosition() + length <= position + elementChunkLength))
118  return chunk->peekUnchecked(predicate, converter, Iterator(iterator.isForward(), iterator.getPosition() - position, -1), length, flags);
119  position += elementChunkLength;
120  }
121  // 5. peeking without conversion returns a SequenceChunk
122  if (converter == nullptr)
123  return peekConverted<SequenceChunk>(iterator, length, flags);
124  // 6. peeking with conversion
125  return converter(const_cast<SequenceChunk *>(this)->shared_from_this(), iterator, length, flags);
126 }

◆ printToStream()

std::ostream & inet::SequenceChunk::printToStream ( std::ostream &  stream,
int  level,
int  evFlags = 0 
) const
overridevirtual

Prints an optinally formatted human readable string representation of the data present in this chunk to the given stream.

Reimplemented from inet::Chunk.

392 {
393  stream << "[";
394  bool first = true;
395  for (const auto& chunk : chunks) {
396  if (!first)
397  stream << " | ";
398  else
399  first = false;
400  chunk->printToStream(stream, level + 1, evFlags);
401  }
402  return stream << "]";
403 }

◆ seekIterator()

void inet::SequenceChunk::seekIterator ( Iterator iterator,
b  offset 
) const
overridevirtual

Reimplemented from inet::Chunk.

196 {
197  CHUNK_CHECK_USAGE(b(0) <= offset && offset <= getChunkLength(), "offset is out of range");
198  iterator.setPosition(offset);
199  if (offset == b(0))
200  iterator.setIndex(0);
201  else {
202  b p = b(0);
203  for (size_t i = 0; i < chunks.size(); i++) {
204  const auto& chunk = chunks[getElementIndex(iterator.isForward(), i)];
205  p += chunk->getChunkLength();
206  if (p == offset) {
207  iterator.setIndex(i + 1);
208  return;
209  }
210  else if (p > offset) {
211  iterator.setIndex(-1);
212  return;
213  }
214  }
216  }
217 }

◆ setChunks()

void inet::SequenceChunk::setChunks ( const std::deque< Ptr< const Chunk >> &  chunks)
149 {
150  handleChange();
151  this->chunks = chunks;
152 }

Friends And Related Function Documentation

◆ Chunk

friend class Chunk
friend

◆ SequenceChunkDescriptor

friend class SequenceChunkDescriptor
friend

Member Data Documentation

◆ chunks


The documentation for this class was generated from the following files:
inet::SequenceChunk::doInsertChunkAtBack
void doInsertChunkAtBack(const Ptr< const Chunk > &chunk)
Definition: SequenceChunk.cc:290
CHUNK_CHECK_IMPLEMENTATION
#define CHUNK_CHECK_IMPLEMENTATION(condition)
Definition: Chunk.h:29
inet::Chunk::forEachChild
virtual void forEachChild(cVisitor *v) override
Definition: Chunk.cc:33
inet::Chunk::isIncorrect
virtual bool isIncorrect() const
Definition: Chunk.h:469
inet::SequenceChunk::doInsertSliceChunkAtBack
void doInsertSliceChunkAtBack(const Ptr< const SliceChunk > &chunk)
Definition: SequenceChunk.cc:309
inet::Chunk::containsSameData
virtual bool containsSameData(const Chunk &other) const
Returns true if the two chunks represent the same binary data.
Definition: Chunk.h:619
inet::makeExclusivelyOwnedMutableChunk
const Ptr< T > makeExclusivelyOwnedMutableChunk(const Ptr< const T > &chunk)
Definition: Chunk.h:860
inet::sctp::min
double min(const double a, const double b)
Returns the minimum of a and b.
Definition: SctpAssociation.h:261
inet::SequenceChunk::getChunkLength
virtual b getChunkLength() const override
Returns the length of data represented by this chunk.
Definition: SequenceChunk.cc:184
inet::SequenceChunk::isIncorrect
virtual bool isIncorrect() const override
Definition: SequenceChunk.cc:164
inet::Chunk::isIncomplete
virtual bool isIncomplete() const
Definition: Chunk.h:461
inet::Chunk::handleChange
virtual void handleChange()
Definition: Chunk.cc:53
inet::SequenceChunk::doInsertSequenceChunkAtFront
void doInsertSequenceChunkAtFront(const Ptr< const SequenceChunk > &chunk)
Definition: SequenceChunk.cc:274
inet::SequenceChunk::isImproperlyRepresented
virtual bool isImproperlyRepresented() const override
Definition: SequenceChunk.cc:174
inet::SequenceChunk::isIncomplete
virtual bool isIncomplete() const override
Definition: SequenceChunk.cc:154
CHUNK_CHECK_USAGE
#define CHUNK_CHECK_USAGE(condition, format,...)
Definition: Chunk.h:42
inet::SequenceChunk::doInsertChunkAtFront
void doInsertChunkAtFront(const Ptr< const Chunk > &chunk)
Definition: SequenceChunk.cc:228
inet::SequenceChunk::getElementChunk
const Ptr< const Chunk > & getElementChunk(const Iterator &iterator) const
Definition: SequenceChunk.h:38
inet::SequenceChunk::SequenceChunk
SequenceChunk()
Definition: SequenceChunk.cc:16
inet::SequenceChunk::getElementIndex
int getElementIndex(bool isForward, int index) const
Definition: SequenceChunk.h:37
inet::Chunk::parsimPack
virtual void parsimPack(cCommBuffer *buffer) const override
Definition: Chunk.cc:39
inet::units::values::b
value< int64_t, units::b > b
Definition: Units.h:1241
inet::evFlags
int evFlags
Definition: INETDefs.cc:12
inet::Chunk::flags
int flags
The boolean chunk flags are merged into a single integer.
Definition: Chunk.h:352
inet::Chunk::CT_SEQUENCE
@ CT_SEQUENCE
Definition: Chunk.h:270
inet::SequenceChunk::containsSameData
virtual bool containsSameData(const Chunk &other) const override
Returns true if the two chunks represent the same binary data.
Definition: SequenceChunk.cc:60
inet::SequenceChunk::chunks
std::deque< Ptr< const Chunk > > chunks
The list of chunks that make up this chunk.
Definition: SequenceChunk.h:31
inet::SequenceChunk::doInsertSequenceChunkAtBack
void doInsertSequenceChunkAtBack(const Ptr< const SequenceChunk > &chunk)
Definition: SequenceChunk.cc:335
inet::EmptyChunk::getEmptyChunk
static const Ptr< Chunk > getEmptyChunk(int flags)
Definition: EmptyChunk.h:48
inet::SequenceChunk::Chunk
friend class Chunk
Definition: SequenceChunk.h:24
inet::Chunk::parsimUnpack
virtual void parsimUnpack(cCommBuffer *buffer) override
Definition: Chunk.cc:46
inet::SequenceChunk::doInsertSliceChunkAtFront
void doInsertSliceChunkAtFront(const Ptr< const SliceChunk > &chunk)
Definition: SequenceChunk.cc:247
inet::Chunk::isImproperlyRepresented
virtual bool isImproperlyRepresented() const
Definition: Chunk.h:477
inet::Chunk::CT_SLICE
@ CT_SLICE
Definition: Chunk.h:267