MLECO-4260: Replace raw C++ pointers with smart variants

Model:
Added std::unique_ptr qualifier to Model.cc member and
used make_unique when creating interpreter object
Removed custom destructor and un-necessary memory cleanup following
failed allocation

DataStructures:
Refactored array 2d to use a std::vector under the hood.
This should preserve desired attributes including contiguous
memory while removing the need for custom destructor.
Original size function renamed to dimSize to avoid confusion with
vector.size()
Accompanying changes made to preprocessing and ASR tests.

AppContext:
Replaced use of raw pointers in AppContext.hpp.
Previously a std::map including IAttribute pointers required
individual deallocation as they were allocated using new.

Signed-off-by: Liam Barry <liam.barry@arm.com>
Change-Id: I1a34dce5dea6ecf4883a9ada3a20f827eb6e6d6b
diff --git a/source/application/main/include/AppContext.hpp b/source/application/main/include/AppContext.hpp
index 2f028d5..aae1944 100644
--- a/source/application/main/include/AppContext.hpp
+++ b/source/application/main/include/AppContext.hpp
@@ -1,6 +1,6 @@
 /*
- * SPDX-FileCopyrightText: Copyright 2021 Arm Limited and/or its affiliates <open-source-office@arm.com>
- * SPDX-License-Identifier: Apache-2.0
+ * SPDX-FileCopyrightText: Copyright 2021, 2023 Arm Limited and/or its affiliates
+ * <open-source-office@arm.com> SPDX-License-Identifier: Apache-2.0
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -17,9 +17,9 @@
 #ifndef APP_CTX_HPP
 #define APP_CTX_HPP
 
-#include <string>
 #include <map>
-
+#include <memory>
+#include <string>
 namespace arm {
 namespace app {
 
@@ -58,13 +58,11 @@
         template<typename T>
         void Set(const std::string &name, T object)
         {
-            /* check if we have already the attribute allocated. */
-            if( true == this->Has(name) ){
-                //delete its value
-                delete this->m_attributes[name];
+            /* Attribute exists; reset the smart pointer */
+            if (this->Has(name)) {
+              this->m_attributes.at(name).reset();
             }
-            /* allocate new value */
-            this->m_attributes[name] = new Attribute<T>(object);
+            this->m_attributes[name] = std::make_unique<Attribute<T>>(object);
         }
 
         /**
@@ -73,11 +71,13 @@
          * @param[in]  name   Context attribute name.
          * @return     Value saved in the context.
          */
-        template<typename T>
-        T Get(const std::string &name)
+
+        template <typename T>
+        T Get(const std::string& name)
         {
-            auto a = (Attribute<T>*)m_attributes[name];
-            return a->Get();
+            //TODO Add logic to handle access of non-existent attribute
+            auto attributeValue = (Attribute<T>*)m_attributes.at(name).get();
+            return attributeValue->Get(); 
         }
 
         /**
@@ -92,14 +92,10 @@
 
         ApplicationContext() = default;
 
-        ~ApplicationContext() {
-            for (auto& attribute : m_attributes)
-                delete attribute.second;
+        ~ApplicationContext() = default;
 
-            this->m_attributes.clear();
-        }
     private:
-        std::map<std::string, IAttribute*> m_attributes;
+        std::map<std::string, std::unique_ptr<IAttribute>> m_attributes;
     };
 
 } /* namespace app */