Removed superfluous assembly map from MonoScriptManager.
authorJD Marble <[email protected]>
Tue, 2 Oct 2007 05:01:08 +0000 (1 22:01 -0700)
committerJD Marble <[email protected]>
Tue, 2 Oct 2007 05:01:08 +0000 (1 22:01 -0700)
mono/src/main/MonoScript.cpp
mono/src/main/MonoScriptManager.cpp
mono/src/main/MonoScriptManager.hpp
mono/src/unittest/monoScriptManager_test.cpp

index e74f99c..717f940 100644 (file)
@@ -17,6 +17,8 @@ MidoriGraph; if not, write to the Free Software Foundation, Inc.,
 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */
 
+#include<iostream>
+
 #include <mono/jit/jit.h>
 #include <mono/metadata/object.h>
 #include <mono/metadata/assembly.h>
@@ -86,17 +88,15 @@ void MonoScript::connect(const Node& newParent) {
     if (!assembly){
         throw runtime_error((string("File not found: ") + filename).c_str());
     }
+    
 
-    scriptManager->addAssembly(assembly, filename);
 }
 
 
 void MonoScript::disconnect(const Node& oldParent) {
 
-    MonoScriptManager* scriptManager =
-        owner.getAncestorProperty<MonoScriptManager>();
-
-    scriptManager->removeAssembly(filename);
+    mono_assembly_close(assembly);
+    assembly = (MonoAssembly*)(0);
 }
 
 
index c06bf71..32df4fb 100644 (file)
@@ -48,31 +48,16 @@ void MonoScriptManager::initialize(const Node& owner) {
 }
 
 
-void MonoScriptManager::addAssembly(AssemblyMap::mapped_type assembly,
-                 AssemblyMap::key_type name) {
-    //\todo read lock for multithreading
-    assemblies.insert(make_pair(name, assembly));
-}
-
-MonoAssembly* MonoScriptManager::getAssembly(AssemblyMap::key_type name) {
-    //\todo read lock for multithreading
-    AssemblyMap::iterator assembly = assemblies.find(name);
-    if (assembly == assemblies.end()) {
-        throw runtime_error((string("Assembly not found: ") + name).c_str());
-    }
-    return assembly->second;
-}
+MonoAssembly* MonoScriptManager::getAssembly(string imageName) {
 
+    MonoImage* image = mono_image_loaded(imageName.c_str());
 
-void MonoScriptManager::removeAssembly(AssemblyMap::key_type name) {
-    //\todo write lock for multithreading
-    AssemblyMap::iterator assembly = assemblies.find(name);
-    if (assembly == assemblies.end()) {
-        throw runtime_error((string("Assembly not found: ") + name).c_str());
+    if (!image) {
+        throw runtime_error((string("Image not loaded: ") + imageName).c_str());
     }
-    assemblies.erase(assembly);
-}
 
+    return mono_image_get_assembly(image);
+}
 
 
 MonoScriptManager::RootDomain::RootDomain() {
index 841cf64..9b06062 100644 (file)
@@ -52,16 +52,8 @@ class MonoScriptManager: public Property {
         return rootDomain.domain;
     }
 
-  private:
-    typedef std::map<std::string, MonoAssembly*> AssemblyMap;
-    AssemblyMap assemblies;
-  
-  public:
 
-    void addAssembly(AssemblyMap::mapped_type assembly,
-                     AssemblyMap::key_type name);
-    MonoAssembly* getAssembly(AssemblyMap::key_type name);
-    void removeAssembly(AssemblyMap::key_type name);
+    MonoAssembly* getAssembly(std::string imageName);
 
     
   private:
dissimilarity index 61%
index 974073f..e094922 100644 (file)
@@ -1,98 +1,35 @@
-/* 
-Copyright 2007, JD Marble <[email protected]>
-This file is part of MidoriGraph.
-
-MidoriGraph is free software; you can redistribute it and/or modify it under the 
-terms of the GNU General Public License as published by the Free Software 
-Foundation; either version 2 of the License, or (at your option) any later
-version.
-
-MidoriGraph is distributed in the hope that it will be useful, but WITHOUT ANY
-WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
-PARTICULAR PURPOSE.  See the GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License along with
-MidoriGraph; if not, write to the Free Software Foundation, Inc.,
-51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-*/
-
-#include <boost/test/auto_unit_test.hpp>
-
-#include "Node.hpp"
-#include "MonoScriptManager.hpp"
-
-using namespace MidoriGraph;
-using namespace std;
-
-
-BOOST_AUTO_TEST_CASE (MonoScriptManager_initialize) {
-
-    Node root = Node::makeRoot();
-    root.addProperty(new MonoScriptManager());
-}
-
-
-BOOST_AUTO_TEST_CASE (MonoScriptManager_addAssembly) {
-
-    Node root = Node::makeRoot();
-    root.addProperty(new MonoScriptManager());
-
-    root.getProperty<MonoScriptManager>()->
-        addAssembly((MonoAssembly*)(0), "foo");
-}
-
-
-BOOST_AUTO_TEST_CASE (MonoScriptManager_getAssembly) {
-
-    Node root = Node::makeRoot();
-    root.addProperty(new MonoScriptManager());
-
-    root.getProperty<MonoScriptManager>()->
-        addAssembly((MonoAssembly*)(42), "foo");
-
-    MonoAssembly* assembly;
-    BOOST_REQUIRE_NO_THROW(
-        assembly = root.getProperty<MonoScriptManager>()->getAssembly("foo"));
-
-    BOOST_CHECK_EQUAL(int(assembly), 42);
-}
-
-
-BOOST_AUTO_TEST_CASE (MonoScriptManager_getAssembly_fail) {
-
-    Node root = Node::makeRoot();
-    root.addProperty(new MonoScriptManager());
-
-    BOOST_CHECK_THROW(root.getProperty<MonoScriptManager>()->getAssembly("foo"),
-                      runtime_error);
-    
-}
-
-
-BOOST_AUTO_TEST_CASE (MonoScriptManager_removeAssembly) {
-
-    Node root = Node::makeRoot();
-    root.addProperty(new MonoScriptManager());
-
-    root.getProperty<MonoScriptManager>()->
-        addAssembly((MonoAssembly*)(42), "foo");
-
-    MonoAssembly* assembly;
-    BOOST_REQUIRE_NO_THROW(
-        root.getProperty<MonoScriptManager>()->removeAssembly("foo"));
-
-    BOOST_CHECK_THROW(root.getProperty<MonoScriptManager>()->getAssembly("foo"),
-                      runtime_error);
-}
-
-
-BOOST_AUTO_TEST_CASE (MonoScriptManager_removeAssembly_fail) {
-
-    Node root = Node::makeRoot();
-    root.addProperty(new MonoScriptManager());
-
-    BOOST_CHECK_THROW(
-        root.getProperty<MonoScriptManager>()->removeAssembly("foo"),
-        runtime_error);
-}
+/* 
+Copyright 2007, JD Marble <[email protected]>
+This file is part of MidoriGraph.
+
+MidoriGraph is free software; you can redistribute it and/or modify it under the 
+terms of the GNU General Public License as published by the Free Software 
+Foundation; either version 2 of the License, or (at your option) any later
+version.
+
+MidoriGraph is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along with
+MidoriGraph; if not, write to the Free Software Foundation, Inc.,
+51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+*/
+
+#include <boost/test/auto_unit_test.hpp>
+
+#include "Node.hpp"
+#include "MonoScriptManager.hpp"
+
+using namespace MidoriGraph;
+using namespace std;
+
+
+BOOST_AUTO_TEST_CASE (MonoScriptManager_initialize) {
+
+    Node root = Node::makeRoot();
+    root.addProperty(new MonoScriptManager());
+}
+
+