HAL
boolean_function_table_model.cpp
Go to the documentation of this file.
2 
6 
7 namespace hal {
8 
9 
10  /* ========================================================
11  * BooleanFunctionTableEntry - Superclass
12  * ========================================================*/
13 
15  {
16  mGateId = gateId;
18  }
19 
21  {
22  return mLeft;
23  }
24 
26  {
27  return mRight;
28  }
29 
31  return mGateId;
32  }
33 
35  {
36  return mType;
37  }
38 
39  /* ========================================================
40  * BooleanFunctionTableEntry - BooleanFunctionEntry
41  * ========================================================*/
42 
45  {
46  mLeft = functionName;
49  }
50 
52  {
53  //set the gateId to 0, indicating that this entry is an arbitrary boolean function
54  mLeft = functionName;
57  }
58 
60  {
61  return mBF;
62  }
63 
65  {
66  if(mGateId == 0)
67  return "";
68  else
70  }
71 
72  /* ========================================================
73  * BooleanFunctionTableEntry - CPBehaviorEntry
74  * ========================================================*/
75 
76  CPBehaviorEntry::CPBehaviorEntry(u32 gateId, std::pair<hal::AsyncSetResetBehavior, hal::AsyncSetResetBehavior> cPBehavior)
78  {
79  mLeft = "set_reset_behavior";
80  mRight = cPBehaviourToString(cPBehavior);
81  mCPBehavior =cPBehavior;
83  }
84 
85  std::pair<hal::AsyncSetResetBehavior, hal::AsyncSetResetBehavior> CPBehaviorEntry::getCPBehavior() const
86  {
87  return mCPBehavior;
88  }
89 
90  QString CPBehaviorEntry::cPBehaviourToString (std::pair<hal::AsyncSetResetBehavior, hal::AsyncSetResetBehavior> cPBehaviour)
91  {
92  static QMap<hal::AsyncSetResetBehavior, QString> cPBehaviourToString {
98  {hal::AsyncSetResetBehavior::undef, "Undefined"},
99  };
100  return QString(cPBehaviourToString[cPBehaviour.first] + ", " + cPBehaviourToString[cPBehaviour.second]);
101  }
102 
104  {
106  specificType = type;
107  mLeft = enumTypeToString();
108  mRight = stateVal;
109  }
110 
112  {
113  switch (specificType)
114  {
115  case StateCompType::NegState: return PyCodeProvider::pyCodeStateCompNegState(mGateId); break;
116  case StateCompType::PosState: return PyCodeProvider::pyCodeStateCompPosState(mGateId); break;
117  default: return "";
118  }
119  }
120 
121  QString StateComponentEntry::enumTypeToString()
122  {
123  const QString types[] = {"Internal state", "Negated internal state"};
124  return types[specificType];
125  }
126 
127  /* ========================================================
128  * BooleanFunctionTableModel
129  * ========================================================*/
130 
132  {
133  mEntries.clear();
134  }
135 
137  {
138  Q_UNUSED(parent);
139  return 3;
140  }
141 
143  {
144  Q_UNUSED(parent);
145  return mEntries.size();
146  }
147 
149  {
150  int row = index.row();
151  int col = index.column();
152 
153  if (role == Qt::DisplayRole){
154 
155  // Extract the information from the entry based on the column
156  if(col == 0)
157  {
158  return (mEntries[row]->getEntryIdentifier());
159  }
160  else if(col == 1)
161  {
162  return mSeparator;
163  }
164  else
165  {
166  return (mEntries[row]->getEntryValueString());
167  }
168  }
169 
170  else if (role == Qt::TextAlignmentRole)
171  {
172  if(col == 0)
173  {
175  }
176  else if(col == 1)
177  {
179  }
180  else
181  {
183  }
184  return Qt::AlignLeft;
185  }
186 
187  return QVariant();
188  }
189 
190  QVariant BooleanFunctionTableModel::headerData(int section, Qt::Orientation orientation, int role) const
191  {
192  Q_UNUSED(section);
193  Q_UNUSED(orientation);
194  Q_UNUSED(role);
195  return QVariant(); // No Header
196  }
197 
198  bool BooleanFunctionTableModel::setData(const QModelIndex &index, const QVariant &value, int role)
199  {
200  Q_UNUSED(index);
201  Q_UNUSED(value);
202  Q_UNUSED(role);
203  return false;
204  }
205 
207  {
208  return mEntries[row];
209  }
210 
213  mEntries = entries;
215  }
216 
218  {
220  mSpecificType = type;
221  mLeft = enumToString();
223  }
224 
225  FFComponentEntry::FFComponentEntry(u32 gateId, std::pair<AsyncSetResetBehavior, AsyncSetResetBehavior> behav) : BooleanFunctionTableEntry(gateId)
226  {
228  mSpecificType = FFCompFunc::SetResetBehav;
229  mLeft = enumToString();
230  mRight = behaviorToString(behav);
231  }
232 
234  {
235  switch (mSpecificType)
236  {
237  case FFCompFunc::Clock: return PyCodeProvider::pyCodeFFCompClockFunc(mGateId);
238  case FFCompFunc::AsyncSet: return PyCodeProvider::pyCodeFFCompAsyncSetFunc(mGateId);
239  case FFCompFunc::NextState: return PyCodeProvider::pyCodeFFCompNextStateFunc(mGateId);
240  case FFCompFunc::AsyncReset: return PyCodeProvider::pyCodeFFCompAsyncResetFunc(mGateId);
241  case FFCompFunc::SetResetBehav: return PyCodeProvider::pyCodeFFCompSetResetBehav(mGateId);
242  default: return "";
243  }
244  }
245 
246  QString FFComponentEntry::enumToString()
247  {
248  static QString types[] = {"Clock", "Next state", "Asynchronous set", "Asynchronous reset", "Set-Reset behavior"};
249  return types[mSpecificType];
250  }
251 
252  QString FFComponentEntry::behaviorToString(std::pair<AsyncSetResetBehavior, AsyncSetResetBehavior> behav)
253  {
254  static QMap<hal::AsyncSetResetBehavior, QString> cPBehaviourToString {
260  {hal::AsyncSetResetBehavior::undef, "Undefined"},
261  };
262  return QString(cPBehaviourToString[behav.first] + ", " + cPBehaviourToString[behav.second]);
263  }
264 
266  {
268  mSpecificType = type;
269  mLeft = enumToString();
271  }
272 
273  LatchComponentEntry::LatchComponentEntry(u32 gateId, std::pair<AsyncSetResetBehavior, AsyncSetResetBehavior> behav) : BooleanFunctionTableEntry(gateId)
274  {
276  mSpecificType = LatchCompFunc::SetResetBehav;
277  mLeft = enumToString();
278  mRight = behaviorToString(behav);
279  }
280 
282  {
283  switch (mSpecificType)
284  {
285  case LatchCompFunc::Enable: return PyCodeProvider::pyCodeLatchCompEnableFunc(mGateId);
286  case LatchCompFunc::AsyncSet: return PyCodeProvider::pyCodeLatchCompAsyncSetFunc(mGateId);
287  case LatchCompFunc::AsyncReset: return PyCodeProvider::pyCodeLatchCompAsyncResetFunc(mGateId);
288  case LatchCompFunc::DataInFunc: return PyCodeProvider::pyCodeLatchCompDataInFunc(mGateId);
289  case LatchCompFunc::SetResetBehav: return PyCodeProvider::pyCodeLatchCompSetResetBehav(mGateId);
290  default: return "";
291  }
292  }
293 
294  QString LatchComponentEntry::enumToString()
295  {
296  const QString types[] = {"Enable", "Data in bf", "Asynchronous set", "Asynchronous Reset", "Set reset behavior"};
297  return types[mSpecificType];
298  }
299 
300  QString LatchComponentEntry::behaviorToString(std::pair<AsyncSetResetBehavior, AsyncSetResetBehavior> behav)
301  {
302  static QMap<hal::AsyncSetResetBehavior, QString> cPBehaviourToString {
308  {hal::AsyncSetResetBehavior::undef, "Undefined"},
309  };
310  return QString(cPBehaviourToString[behav.first] + ", " + cPBehaviourToString[behav.second]);
311  }
312 
313 }// namespace hal
QString getPythonCode() override
BooleanFunction getBooleanFunction() const
BooleanFunctionEntry(u32 gateId, QString functionName, BooleanFunction bf)
static std::string to_string(Value value)
An entry in the boolean function table model.
u32 mGateId
u32 getGateId() const
EntryType
@ CPBehavior
@ LatchComp
@ BooleanFunctionStandard
@ StateComp
@ FFComp
EntryType mType
QString mRight
EntryType getEntryType() const
QString getEntryValueString() const
BooleanFunctionTableEntry(u32 gateId)
QString mLeft
QString getEntryIdentifier() const
QSharedPointer< BooleanFunctionTableEntry > getEntryAtRow(int row) const
BooleanFunctionTableModel(QObject *parent=nullptr)
void setEntries(QVector< QSharedPointer< BooleanFunctionTableEntry >> entries)
bool setData(const QModelIndex &index, const QVariant &value, int role) override
QVariant data(const QModelIndex &index, int role) const override
int rowCount(const QModelIndex &parent=QModelIndex()) const override
QVariant headerData(int section, Qt::Orientation orientation, int role) const override
int columnCount(const QModelIndex &parent=QModelIndex()) const override
std::pair< hal::AsyncSetResetBehavior, hal::AsyncSetResetBehavior > getCPBehavior() const
CPBehaviorEntry(u32 gateId, std::pair< hal::AsyncSetResetBehavior, hal::AsyncSetResetBehavior > cPBehavior)
QString getPythonCode() override
FFComponentEntry(u32 gateId, FFCompFunc type, BooleanFunction func)
FFCompFunc
QString getPythonCode() override
LatchComponentEntry(u32 gateId, LatchCompFunc type, BooleanFunction func)
LatchCompFunc
static QString pyCodeStateCompNegState(u32 gateId)
static QString pyCodeLatchCompAsyncSetFunc(u32 gateId)
static QString pyCodeStateCompPosState(u32 gateId)
static QString pyCodeLatchCompAsyncResetFunc(u32 gateId)
static QString pyCodeLatchCompEnableFunc(u32 gateId)
static QString pyCodeLatchCompDataInFunc(u32 gateId)
static QString pyCodeGateBooleanFunction(u32 gateId, QString booleanFunctionName)
static QString pyCodeFFCompSetResetBehav(u32 gateId)
static QString pyCodeFFCompAsyncSetFunc(u32 gateId)
static QString pyCodeFFCompAsyncResetFunc(u32 gateId)
static QString pyCodeFFCompNextStateFunc(u32 gateId)
static QString pyCodeFFCompClockFunc(u32 gateId)
static QString pyCodeLatchCompSetResetBehav(u32 gateId)
StateComponentEntry(u32 gateId, StateCompType type, QString stateVal)
StateCompType
QString getPythonCode() override
quint32 u32
PinType type
void layoutAboutToBeChanged(const QList< QPersistentModelIndex > &parents, QAbstractItemModel::LayoutChangeHint hint)
void layoutChanged(const QList< QPersistentModelIndex > &parents, QAbstractItemModel::LayoutChangeHint hint)
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const const override
int column() const const
int row() const const
Q_EMITQ_EMIT
QObject * parent() const const
QString fromStdString(const std::string &str)
AlignTop
DisplayRole
Orientation