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/chip_data/hei_chip_data.cpp b/src/chip_data/hei_chip_data.cpp
index 463e9ae..83c7a3d 100644
--- a/src/chip_data/hei_chip_data.cpp
+++ b/src/chip_data/hei_chip_data.cpp
@@ -23,7 +23,7 @@
 
 //------------------------------------------------------------------------------
 
-void __readRegister(ChipDataStream& io_stream, IsolationChipPtr& io_isoChip)
+void __readRegister(ChipDataStream& io_stream, IsolationChip::Ptr& io_isoChip)
 {
     // Read the register metadata.
     RegisterId_t id;
@@ -49,7 +49,7 @@
 
             // Get this register from the flyweight factory.
             auto& factory = Flyweight<const ScomRegister>::getSingleton();
-            HardwareRegisterPtr hwReg = factory.get(id, inst, attr, addr);
+            auto hwReg    = factory.get(id, inst, attr, addr);
 
             // Add this register to the isolation chip.
             io_isoChip->addHardwareRegister(hwReg);
@@ -61,7 +61,7 @@
 
             // Get this register from the flyweight factory.
             auto& factory = Flyweight<const IdScomRegister>::getSingleton();
-            HardwareRegisterPtr hwReg = factory.get(id, inst, attr, addr);
+            auto hwReg    = factory.get(id, inst, attr, addr);
 
             // Add this register to the isolation chip.
             io_isoChip->addHardwareRegister(hwReg);
@@ -147,7 +147,7 @@
 
 //------------------------------------------------------------------------------
 
-void __readNode(ChipDataStream& io_stream, IsolationChipPtr& io_isoChip)
+void __readNode(ChipDataStream& io_stream, IsolationChip::Ptr& io_isoChip)
 {
     // Read the node metadata.
     NodeId_t nodeId;
@@ -191,7 +191,7 @@
 
 //------------------------------------------------------------------------------
 
-void __readRoot(ChipDataStream& io_stream, IsolationChipPtr& io_isoChip)
+void __readRoot(ChipDataStream& io_stream, IsolationChip::Ptr& io_isoChip)
 {
     AttentionType_t attnType;
     NodeId_t id;
@@ -202,7 +202,7 @@
 //------------------------------------------------------------------------------
 
 void parseChipDataFile(void* i_buffer, size_t i_bufferSize,
-                       IsolationChipMap& io_isoChips)
+                       IsolationChip::Map& io_isoChips)
 {
     ChipDataStream stream{i_buffer, i_bufferSize};
 
diff --git a/src/chip_data/hei_chip_data.hpp b/src/chip_data/hei_chip_data.hpp
index f35cdc1..8b70def 100644
--- a/src/chip_data/hei_chip_data.hpp
+++ b/src/chip_data/hei_chip_data.hpp
@@ -20,6 +20,6 @@
  *                     for each of the user applications chip types.
  */
 void parseChipDataFile(void* i_buffer, size_t i_bufferSize,
-                       IsolationChipMap& io_isoChips);
+                       IsolationChip::Map& io_isoChips);
 
 } // end namespace libhei
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. */
diff --git a/src/register/hei_hardware_register.hpp b/src/register/hei_hardware_register.hpp
index f69e8a7..358cc8f 100644
--- a/src/register/hei_hardware_register.hpp
+++ b/src/register/hei_hardware_register.hpp
@@ -36,6 +36,12 @@
  */
 class HardwareRegister : public Register
 {
+  public: // Aliases
+    using Ptr      = std::shared_ptr<HardwareRegister>;
+    using ConstPtr = std::shared_ptr<const HardwareRegister>;
+
+    using Key = std::pair<RegisterId_t, Instance_t>;
+
   public:
     /** @brief Pure virtual destructor. */
     virtual ~HardwareRegister() = 0;
@@ -79,6 +85,12 @@
         return iv_instance;
     }
 
+    /** @return The register/instance key. */
+    Key getKey() const
+    {
+        return {iv_id, iv_instance};
+    }
+
     /** @return True if given flag is enabled, false if disabled. */
     bool queryAttrFlag(RegisterAttributeFlags_t i_flag) const
     {
@@ -102,12 +114,12 @@
     {
         // In general, comparing the ID and instance should be enough. However,
         // no error will be thrown when adding the register to the flyweights
-        // and any other field differs. Therfore all fields will be used and
+        // and any other field differs. Therefore, all fields will be used and
         // invalid duplicates will be found when adding the register pointers
         // to the IsolationChip objects.
         return (getAddress() == i_r.getAddress()) && (getId() == i_r.getId()) &&
                (getInstance() == i_r.getInstance()) &&
-               (getType() == i_r.getType());
+               (getType() == i_r.getType()) && (iv_flags == i_r.iv_flags);
     }
 
     /** @brief Less than operator. */
@@ -115,7 +127,7 @@
     {
         // In general, comparing the ID and instance should be enough. However,
         // no error will be thrown when adding the register to the flyweights
-        // and any other field differs. Therfore all fields will be used and
+        // and any other field differs. Therefore, all fields will be used and
         // invalid duplicates will be found when adding the register pointers
         // to the IsolationChip objects.
         if (getAddress() < i_r.getAddress())
@@ -136,7 +148,14 @@
                 }
                 else if (getInstance() == i_r.getInstance())
                 {
-                    return (getType() < i_r.getType());
+                    if (getType() < i_r.getType())
+                    {
+                        return true;
+                    }
+                    else if (getType() == i_r.getType())
+                    {
+                        return (iv_flags < i_r.iv_flags);
+                    }
                 }
             }
         }
@@ -293,7 +312,4 @@
     }
 };
 
-/** Pointer management for hardware registers. */
-using HardwareRegisterPtr = std::shared_ptr<const HardwareRegister>;
-
 } // end namespace libhei
diff --git a/src/register/hei_register.hpp b/src/register/hei_register.hpp
index 7cc28eb..e0473aa 100644
--- a/src/register/hei_register.hpp
+++ b/src/register/hei_register.hpp
@@ -26,6 +26,10 @@
 */
 class Register
 {
+  public: // Aliases
+    using Ptr      = std::shared_ptr<Register>;
+    using ConstPtr = std::shared_ptr<const Register>;
+
   public:
     /** @brief Pure virtual destructor. */
     virtual ~Register() = 0;
@@ -44,7 +48,4 @@
 // Pure virtual destructor must be defined.
 inline Register::~Register() {}
 
-/** Pointer management for Register objects. */
-using RegisterPtr = std::shared_ptr<const Register>;
-
 } // end namespace libhei