mirror of https://github.com/XS-MLVP/xcomm.git
add assert in XPort get
This commit is contained in:
parent
208f41deb6
commit
fe4e0628f1
|
@ -26,6 +26,7 @@ public:
|
|||
XPort &NewSubPort(std::string subprefix);
|
||||
XPort &SelectPins(std::vector<std::string> pins);
|
||||
XPort &SelectPins(std::initializer_list<std::string> pins);
|
||||
bool Has(std::string key, bool raw_key = false);
|
||||
xspcomm::XData &Get(std::string key, bool raw_key = false);
|
||||
XPort &FlipIOType();
|
||||
XPort &AsBiIO();
|
||||
|
|
|
@ -95,6 +95,11 @@ xspcomm::XData &XPort::operator[](std::string key)
|
|||
return this->Get(key);
|
||||
}
|
||||
|
||||
bool XPort::Has(std::string key, bool raw_key)
|
||||
{
|
||||
return this->port_list.count(raw_key ? key : this->asKey(key)) > 0;
|
||||
}
|
||||
|
||||
xspcomm::XData &XPort::Get(std::string key, bool raw_key)
|
||||
{
|
||||
Assert(this->port_list.count(raw_key ? key : this->asKey(key)) > 0,
|
||||
|
|
|
@ -138,6 +138,8 @@ def XPort__str__(self: XPort):
|
|||
return f"XPort(prefix={self.prefix}, size={self.PortCount()})"
|
||||
|
||||
def XPort__getitem__(self: XPort, key):
|
||||
assert isinstance(key, str), f"Pin key ({key}) must be str"
|
||||
assert self.Has(key), f"Pin '{key}' not found in XPort"
|
||||
return self.Get(key)
|
||||
|
||||
def XPort__setitem__(self: XPort, key, value):
|
||||
|
|
Loading…
Reference in New Issue