Cleaned smart pointer aliases and node/reg/inst keys
Scoped the aliases within the classes requiring them. Made separate
aliases for pointers and constant pointers. Created node/register
key aliases.
Change-Id: Iaed5ed7955d781c77e5c294351851c1523c6e28e
Signed-off-by: Zane Shelley <zshelle@us.ibm.com>
diff --git a/src/isolator/hei_isolation_chip.cpp b/src/isolator/hei_isolation_chip.cpp
index 69bc643..118e282 100644
--- a/src/isolator/hei_isolation_chip.cpp
+++ b/src/isolator/hei_isolation_chip.cpp
@@ -27,13 +27,11 @@
//------------------------------------------------------------------------------
-void IsolationChip::addHardwareRegister(HardwareRegisterPtr i_hwReg)
+void IsolationChip::addHardwareRegister(HardwareRegister::ConstPtr i_hwReg)
{
HEI_ASSERT(i_hwReg); // should not be null
- RegisterKey_t key = {i_hwReg->getId(), i_hwReg->getInstance()};
-
- auto ret = iv_regs.emplace(key, i_hwReg);
+ auto ret = iv_regs.emplace(i_hwReg->getKey(), i_hwReg);
// If an entry already exists, it should point to the same object.
HEI_ASSERT(ret.second || (ret.first->second == i_hwReg));
@@ -41,13 +39,11 @@
//------------------------------------------------------------------------------
-void IsolationChip::addIsolationNode(IsolationNodePtr i_isoNode)
+void IsolationChip::addIsolationNode(IsolationNode::ConstPtr i_isoNode)
{
HEI_ASSERT(i_isoNode); // should not be null
- NodeKey_t key = {i_isoNode->getId(), i_isoNode->getInstance()};
-
- auto ret = iv_nodes.emplace(key, i_isoNode);
+ auto ret = iv_nodes.emplace(i_isoNode->getKey(), i_isoNode);
// If an entry already exists, it should point to the same object.
HEI_ASSERT(ret.second || (ret.first->second == i_isoNode));
@@ -56,7 +52,7 @@
//------------------------------------------------------------------------------
void IsolationChip::addRootNode(AttentionType_t i_attnType,
- IsolationNodePtr i_rootNode)
+ IsolationNode::ConstPtr i_rootNode)
{
HEI_ASSERT(i_rootNode); // should not be null
@@ -68,13 +64,10 @@
//------------------------------------------------------------------------------
-HardwareRegisterPtr
- IsolationChip::getHardwareRegister(RegisterId_t i_regId,
- Instance_t i_regInst) const
+HardwareRegister::ConstPtr
+ IsolationChip::getHardwareRegister(HardwareRegister::Key i_key) const
{
- RegisterKey_t key = {i_regId, i_regInst};
-
- auto itr = iv_regs.find(key);
+ auto itr = iv_regs.find(i_key);
HEI_ASSERT(iv_regs.end() != itr); // The register should exist.
return itr->second;
@@ -82,12 +75,10 @@
//------------------------------------------------------------------------------
-IsolationNodePtr IsolationChip::getIsolationNode(NodeId_t i_nodeId,
- Instance_t i_nodeInst) const
+IsolationNode::ConstPtr
+ IsolationChip::getIsolationNode(IsolationNode::Key i_key) const
{
- NodeKey_t key = {i_nodeId, i_nodeInst};
-
- auto itr = iv_nodes.find(key);
+ auto itr = iv_nodes.find(i_key);
HEI_ASSERT(iv_nodes.end() != itr); // The node should exist.
return itr->second;
diff --git a/src/isolator/hei_isolation_chip.hpp b/src/isolator/hei_isolation_chip.hpp
index b02d328..a7badcb 100644
--- a/src/isolator/hei_isolation_chip.hpp
+++ b/src/isolator/hei_isolation_chip.hpp
@@ -30,6 +30,12 @@
*/
class IsolationChip
{
+ public: // Aliases
+ using Ptr = std::unique_ptr<IsolationChip>;
+ using ConstPtr = std::unique_ptr<const IsolationChip>;
+
+ using Map = std::map<ChipType_t, const ConstPtr>;
+
public: // Constructors, destructor, assignment
/** @brief Constructor. */
explicit IsolationChip(ChipType_t i_chipType) : iv_chipType(i_chipType) {}
@@ -48,15 +54,13 @@
const ChipType_t iv_chipType;
/** All hardware registers for this chip type. */
- using RegisterKey_t = std::pair<RegisterId_t, Instance_t>;
- std::map<RegisterKey_t, const HardwareRegisterPtr> iv_regs;
+ std::map<HardwareRegister::Key, const HardwareRegister::ConstPtr> iv_regs;
/** All isolation nodes for this chip type. */
- using NodeKey_t = std::pair<NodeId_t, Instance_t>;
- std::map<NodeKey_t, const IsolationNodePtr> iv_nodes;
+ std::map<IsolationNode::Key, const IsolationNode::ConstPtr> iv_nodes;
/** Root nodes for this chip type. */
- std::map<AttentionType_t, const IsolationNodePtr> iv_rootNodes;
+ std::map<AttentionType_t, const IsolationNode::ConstPtr> iv_rootNodes;
public: // Member functions
/**
@@ -81,14 +85,14 @@
* @param i_hwReg The target hardware register. Will assert that a different
* register with the same ID and instance does not exist.
*/
- void addHardwareRegister(HardwareRegisterPtr i_hwReg);
+ void addHardwareRegister(HardwareRegister::ConstPtr i_hwReg);
/**
* @brief Adds an isolation node to this chip.
* @param i_isoNode The target isolation node. Will assert that a different
* node with the same ID and instance does not exist.
*/
- void addIsolationNode(IsolationNodePtr i_isoNode);
+ void addIsolationNode(IsolationNode::ConstPtr i_isoNode);
/**
* @brief Adds a root node to this chip.
@@ -96,34 +100,25 @@
* not already exist in iv_rootNodes.
* @param i_rootNode The target isolation node for this attention type.
*/
- void addRootNode(AttentionType_t i_attnType, IsolationNodePtr i_rootNode);
+ void addRootNode(AttentionType_t i_attnType,
+ IsolationNode::ConstPtr i_rootNode);
/**
* @brief Retrieves a hardware register from this chip, if it exists.
- * @param i_regId The register ID.
- * @param i_regInst The register instance.
+ * @param i_key The register key.
* @return The target hardware register. Will assert that the target
* register exists in iv_regs.
*/
- HardwareRegisterPtr getHardwareRegister(RegisterId_t i_regId,
- Instance_t i_regInst) const;
+ HardwareRegister::ConstPtr
+ getHardwareRegister(HardwareRegister::Key i_key) const;
/**
* @brief Retrieves an isolation node from this chip, if it exists.
- * @param i_nodeId The node ID.
- * @param i_nodeInst The node instance.
+ * @param i_key The node key.
* @return The target isolation node. Will assert that the target node
* exists in iv_nodes.
*/
- IsolationNodePtr getIsolationNode(NodeId_t i_nodeId,
- Instance_t i_nodeInst) const;
+ IsolationNode::ConstPtr getIsolationNode(IsolationNode::Key i_key) const;
};
-/** Pointer management for isolation chips. */
-using IsolationChipPtr = std::unique_ptr<IsolationChip>;
-
-/** A simple map to ensure only one IsolationChip exists per chip type. */
-using IsolationChipMap =
- std::map<ChipType_t, const std::unique_ptr<const IsolationChip>>;
-
} // end namespace libhei
diff --git a/src/isolator/hei_isolation_node.cpp b/src/isolator/hei_isolation_node.cpp
index d41bdee..c952207 100644
--- a/src/isolator/hei_isolation_node.cpp
+++ b/src/isolator/hei_isolation_node.cpp
@@ -76,7 +76,8 @@
//------------------------------------------------------------------------------
-void IsolationNode::addRule(AttentionType_t i_attnType, RegisterPtr i_rule)
+void IsolationNode::addRule(AttentionType_t i_attnType,
+ Register::ConstPtr i_rule)
{
HEI_ASSERT(i_rule); // should not be null
@@ -88,7 +89,7 @@
//------------------------------------------------------------------------------
-void IsolationNode::addChild(uint8_t i_bit, IsolationNodePtr i_child)
+void IsolationNode::addChild(uint8_t i_bit, ConstPtr i_child)
{
HEI_ASSERT(i_child); // should not be null
@@ -100,7 +101,7 @@
//------------------------------------------------------------------------------
-std::vector<IsolationNodePtr> IsolationNode::cv_isolationStack{};
+std::vector<IsolationNode::ConstPtr> IsolationNode::cv_isolationStack{};
//------------------------------------------------------------------------------
@@ -108,11 +109,11 @@
{
// Ensure this node does not already exist in cv_isolationStack.
auto itr = std::find(cv_isolationStack.begin(), cv_isolationStack.end(),
- IsolationNodePtr(this));
+ ConstPtr(this));
HEI_ASSERT(cv_isolationStack.end() == itr);
// Push to node to the stack.
- cv_isolationStack.push_back(IsolationNodePtr(this));
+ cv_isolationStack.push_back(ConstPtr(this));
}
//------------------------------------------------------------------------------
diff --git a/src/isolator/hei_isolation_node.hpp b/src/isolator/hei_isolation_node.hpp
index 4fc5927..26424cc 100644
--- a/src/isolator/hei_isolation_node.hpp
+++ b/src/isolator/hei_isolation_node.hpp
@@ -39,6 +39,12 @@
*/
class IsolationNode
{
+ public: // Aliases
+ using Ptr = std::shared_ptr<IsolationNode>;
+ using ConstPtr = std::shared_ptr<const IsolationNode>;
+
+ using Key = std::pair<NodeId_t, Instance_t>;
+
public: // Constructors, destructor, assignment
/**
* @brief Constructor from components.
@@ -52,7 +58,6 @@
/** @brief Destructor. */
~IsolationNode() = default;
- private:
/** @brief Copy constructor. */
IsolationNode(const IsolationNode&) = delete;
@@ -76,14 +81,13 @@
* HardwareRegister objects and virtual operator registers (all children
* of the Register class).
*/
- std::map<AttentionType_t, const RegisterPtr> iv_rules;
+ std::map<AttentionType_t, const Register::ConstPtr> iv_rules;
/**
* Each bit (key) in this map indicates that an attention was driven from
* another register (value).
*/
- std::map<BitPosition_t, const std::shared_ptr<const IsolationNode>>
- iv_children;
+ std::map<BitPosition_t, const ConstPtr> iv_children;
public: // Member functions
/**
@@ -113,7 +117,7 @@
* @param The target attention type.
* @param The rule for this attention type.
*/
- void addRule(AttentionType_t i_attnType, RegisterPtr i_rule);
+ void addRule(AttentionType_t i_attnType, Register::ConstPtr i_rule);
/**
* @brief Adds a child node to analyze for the given bit position in this
@@ -125,8 +129,7 @@
* @param The target bit on this node.
* @param The child node to analyze for the given bit.
*/
- void addChild(BitPosition_t i_bit,
- std::shared_ptr<const IsolationNode> i_child);
+ void addChild(BitPosition_t i_bit, ConstPtr i_child);
/** @return The node ID. */
NodeId_t getId() const
@@ -140,6 +143,12 @@
return iv_instance;
}
+ /** @return The node/instance key. */
+ Key getKey() const
+ {
+ return {iv_id, iv_instance};
+ }
+
private: // Isolation stack and supporting functions.
/** When analyze() is called at the tree root, all recursive calls to
* analyze() will target the same chip and attention type. So we only need
@@ -153,7 +162,7 @@
* this node can be popped off the top of the stack. Once all the recursive
* calls have returned back to the root node the stack should be empty.
*/
- static std::vector<std::shared_ptr<const IsolationNode>> cv_isolationStack;
+ static std::vector<ConstPtr> cv_isolationStack;
/**
* @brief Pushes this node to the top of the stack. Will assert that this
@@ -168,7 +177,4 @@
}
};
-/** Pointer management for IsolationNode objects. */
-using IsolationNodePtr = std::shared_ptr<const IsolationNode>;
-
} // end namespace libhei
diff --git a/src/isolator/hei_isolator.hpp b/src/isolator/hei_isolator.hpp
index 25aaa50..79a7993 100644
--- a/src/isolator/hei_isolator.hpp
+++ b/src/isolator/hei_isolator.hpp
@@ -48,7 +48,7 @@
private:
/** Keeps track of all chip types that have been initialized. */
- IsolationChipMap iv_isoChips;
+ IsolationChip::Map iv_isoChips;
public:
/** @brief Provides access to a singleton instance of this object. */