orca-sim
Public Member Functions | Private Attributes | List of all members
orcasim::modeling::SignalSet< T > Class Template Reference

The SignalSet class models a generic set of busses of type T. More...

#include <SignalSet.hpp>

Inheritance diagram for orcasim::modeling::SignalSet< T >:
orcasim::base::UntimedModel orcasim::base::Model

Public Member Functions

 SignalSet (std::string name, uint32_t nsig)
 Constructor. More...
 
 ~SignalSet ()
 Destructor. More...
 
Signal< T > * GetSignal (uint32_t index)
 Get the a signal from the set. More...
 
void MapTo (MemoryType *mptr, MemoryAddr addr)
 Maps the signal set to a given memory address. More...
 
a name that identifies the model, advisably not empty.

Default ctor.

std::string GetName ()
 Getter method for the <_name> field. More...
 
void SetName (std::string s)
 Setter method for the <_name> field. More...
 

Private Attributes

uint32_t _num_signals
 number of signals in the set. More...
 
MemoryAddr _mem_addr
 memory position of the first signal. More...
 
MemoryType_mem_ptr
 
Signal< T > ** _signals
 a pointer to the first signal. More...
 
std::string _t_name
 an optional name to identify this model during runtime More...
 

Detailed Description

template<typename T>
class orcasim::modeling::SignalSet< T >

The SignalSet class models a generic set of busses of type T.

Definition at line 47 of file SignalSet.hpp.

Constructor & Destructor Documentation

§ SignalSet()

template<typename T >
SignalSet::SignalSet ( std::string  name,
uint32_t  nsig 
)

Constructor.

Creates a new SignalSet.

Parameters
nameAn arbitrary name for the instance.
nsigNumber of signals to be created

Definition at line 46 of file SignalSet.cpp.

46  : UntimedModel(name) {
47  // set internal variables
48  _num_signals = nsig;
50 
51  // create a new vector of signals. Signals are no mapped yep, use MapTo.
52  for (uint32_t i = 0; i < _num_signals; i++)
53  _signals[i] = new Signal<T>(this->GetName() + "." + std::to_string(i));
54 }
The Signal class models a generic bus of width equals to the sizeof(T)
Definition: Signal.hpp:45
UntimedModel(std::string name)
Default Ctor.
uint32_t _num_signals
number of signals in the set.
Definition: SignalSet.hpp:50
std::string GetName()
Getter method for the <_name> field.
Definition: Model.cpp:34
Signal< T > ** _signals
a pointer to the first signal.
Definition: SignalSet.hpp:59

§ ~SignalSet()

template<typename T >
SignalSet::~SignalSet ( )

Destructor.

Note
DO NOT free _t_ptr by any means as this pointer must be freed by the class which allocated the space.

Definition at line 58 of file SignalSet.cpp.

58  {
59  delete[] _signals;
60 }
Signal< T > ** _signals
a pointer to the first signal.
Definition: SignalSet.hpp:59

Member Function Documentation

§ GetName()

std::string Model::GetName ( )
inherited

Getter method for the <_name> field.

Definition at line 34 of file Model.cpp.

34  {
35  return _name;
36 }
std::string _name
A name for the model.
Definition: Model.hpp:47

§ GetSignal()

template<typename T >
Signal< T > * SignalSet::GetSignal ( uint32_t  index)

Get the a signal from the set.

Parameters
indexThe identifier of the signal to be returned.
Returns
A pointer to the requested signal.

Definition at line 83 of file SignalSet.cpp.

83  {
84  if (index > _num_signals - 1 || index < 0) {
85  std::cout << "warn: requested signals is out of the bounds of the set"
86  << std::endl;
87  return nullptr;
88  }
89 
90  return _signals[index];
91 }
uint32_t _num_signals
number of signals in the set.
Definition: SignalSet.hpp:50
Signal< T > ** _signals
a pointer to the first signal.
Definition: SignalSet.hpp:59

§ MapTo()

template<typename T >
void SignalSet::MapTo ( MemoryType mptr,
MemoryAddr  addr 
)

Maps the signal set to a given memory address.

Signals' addresses are generated by incrementing the address of the first signal.

Parameters
mptrPointer to the memory location to be mapped
addrAddress to the set to the first signals

Definition at line 64 of file SignalSet.cpp.

64  {
65  MemoryAddr address = addr;
66  MemoryType* memtype = memptr;
67 
68  // set the proper address to each signal and map
69  for (uint32_t i = 0; i < _num_signals; i++) {
70  _signals[i]->SetAddress(address);
71  _signals[i]->MapTo(memtype, address, false);
72 
73  address += sizeof(T);
74 
75  // caution, pointer arithmetic here
76  for (uint32_t j = 0; j < sizeof(T) / sizeof(MemoryType); j++)
77  memtype++;
78  }
79 }
#define MemoryAddr
Definition: MemoryType.hpp:34
uint32_t _num_signals
number of signals in the set.
Definition: SignalSet.hpp:50
Signal< T > ** _signals
a pointer to the first signal.
Definition: SignalSet.hpp:59
#define MemoryType
Definition: MemoryType.hpp:33

§ SetName()

void Model::SetName ( std::string  s)
inherited

Setter method for the <_name> field.

Parameters
sValue to be set

Definition at line 38 of file Model.cpp.

38  {
39  _name = name;
40 }
std::string _name
A name for the model.
Definition: Model.hpp:47

Member Data Documentation

§ _mem_addr

template<typename T >
MemoryAddr orcasim::modeling::SignalSet< T >::_mem_addr
private

memory position of the first signal.

Other signals' positions are generated by incrementing this index by sizeof(T)

Definition at line 54 of file SignalSet.hpp.

§ _mem_ptr

template<typename T >
MemoryType* orcasim::modeling::SignalSet< T >::_mem_ptr
private

Definition at line 55 of file SignalSet.hpp.

§ _num_signals

template<typename T >
uint32_t orcasim::modeling::SignalSet< T >::_num_signals
private

number of signals in the set.

Cannot be changed runtime.

Definition at line 50 of file SignalSet.hpp.

§ _signals

template<typename T >
Signal<T>** orcasim::modeling::SignalSet< T >::_signals
private

a pointer to the first signal.

An array will be instantiated to store signals in that pointer.

Definition at line 59 of file SignalSet.hpp.

§ _t_name

template<typename T >
std::string orcasim::modeling::SignalSet< T >::_t_name
private

an optional name to identify this model during runtime

Definition at line 62 of file SignalSet.hpp.


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