summaryrefslogtreecommitdiffstats
path: root/src/bindings/swig/csharp
diff options
context:
space:
mode:
Diffstat (limited to 'src/bindings/swig/csharp')
-rw-r--r--src/bindings/swig/csharp/CMakeLists.txt85
-rw-r--r--src/bindings/swig/csharp/stl_list.i49
-rw-r--r--src/bindings/swig/csharp/stl_set.i73
-rw-r--r--src/bindings/swig/csharp/uscxml.i185
4 files changed, 392 insertions, 0 deletions
diff --git a/src/bindings/swig/csharp/CMakeLists.txt b/src/bindings/swig/csharp/CMakeLists.txt
new file mode 100644
index 0000000..6310778
--- /dev/null
+++ b/src/bindings/swig/csharp/CMakeLists.txt
@@ -0,0 +1,85 @@
+# generate JNI library and create a jar
+# Make from within Eclipse fails miserably with the whole thing
+
+if (WIN32)
+ LIST(APPEND CMAKE_PROGRAM_PATH "C:/Program Files (x86)/swig") # swig.exe
+ #LIST(APPEND CMAKE_PROGRAM_PATH "C:/Windows/Microsoft.NET/Framework/v4.0.30319") # CSharp compiler
+ LIST(APPEND CMAKE_PROGRAM_PATH "C:/Windows/Microsoft.NET/Framework/v3.5") # CSharp compiler
+endif()
+
+FIND_PROGRAM(DMCS_EXECUTABLE dmcs PATHS $ENV{DMCS_HOME} ENV PATH ) # Mono compiler
+FIND_PROGRAM(CSC_EXECUTABLE csc PATHS $ENV{CSC_HOME} ENV PATH ) # CSharp compiler
+
+if (DMCS_EXECUTABLE OR CSC_EXECUTABLE)
+
+ # unset all library suffixes as swig will hardcode a library without
+ SET(LIB_POSTFIX ${CMAKE_LIBRARY_POSTFIX})
+
+ SET(CMAKE_DEBUG_POSTFIX "")
+ SET(CMAKE_RELEASE_POSTFIX "")
+ SET(CMAKE_RELWITHDEBINFO_POSTFIX "")
+ SET(CMAKE_MINSIZEREL_POSTFIX "")
+ SET(CMAKE_LIBRARY_POSTFIX "")
+
+ if (MSVC)
+ # MSVC does not include inttypes.h but SWIG needs it
+ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../msvc)
+ endif()
+
+ include_directories(${CMAKE_CURRENT_SOURCE_DIR})
+
+ SET(CMAKE_SWIG_FLAGS "")
+ SET(USCXML_CSHARP_NAMESPACE "org.uscxml")
+ SET(USCXML_CSHARP_DIR "org/uscxml")
+
+ if (CMAKE_BUILD_TYPE STREQUAL "Debug")
+ list(APPEND CMAKE_SWIG_FLAGS "-DDEBUG")
+ endif()
+
+
+ # we need ; to produce a space with the package .. weird
+ SET_SOURCE_FILES_PROPERTIES(uscxml.i PROPERTIES SWIG_FLAGS "-w401;-namespace;${USCXML_CSHARP_NAMESPACE}")
+ SET_SOURCE_FILES_PROPERTIES(uscxml.i PROPERTIES CPLUSPLUS ON)
+ SET(CMAKE_SWIG_OUTDIR "${CMAKE_CURRENT_BINARY_DIR}/${USCXML_CSHARP_DIR}")
+
+ set(USCXML_LANGUAGE_BINDINGS "csharp ${USCXML_LANGUAGE_BINDINGS}")
+
+ SWIG_ADD_MODULE(uscxmlNativeCSharp csharp uscxml.i)
+ set_target_properties(uscxmlNativeCSharp PROPERTIES FOLDER "Bindings")
+ set_target_properties(uscxmlNativeCSharp
+ PROPERTIES
+ ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/csharp${LIB_POSTFIX}"
+ LIBRARY_OUTPUT_DIRECTORY "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/csharp${LIB_POSTFIX}"
+ RUNTIME_OUTPUT_DIRECTORY "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/csharp${LIB_POSTFIX}"
+ )
+
+ set_target_properties(uscxmlNativeCSharp PROPERTIES COMPILE_FLAGS "-DSWIG")
+ swig_link_libraries(uscxmlNativeCSharp uscxml)
+
+ # build managed code part
+ if (CSC_EXECUTABLE)
+ ADD_CUSTOM_TARGET(csharp
+ COMMAND ${CSC_EXECUTABLE}
+ /target:library
+ /out:${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/uscxmlCSharp.dll
+ *.cs
+ WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/src/bindings/swig/csharp/org/uscxml
+ COMMENT "Creating umundoCSharp.dll for C# ...")
+ else()
+ ADD_CUSTOM_TARGET(csharp
+ COMMAND ${DMCS_EXECUTABLE}
+ -target:library
+ /out:${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/uscxmlCSharp.dll
+ *.cs
+ WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/src/bindings/swig/csharp/org/uscxml
+ COMMENT "Creating umundoCSharp.dll for Mono ...")
+ endif()
+
+ add_dependencies(csharp umundoNativeCSharp)
+ if (BUILD_TESTS)
+ add_dependencies(ALL_TESTS csharp)
+ endif()
+ set_target_properties(csharp PROPERTIES FOLDER "Bindings")
+
+ set(USCXML_LANGUAGE_BINDINGS ${USCXML_LANGUAGE_BINDINGS} PARENT_SCOPE)
+endif() \ No newline at end of file
diff --git a/src/bindings/swig/csharp/stl_list.i b/src/bindings/swig/csharp/stl_list.i
new file mode 100644
index 0000000..aabd448
--- /dev/null
+++ b/src/bindings/swig/csharp/stl_list.i
@@ -0,0 +1,49 @@
+/* -----------------------------------------------------------------------------
+ * See the LICENSE file for information on copyright, usage and redistribution
+ * of SWIG, and the README file for authors - http://www.swig.org/release.html.
+ *
+ * std_list.i
+ * ----------------------------------------------------------------------------- */
+
+%include <std_common.i>
+
+%{
+#include <list>
+#include <stdexcept>
+%}
+
+namespace std {
+
+ template<class T> class list {
+ public:
+ typedef size_t size_type;
+ typedef T value_type;
+ typedef const value_type& const_reference;
+ list();
+ size_type size() const;
+ %rename(isEmpty) empty;
+ bool empty() const;
+ void clear();
+ %rename(add) push_back;
+ void push_back(const value_type& x);
+ %extend {
+ const_reference get(int i) throw (std::out_of_range) {
+ int size = int(self->size());
+ int j;
+ if (i>=0 && i<size) {
+ std::list<T>::const_iterator p;
+ p=self->begin();
+ for (j=0; j<i; j++) {p++;}
+ return (*p);
+ }
+ else
+ throw std::out_of_range("list index out of range");
+ }
+ }
+ };
+}
+
+%define specialize_std_list(T)
+#warning "specialize_std_list - specialization for type T no longer needed"
+%enddef
+
diff --git a/src/bindings/swig/csharp/stl_set.i b/src/bindings/swig/csharp/stl_set.i
new file mode 100644
index 0000000..d009a7b
--- /dev/null
+++ b/src/bindings/swig/csharp/stl_set.i
@@ -0,0 +1,73 @@
+/*=========================================================================
+
+ Program: GDCM (Grassroots DICOM). A DICOM library
+
+ Copyright (c) 2006-2011 Mathieu Malaterre
+ All rights reserved.
+ See Copyright.txt or http://gdcm.sourceforge.net/Copyright.html for details.
+
+ This software is distributed WITHOUT ANY WARRANTY; without even
+ the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ PURPOSE. See the above copyright notice for more information.
+
+=========================================================================*/
+/* -----------------------------------------------------------------------------
+ * std_set.i
+ *
+ * SWIG typemaps for std::set
+ * ----------------------------------------------------------------------------- */
+
+%include <std_common.i>
+
+// ------------------------------------------------------------------------
+// std::set
+// ------------------------------------------------------------------------
+
+%{
+#include <set>
+#include <algorithm>
+#include <stdexcept>
+%}
+
+// exported class
+
+namespace std {
+
+ template<class V> class set {
+ // add typemaps here
+ public:
+ typedef size_t size_type;
+ typedef ptrdiff_t difference_type;
+ typedef V value_type;
+ set();
+ set(const set<V> &);
+
+ unsigned int size() const;
+ bool empty() const;
+ void clear();
+ %extend {
+ const V& get(const V& key) throw (std::out_of_range) {
+ std::set<V>::iterator i = self->find(key);
+ if (i != self->end())
+ return *i;
+ else
+ throw std::out_of_range("key not found");
+ }
+ void insert(const V& key) { // Do NOT call this function 'set' !
+ self->insert(key);
+ }
+ void del(const V& key) throw (std::out_of_range) {
+ std::set<V>::iterator i = self->find(key);
+ if (i != self->end())
+ self->erase(i);
+ else
+ throw std::out_of_range("key not found");
+ }
+ bool has_key(const V& key) {
+ std::set<V>::iterator i = self->find(key);
+ return i != self->end();
+ }
+ }
+ };
+
+} \ No newline at end of file
diff --git a/src/bindings/swig/csharp/uscxml.i b/src/bindings/swig/csharp/uscxml.i
new file mode 100644
index 0000000..07604c4
--- /dev/null
+++ b/src/bindings/swig/csharp/uscxml.i
@@ -0,0 +1,185 @@
+%module(directors="1", allprotected="1") uscxmlNativeCSharp
+
+// provide a macro for the header files
+#define SWIGIMPORTED 1
+
+// import swig typemaps
+//%include <inttypes.i>
+
+%include <stl.i>
+%include <std_map.i>
+%include <std_string.i>
+%include <inttypes.i>
+%include "../stl_set.i"
+%include "../stl_list.i"
+
+%include <boost_shared_ptr.i>
+
+typedef uscxml::Data Data;
+typedef uscxml::Event Event;
+typedef uscxml::InvokeRequest InvokeRequest;
+typedef uscxml::SendRequest SendRequest;
+
+// disable warning related to unknown base class
+#pragma SWIG nowarn=401
+//%ignore boost::enable_shared_from_this;
+
+%csconst(1);
+
+# %shared_ptr(uscxml::dom::Element);
+# %shared_ptr(uscxml::dom::Executable);
+
+%rename(equals) operator==;
+%rename(isValid) operator bool;
+%ignore operator!=;
+%ignore operator<;
+%ignore operator=;
+%ignore operator[];
+%ignore operator std::list<Data>;
+%ignore operator std::string;
+%ignore operator std::map<std::string,Data>;
+%ignore operator<<;
+
+
+//**************************************************
+// This ends up in the generated wrapper code
+//**************************************************
+
+%{
+
+#include "../../../uscxml/Message.h"
+#include "../../../uscxml/Factory.h"
+#include "../../../uscxml/Interpreter.h"
+
+//#include <DOM/Document.hpp>
+//#include <DOM/Node.hpp>
+//#include <DOM/Element.hpp>
+//#include <DOM/Attr.hpp>
+//#include <DOM/Text.hpp>
+
+#include "../wrapped/WrappedInvoker.h"
+#include "../wrapped/WrappedDataModel.h"
+
+using namespace uscxml;
+using namespace Arabica::DOM;
+
+#include "../wrapped/WrappedInvoker.cpp"
+#include "../wrapped/WrappedDataModel.cpp"
+
+%}
+
+%ignore uscxml::NumAttr;
+%ignore uscxml::SCXMLParser;
+%ignore uscxml::InterpreterImpl;
+
+%ignore create();
+
+%ignore uscxml::Interpreter::getDelayQueue();
+
+%ignore uscxml::WrappedInvoker::create(InterpreterImpl*);
+
+%ignore uscxml::WrappedDataModel::create(InterpreterImpl*);
+%ignore uscxml::WrappedDataModel::init(const Arabica::DOM::Element<std::string>&, const Arabica::DOM::Document<std::string>&, const std::string&);
+%ignore uscxml::WrappedDataModel::init(const std::string&, const Data&);
+%ignore uscxml::WrappedDataModel::assign(const Arabica::DOM::Element<std::string>&, const Arabica::DOM::Document<std::string>&, const std::string&);
+%ignore uscxml::WrappedDataModel::assign(const std::string&, const Data&);
+%ignore uscxml::WrappedDataModel::eval(const Arabica::DOM::Element<std::string>&, const std::string&);
+
+%ignore uscxml::Event::Event(const Arabica::DOM::Node<std::string>&);
+%ignore uscxml::Event::getStrippedDOM;
+%ignore uscxml::Event::getFirstDOMElement;
+%ignore uscxml::Event::getDOM();
+%ignore uscxml::Event::setDOM(const Arabica::DOM::Document<std::string>&);
+%ignore uscxml::Event::toDocument();
+
+%template(DataList) std::list<uscxml::Data>;
+%template(DataMap) std::map<std::string, uscxml::Data>;
+%template(StringSet) std::set<std::string>;
+%template(StringVector) std::vector<std::string>;
+%template(ParamPair) std::pair<std::string, uscxml::Data>;
+%template(ParamPairVector) std::vector<std::pair<std::string, uscxml::Data> >;
+%template(IOProcMap) std::map<std::string, uscxml::IOProcessor>;
+%template(InvokerMap) std::map<std::string, uscxml::Invoker>;
+
+%rename Data DataNative;
+
+%feature("director") uscxml::WrappedInvoker;
+%feature("director") uscxml::WrappedDataModel;
+
+// translate param multimap to Map<String, List<Data> >
+%rename(getParamsNative) uscxml::Event::getParams();
+%csmethodmodifiers uscxml::Event::getParams() "private";
+
+%extend uscxml::Event {
+ std::vector<std::pair<std::string, Data> > getParamPairs() {
+ std::vector<std::pair<std::string, Data> > pairs;
+ std::multimap<std::string, Data>::iterator paramPairIter = self->getParams().begin();
+ while(paramPairIter != self->getParams().end()) {
+ pairs.push_back(*paramPairIter);
+ paramPairIter++;
+ }
+ return pairs;
+ }
+};
+
+%extend uscxml::Interpreter {
+ std::vector<std::string> getIOProcessorKeys() {
+ std::vector<std::string> keys;
+ std::map<std::string, IOProcessor>::const_iterator iter = self->getIOProcessors().begin();
+ while(iter != self->getIOProcessors().end()) {
+ keys.push_back(iter->first);
+ iter++;
+ }
+ return keys;
+ }
+
+ std::vector<std::string> getInvokerKeys() {
+ std::vector<std::string> keys;
+ std::map<std::string, Invoker>::const_iterator iter = self->getInvokers().begin();
+ while(iter != self->getInvokers().end()) {
+ keys.push_back(iter->first);
+ iter++;
+ }
+ return keys;
+ }
+
+};
+
+%extend uscxml::Data {
+ std::vector<std::string> getCompundKeys() {
+ std::vector<std::string> keys;
+ std::map<std::string, Data>::const_iterator iter = self->compound.begin();
+ while(iter != self->compound.end()) {
+ keys.push_back(iter->first);
+ iter++;
+ }
+ return keys;
+ }
+};
+
+
+
+//***********************************************
+// Parse the header file to generate wrappers
+//***********************************************
+
+%include "../../../uscxml/Common.h"
+%include "../../../uscxml/Factory.h"
+%include "../../../uscxml/Message.h"
+%include "../../../uscxml/Interpreter.h"
+#include "../../../uscxml/DOMUtils.h"
+
+# %include <DOM/Document.hpp>
+# %include <DOM/Node.hpp>
+# %include <DOM/Element.hpp>
+# %include <DOM/Attr.hpp>
+# %include <DOM/Text.hpp>
+
+%include "../wrapped/WrappedInvoker.h"
+%include "../wrapped/WrappedDataModel.h"
+
+# %template(XMLDocument) Arabica::DOM::Document<std::string>;
+# %template(XMLNode) Arabica::DOM::Node<std::string>;
+# %template(XMLElement) Arabica::DOM::Element<std::string>;
+# %template(XMLAttr) Arabica::DOM::Attr<std::string>;
+# %template(XMLText) Arabica::DOM::Text<std::string>;