@@ -20,6 +20,7 @@ MidoriGraph; if not, write to the Free Software Foundation, Inc.,
#include "MonoPropertyFactory.hpp"
#include "MonoScriptManager.hpp"
#include "MonoScript.hpp"
+#include "MonoState.hpp"
namespace MidoriGraph {
@@ -30,6 +31,7 @@ MonoPropertyFactory::MonoPropertyFactory() {
addPropertyType<MonoScriptManager>("ScriptManager");
addPropertyType<MonoScript>();
+ addPropertyType<MonoState>();
}
@@ -17,11 +17,11 @@ 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>
+extern "C" {
+ #include <mono/jit/jit.h>
+ #include <mono/metadata/object.h>
+ #include <mono/metadata/assembly.h>
+}
#include "MonoScriptManager.hpp"
#include "MonoScript.hpp"
--- /dev/null
+/*
+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
+*/
+
+extern "C" {
+ #include <mono/jit/jit.h>
+ #include <mono/metadata/object.h>
+ #include <mono/metadata/assembly.h>
+}
+
+#include "MonoScriptManager.hpp"
+#include "MonoScript.hpp"
+#include "MonoState.hpp"
+
+namespace MidoriGraph {
+
+using namespace std;
+
+
+MonoState::MonoState(AttributeMap attributes) {
+
+ AttributeMap::const_iterator found;
+
+ found = attributes.find("image");
+ if (found == attributes.end()) {
+ throw AttributeNotFound("image");
+ }
+ imageName = boost::any_cast<string>(found->second);
+
+ found = attributes.find("namespace");
+ if (found == attributes.end()) {
+ namespaceName = string("");
+ } else {
+ namespaceName = boost::any_cast<string>(found->second);
+ }
+
+ found = attributes.find("class");
+ if (found == attributes.end()) {
+ throw AttributeNotFound("class");
+ }
+ className = boost::any_cast<string>(found->second);
+
+}
+
+
+MonoState::~MonoState() {
+
+
+}
+
+
+void MonoState::initialize(const Node& owner) {
+
+ Property::initialize(owner);
+
+ /*
+
+ */
+
+}
+
+
+void MonoState::connect(const Node& newParent) {
+
+ // Get a MonoDomain from the ScriptManager to load the assembly into.
+ MonoScriptManager* scriptManager =
+ owner.getAncestorProperty<MonoScriptManager>();
+ // \todo Test for no scriptManager found.
+
+ MonoDomain* domain = scriptManager->getDomain();
+ MonoAssembly* assembly = scriptManager->getAssembly(imageName);
+
+ // Load the State class from the assembly.
+ MonoClass *klass = mono_class_from_name_case(
+ mono_assembly_get_image(assembly),
+ namespaceName.c_str(), className.c_str());
+ if (!klass) {
+ throw runtime_error("Class or namespace not found.");
+ }
+
+ object = mono_object_new(domain, klass);
+
+ // This runs the default, argumentless constructor.
+ mono_runtime_object_init(object);
+}
+
+
+void MonoState::disconnect(const Node& oldParent) {
+
+}
+
+
+} //namespace MidoriGraph
+
--- /dev/null
+/*
+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 theterms 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
+*/
+
+#ifndef _MONO_STATE_HPP_
+#define _MONO_STATE_HPP_
+
+extern "C" {
+ #include <mono/jit/jit.h>
+}
+
+#include "Property.hpp"
+
+namespace MidoriGraph {
+
+
+class MonoState: public Property {
+
+ public:
+
+ MonoState(AttributeMap attributes = AttributeMap());
+
+ virtual ~MonoState();
+
+ virtual void initialize(const Node& owner);
+ virtual void connect(const Node& newParent);
+ virtual void disconnect(const Node& oldParent);
+
+ static const std::string name() { return "MonoState"; }
+ virtual const std::string getName() const { return name(); }
+
+ virtual const InterfaceList getInterfaces() const {
+
+ InterfaceList interfaces = InterfaceList();
+ interfaces.push_back(name());
+ return interfaces;
+ }
+
+
+ private:
+
+ std::string imageName;
+ std::string namespaceName;
+ std::string className;
+
+ MonoObject* object;
+
+};
+
+
+} //namespace MidoriGraph
+
+#endif //_MONO_STATE_HPP_
+
@@ -15,6 +15,7 @@ env.Append(CPPPATH=[
mono_objects = [env.Object("MonoPropertyFactory.cpp"),
env.Object("MonoScriptManager.cpp"),
env.Object("MonoScript.cpp"),
+ env.Object("MonoState.cpp"),
]
Return("mono_objects")
@@ -31,6 +31,7 @@ monounittest = env.Program("monounittest",
"monoPropertyFactory_test.cpp",
"monoScriptManager_test.cpp",
"monoScript_test.cpp",
+ "monoState_test.cpp",
])
monounittest_passed = env.Test("monounittest.passed", monounittest)
@@ -37,4 +37,15 @@ BOOST_AUTO_TEST_CASE (MonoPropertyFactory_create) {
("filename", string("test.dll"))
);
+ create<MonoPropertyFactory>("MonoScript", "MonoScript",
+ list_of< pair<string, any> >
+ ("filename", string("test.dll"))
+ );
+
+ create<MonoPropertyFactory>("MonoState", "MonoState",
+ list_of< pair<string, any> >
+ ("image", string("test"))
+ ("namespace", string(""))
+ ("class", string("State"))
+ );
}
--- /dev/null
+/*
+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 <boost/assign/list_of.hpp> // for 'map_list_of()'
+
+#include "Node.hpp"
+#include "Property.hpp" // AttributeNotFound
+#include "MonoScriptManager.hpp"
+#include "MonoScript.hpp"
+#include "MonoState.hpp"
+
+using namespace std;
+using boost::any;
+using boost::assign::map_list_of;
+using namespace MidoriGraph;
+
+
+class MonoState_testFramework {
+
+ public:
+
+ MonoState_testFramework() {
+
+ root = Node::makeRoot();
+ root.addProperty(new MonoScriptManager());
+
+ script = root.createChild();
+ Property::AttributeMap attributes;
+ attributes.insert(make_pair("filename", string("test.dll")));
+ script.addProperty(new MonoScript(attributes));
+ }
+
+ Node root;
+ Node script;
+};
+
+
+BOOST_AUTO_TEST_CASE (MonoState_initialize) {
+
+ MonoState_testFramework test;
+
+ Node stateNode = test.root.createChild();
+ Property::AttributeMap attributes;
+ attributes.insert(make_pair("image", string("test")));
+ attributes.insert(make_pair("class", string("empty")));
+
+ BOOST_CHECK_NO_THROW(
+ stateNode.addProperty(new MonoState(attributes))
+ );
+
+}
+
+
+BOOST_AUTO_TEST_CASE (MonoState_initialize_noImage) {
+
+ MonoState_testFramework test;
+
+ Node stateNode = test.root.createChild();
+ Property::AttributeMap attributes;
+ attributes.insert(make_pair("class", string("empty")));
+
+ BOOST_CHECK_THROW(
+ stateNode.addProperty(new MonoState(attributes)),
+ AttributeNotFound
+ )
+}
+
+
+BOOST_AUTO_TEST_CASE (MonoState_initialize_noClass) {
+
+ MonoState_testFramework test;
+
+ Node stateNode = test.root.createChild();
+ Property::AttributeMap attributes;
+ attributes.insert(make_pair("image", string("test")));
+
+ BOOST_CHECK_THROW(
+ stateNode.addProperty(new MonoState(attributes)),
+ AttributeNotFound
+ )
+}
+
+
+BOOST_AUTO_TEST_CASE (MonoState_initialize_badImage) {
+
+ MonoState_testFramework test;
+
+ Node stateNode = test.root.createChild();
+ Property::AttributeMap attributes;
+ attributes.insert(make_pair("image", string("foo")));
+ attributes.insert(make_pair("class", string("empty")));
+
+ BOOST_CHECK_THROW(
+ stateNode.addProperty(new MonoState(attributes)),
+ runtime_error
+ )
+}
+
+
+BOOST_AUTO_TEST_CASE (MonoState_initialize_badClass) {
+
+ MonoState_testFramework test;
+
+ Node stateNode = test.root.createChild();
+ Property::AttributeMap attributes;
+ attributes.insert(make_pair("image", string("test")));
+ attributes.insert(make_pair("class", string("bar")));
+
+ BOOST_CHECK_THROW(
+ stateNode.addProperty(new MonoState(attributes)),
+ runtime_error
+ )
+}
+
+
+BOOST_AUTO_TEST_CASE (MonoState_initialize_badNamespace) {
+
+ MonoState_testFramework test;
+
+ Node stateNode = test.root.createChild();
+ Property::AttributeMap attributes;
+ attributes.insert(make_pair("image", string("test")));
+ attributes.insert(make_pair("namespace", string("foobar")));
+ attributes.insert(make_pair("class", string("empty")));
+
+ BOOST_CHECK_THROW(
+ stateNode.addProperty(new MonoState(attributes)),
+ runtime_error
+ )
+}
-using System;
-using System.Runtime.CompilerServices;
-class State {
+// The goggles do nothing!
+class empty {
+}
+
+
+class stateful {
+
+ string state = "Constructed";
- State() {
- Console.WriteLine ("State is constructed!");
+ public string State {
+ get {
+ return state;
+ }
}
}