CIRCT 24.0.0git
Loading...
Searching...
No Matches
esi::StructType Class Reference

Structs are an ordered collection of fields, each with a name and a type. More...

#include <Types.h>

Inheritance diagram for esi::StructType:
Collaboration diagram for esi::StructType:

Public Types

using FieldVector = std::vector<std::pair<std::string, const Type *>>
Public Types inherited from esi::Type
using ID = std::string

Public Member Functions

 StructType (const ID &id, const FieldVector &fields, bool reverse=true)
const FieldVector & getFields () const
std::ptrdiff_t getBitWidth () const override
void ensureValid (const std::any &obj) const override
 Ensure that a std::any object is valid for this type.
MutableBitVector serialize (const std::any &obj) const override
 Serialize an object to a MutableBitVector (LSB-first stream).
std::any deserialize (BitVector &data) const override
 Deserialize from a BitVector stream (LSB-first).
bool isReverse () const
std::any deserialize (const MessageData &data) const
Public Member Functions inherited from esi::Type
 Type (const ID &id)
virtual ~Type ()=default
ID getID () const
void setHWBitwidth (std::ptrdiff_t bw)
 Set from manifest JSON hwBitwidth.
std::any deserialize (const MessageData &data) const
std::optional< std::string > isValid (const std::any &obj) const
void dump (std::ostream &os, bool oneLine=false) const
std::string toString (bool oneLine=false) const

Private Attributes

FieldVector fields
bool reverse

Additional Inherited Members

Protected Attributes inherited from esi::Type
ID id
std::ptrdiff_t hwBitwidth = -1

Detailed Description

Structs are an ordered collection of fields, each with a name and a type.

Definition at line 264 of file Types.h.

Member Typedef Documentation

◆ FieldVector

using esi::StructType::FieldVector = std::vector<std::pair<std::string, const Type *>>

Definition at line 266 of file Types.h.

Constructor & Destructor Documentation

◆ StructType()

esi::StructType::StructType ( const ID & id,
const FieldVector & fields,
bool reverse = true )
inline

Definition at line 269 of file Types.h.

References fields, esi::Type::id, reverse, and esi::Type::Type().

Member Function Documentation

◆ deserialize() [1/2]

std::any esi::StructType::deserialize ( BitVector & data) const
overridevirtual

Deserialize from a BitVector stream (LSB-first).

Implementations consume bits from 'data' in-place (via logical right shifts) and return the reconstructed value. Remaining bits stay in 'data'.

Reimplemented from esi::Type.

Definition at line 374 of file Types.cpp.

References esi::Type::deserialize(), fields, isReverse(), and esi::Type::Type().

◆ deserialize() [2/2]

std::any esi::Type::deserialize ( const MessageData & data) const
inline

Definition at line 67 of file Types.h.

◆ ensureValid()

void esi::StructType::ensureValid ( const std::any & obj) const
overridevirtual

Ensure that a std::any object is valid for this type.

Throws std::runtime_error if the object is not valid.

Reimplemented from esi::Type.

Definition at line 325 of file Types.cpp.

References fields.

Referenced by serialize().

◆ getBitWidth()

std::optional< int64_t > StructType::getBitWidth ( ) const
inlineoverridevirtual

Reimplemented from esi::Type.

Definition at line 273 of file Types.h.

References getFields().

◆ getFields()

const FieldVector & esi::StructType::getFields ( ) const
inline

Definition at line 272 of file Types.h.

References fields.

Referenced by getBitWidth(), NB_MODULE(), and esi::ChannelPort::TranslationInfo::precomputeFrameInfo().

◆ isReverse()

bool esi::StructType::isReverse ( ) const
inline

◆ serialize()

MutableBitVector esi::StructType::serialize ( const std::any & obj) const
overridevirtual

Serialize an object to a MutableBitVector (LSB-first stream).

The object should be passed via std::any. Implementations append fields in the order they are iterated (the first serialized field occupies the least-significant bits of the result).

Reimplemented from esi::Type.

Definition at line 353 of file Types.cpp.

References ensureValid(), fields, isReverse(), esi::Type::serialize(), esi::Type::Type(), and esi::BitVector::width().

Member Data Documentation

◆ fields

◆ reverse

bool esi::StructType::reverse
private

Definition at line 297 of file Types.h.

Referenced by isReverse(), and StructType().


The documentation for this class was generated from the following files: