Revision 79bb12dc

View differences:

src/org.omnetpp.ide.nativelibs/META-INF/MANIFEST.MF
1
Manifest-Version: 1.0
2
Bundle-ManifestVersion: 2
3
Bundle-Name: OMNeT++ Native library plug-in
4
Bundle-SymbolicName: org.omnetpp.ide.nativelibs
5
Bundle-Version: 4.1.0.qualifier
6
Bundle-Vendor: OpenSim Ltd.
7
Require-Bundle: org.eclipse.core.runtime,
8
 org.eclipse.swt,
9
 org.eclipse.jface
10
Eclipse-LazyStart: true
11
Export-Package: org.omnetpp.common.engine,
12
 org.omnetpp.eventlog.engine,
13
 org.omnetpp.layout.engine,
14
 org.omnetpp.ned.engine,
15
 org.omnetpp.scave.engine,
16
 org.omnetpp.scave.engineext
src/org.omnetpp.ide.nativelibs/Makefile
1
#
2
# Global definitions
3
#
4

  
5
include ../../Makefile.inc
6

  
7
# Make sure that output locations are set
8
ifeq ("$(strip $(OMNETPP_BIN_DIR))","")
9
$(error OMNETPP_BIN_DIR must be correctly set)
10
endif
11
ifeq ("$(strip $(OMNETPP_OUT_DIR))","")
12
$(error OMNETPP_OUT_DIR must be correctly set)
13
endif
14
ifeq ("$(strip $(OMNETPP_LIB_DIR))","")
15
$(error OMNETPP_LIB_DIR must be correctly set)
16
endif
17

  
18
L=$(OMNETPP_LIB_DIR)/$(TOOLCHAIN_NAME)
19
O=$(OMNETPP_OUT_DIR)/$(TOOLCHAIN_NAME)-$(MODE)/ui
20

  
21
#
22
# Local definitions
23
#
24
COMMON=$(OMNETPP_ROOT)/src/common
25
NEDXML=$(OMNETPP_ROOT)/src/nedxml
26
SCAVE=$(OMNETPP_ROOT)/src/scave
27
LAYOUT=$(OMNETPP_ROOT)/src/layout
28
EVENTLOG=$(OMNETPP_ROOT)/src/eventlog
29

  
30
COMMON_JAVAPKG = org.omnetpp.common.engine
31
NEDXML_JAVAPKG = org.omnetpp.ned.engine
32
SCAVE_JAVAPKG = org.omnetpp.scave.engine
33
LAYOUT_JAVAPKG = org.omnetpp.layout.engine
34
EVENTLOG_JAVAPKG = org.omnetpp.eventlog.engine
35

  
36
COMMON_JAVADIR = src/$(subst .,/,$(COMMON_JAVAPKG))
37
NEDXML_JAVADIR = src/$(subst .,/,$(NEDXML_JAVAPKG))
38
SCAVE_JAVADIR = src/$(subst .,/,$(SCAVE_JAVAPKG))
39
LAYOUT_JAVADIR = src/$(subst .,/,$(LAYOUT_JAVAPKG))
40
EVENTLOG_JAVADIR = src/$(subst .,/,$(EVENTLOG_JAVAPKG))
41

  
42
OBJS = $O/nedxml.o $O/scave.o $O/layout.o $O/eventlog.o $O/common.o $O/jprogressmonitor.o
43
LIBS=-L$L -loppnedxml$D -loppscave$D -lopplayout$D -loppeventlog$D -loppcommon$D
44

  
45
ifeq ("$(JNI_LIB_SUFFIX)",".dll")
46
# on mingw we dont need the lib prefix for a JNI library
47
DLL = opplibs$(JNI_LIB_SUFFIX)
48
# the following is needed for building JNI lib with mingw (name mangling issue)
49
LDFLAGS+= -Wl,--kill-at
50
else
51
DLL = $(LIB_PREFIX)opplibs$(JNI_LIB_SUFFIX)
52
endif
53

  
54
# on MAC OS X we should strip only the non-public symbols
55
ifeq ("$(JNI_LIB_SUFFIX)",".jnilib")
56
STRIP_FLAGS=-x
57
endif
58

  
59
DLL_TARGET_DIR = ../org.omnetpp.ide.nativelibs.$(PLATFORM)
60

  
61
#
62
# Local definitions
63
#
64
INCLUDES=-I$(COMMON) -I$(NEDXML) -I$(SCAVE) -I$(LAYOUT) -I$(EVENTLOG) -I$(OMNETPP_INCL_DIR)/platdep
65
COPTS=$(CFLAGS) $(JAVA_CFLAGS) $(INCLUDES) -DTHREADED $(PTHREAD_CFLAGS) 
66

  
67
#
68
# Automatic rules
69
#
70
.SUFFIXES : .cc .cxx
71

  
72
$O/%.o: %.cc
73
	@mkdir -p $O
74
	$(CXX) -c $(COPTS) -o $@ $<
75

  
76
$O/%.o: %.cxx
77
	@mkdir -p $O
78
	$(CXX) -c $(COPTS) -o $@ $<
79

  
80
#
81
# Targets
82
#
83
all: $(JNILIBS_IF_POSSIBLE)
84

  
85
jnilibs: $O/$(DLL) $(DLL_TARGET_DIR)/$(DLL)
86

  
87
common.cxx : common.i
88
	-rm -f $(COMMON_JAVADIR)/*.java
89
	-mkdir -p $(COMMON_JAVADIR)
90
	$(SWIG) -c++ -java $(INCLUDES) -package $(COMMON_JAVAPKG) -outdir $(COMMON_JAVADIR) -o $@ $<
91

  
92
nedxml.cxx : nedxml.i
93
	-rm -f $(NEDXML_JAVADIR)/*.java
94
	-mkdir -p $(NEDXML_JAVADIR)
95
	$(SWIG) -c++ -java $(INCLUDES) -package $(NEDXML_JAVAPKG) -outdir $(NEDXML_JAVADIR) -o $@ $<
96

  
97
scave.cxx : scave.i idlist.i
98
	-rm -f $(SCAVE_JAVADIR)/*.java
99
	-mkdir -p $(SCAVE_JAVADIR)
100
	$(SWIG) -c++ -java $(INCLUDES) -package $(SCAVE_JAVAPKG) -outdir $(SCAVE_JAVADIR) -o $@ scave.i
101

  
102
layout.cxx : layout.i
103
	-rm -f $(LAYOUT_JAVADIR)/*.java
104
	-mkdir -p $(LAYOUT_JAVADIR)
105
	$(SWIG) -c++ -java $(INCLUDES) -package $(LAYOUT_JAVAPKG) -outdir $(LAYOUT_JAVADIR) -o $@ $<
106

  
107
eventlog.cxx : eventlog.i
108
	-rm -f $(EVENTLOG_JAVADIR)/*.java
109
	-mkdir -p $(EVENTLOG_JAVADIR)
110
	$(SWIG) -c++ -java $(INCLUDES) -package $(EVENTLOG_JAVAPKG) -outdir $(EVENTLOG_JAVADIR) -o $@ $<
111

  
112
$O/$(DLL): $(OBJS)
113
	$(SHLIB_LD) $(LDFLAGS) -o $O/$(DLL) $(OBJS) $(LIBS) $(PTHREAD_LIBS)
114
	$(STRIP) $(STRIP_FLAGS) $O/$(DLL)
115

  
116
$(DLL_TARGET_DIR)/$(DLL): $O/$(DLL)
117
	cp $O/$(DLL) $(DLL_TARGET_DIR)
118

  
119

  
120
missing-dependency:
121
	@echo '  *** Missing required dependency -- skipping build of UI support library.'
122
	@echo '  *** Install missing packages (probably SWIG and/or JDK), then run ./configure again.'
123

  
124
depend:
125
	$(MAKEDEPEND) $(INCLUDES) -fMakefile -- *.cxx *.cc
126

  
127
clean:
128
	-rm -f *.cxx *.o *.a *.so $(DLL_TARGET_DIR)/$(DLL)
129
	-rm -rf $(COMMON_JAVADIR) $(NEDXML_JAVADIR) $(SCAVE_JAVADIR) $(LAYOUT_JAVADIR) $(EVENTLOG_JAVADIR)
130

  
131
# DO NOT DELETE THIS LINE -- make depend depends on it.
132

  
src/org.omnetpp.ide.nativelibs/Makefile.vc
1
#
2
# Global definitions
3
#
4
!include ..\..\configuser.vc
5

  
6
# Make sure that output locations are set
7
!if "$(OMNETPP_BIN_DIR)"==""
8
!error OMNETPP_BIN_DIR must be correctly set
9
!endif
10
!if "$(OMNETPP_OUT_DIR)"==""
11
!error OMNETPP_OUT_DIR must be correctly set
12
!endif
13
!if "$(OMNETPP_LIB_DIR)"==""
14
!error OMNETPP_LIB_DIR must be correctly set
15
!endif
16

  
17
# Make sure that we are linking statically
18
!if "$(LIB_SUFFIX)"!=".lib"
19
!error The UI library is supported only with static linking. Please build with "nmake SHARED_LIBS=no ..."
20
!endif
21

  
22
L=$(OMNETPP_LIB_DIR)/$(TOOLCHAIN_NAME)
23
O=$(OMNETPP_OUT_DIR)/$(TOOLCHAIN_NAME)-$(MODE)/ui
24

  
25
JDK="$(TOOLS_DIR)\jdk1.5.0"
26
SWIG="$(TOOLS_DIR)\SWIGWIN-1.3.31\swig.exe"
27

  
28
COMMON=$(OMNETPP_ROOT)\src\common
29
NEDXML=$(OMNETPP_ROOT)\src\nedxml
30
SCAVE=$(OMNETPP_ROOT)\src\scave
31
LAYOUT=$(OMNETPP_ROOT)\src\layout
32
EVENTLOG=$(OMNETPP_ROOT)\src\eventlog
33

  
34
COMMON_JAVAPKG = org.omnetpp.common.engine
35
NEDXML_JAVAPKG = org.omnetpp.ned.engine
36
SCAVE_JAVAPKG = org.omnetpp.scave.engine
37
LAYOUT_JAVAPKG = org.omnetpp.layout.engine
38
EVENTLOG_JAVAPKG = org.omnetpp.eventlog.engine
39

  
40
COMMON_JAVADIR = src\$(COMMON_JAVAPKG:.=\)
41
NEDXML_JAVADIR = src\$(NEDXML_JAVAPKG:.=\)
42
SCAVE_JAVADIR = src\$(SCAVE_JAVAPKG:.=\)
43
LAYOUT_JAVADIR = src\$(LAYOUT_JAVAPKG:.=\)
44
EVENTLOG_JAVADIR = src\$(EVENTLOG_JAVAPKG:.=\)
45

  
46
OBJS = $O/common.obj $O/nedxml.obj $O/scave.obj $O/layout.obj $O/eventlog.obj $O/jprogressmonitor.obj
47
LIBS=$L/oppcommon$D.lib $L/oppnedxml$D.lib $L/oppscave$D.lib $L/opplayout$D.lib $L/oppeventlog$D.lib
48

  
49
DLL = opplibs.dll
50
DLL_TARGET_DIR = ..\org.omnetpp.ide.nativelibs.win32.x86
51

  
52

  
53
#
54
# Local definitions
55
#
56
INCLUDES=-I$(COMMON) -I$(NEDXML) -I$(SCAVE) -I$(LAYOUT) -I$(EVENTLOG) -I$(OMNETPP_INCL_DIR)/platdep 
57
COPTS=$(CFLAGS) -I$(JDK)\include -I$(JDK)\include\win32 $(INCLUDES) -DTHREADED $(PTHREAD_CFLAGS)
58
SWIGOPTS=$(SWIGFLAGS) $(INCLUDES)
59

  
60
#
61
# Automatic rules
62
#
63
.SUFFIXES : .cc .cxx
64

  
65
{.}.cc{$O}.obj:
66
	$(CXX) /Fo"$@" $(COPTS) /c /Tp $<
67

  
68
{.}.cxx{$O}.obj:
69
	$(CXX) /Fo"$@" $(COPTS) /c /Tp $<
70

  
71
#
72
# Targets. NOTE: cmd.exe "Command Extensions" must be enabled for "mkdir" commands to work!
73
#
74
all: $(JNILIBS_IF_POSSIBLE)
75

  
76
jnilibs: $O/$(DLL) $(DLL_TARGET_DIR)/$(DLL)
77

  
78
common.cxx : common.i
79
	-del $(COMMON_JAVADIR)\*.java >nul
80
	-mkdir $(COMMON_JAVADIR) >nul
81
	$(SWIG) -c++ -java $(SWIGOPTS) -package $(COMMON_JAVAPKG) -outdir $(COMMON_JAVADIR) -o $@ $**
82

  
83
nedxml.cxx : nedxml.i
84
	-del $(NEDXML_JAVADIR)\*.java >nul
85
	-mkdir $(NEDXML_JAVADIR) >nul
86
	$(SWIG) -c++ -java $(SWIGOPTS) -package $(NEDXML_JAVAPKG) -outdir $(NEDXML_JAVADIR) -o $@ $**
87

  
88
scave.cxx : scave.i idlist.i
89
	-del $(SCAVE_JAVADIR)\*.java >nul
90
	-mkdir $(SCAVE_JAVADIR) >nul
91
	$(SWIG) -c++ -java $(SWIGOPTS) -package $(SCAVE_JAVAPKG) -outdir $(SCAVE_JAVADIR) -o $@ scave.i
92

  
93
layout.cxx : layout.i
94
	-del $(LAYOUT_JAVADIR)\*.java >nul
95
	-mkdir $(LAYOUT_JAVADIR) >nul
96
	$(SWIG) -c++ -java $(SWIGOPTS) -package $(LAYOUT_JAVAPKG) -outdir $(LAYOUT_JAVADIR) -o $@ $**
97

  
98
eventlog.cxx : eventlog.i
99
	-del $(EVENTLOG_JAVADIR)\*.java >nul
100
	-mkdir $(EVENTLOG_JAVADIR) >nul
101
	$(SWIG) -c++ -java $(SWIGOPTS) -package $(EVENTLOG_JAVAPKG) -outdir $(EVENTLOG_JAVADIR) -o $@ $**
102

  
103
$O/$(DLL): $(OBJS) $(LIBS)
104
	$(LINK) /dll /out:$(O:/=\)\$(DLL) $(OBJS) $(LIBS) $(PTHREAD_LIBS) $(LDFLAGS)
105

  
106
$(DLL_TARGET_DIR)/$(DLL): $O/$(DLL)
107
!if "$(LIB_SUFFIX)"==".lib"
108
	copy $(O:/=\)\$(DLL) $(DLL_TARGET_DIR)
109
	- copy /b $(O:/=\)\$(DLL).manifest $(DLL_TARGET_DIR)
110
!endif
111

  
112
$(OBJS): $O
113

  
114
$O $L:
115
	md $(@:/=\)
116

  
117

  
118
missing-dependency:
119
	@echo '  *** Missing required dependency -- skipping build of UI support library.'
120
	@echo '  *** Install missing packages (probably SWIG and/or JDK), and edit configuser.vc.'
121

  
122
depend:
123
	$(MAKEDEPEND) $(INCLUDES) -fMakefile.vc -- *.cxx *.cc
124

  
125
clean:
126
	-del *.cxx  2>nul
127
	-rmdir /s /q $(O:/=\) 2>nul
128

  
129
# DO NOT DELETE THIS LINE -- make depend depends on it.
130

  
src/org.omnetpp.ide.nativelibs/bigdecimal.i
1

  
2
/*--------------------------------------------------------------------------
3
 * use JAVA_MATH_BIGDECIMAL() if you want to map BigDecimals
4
 *                            to java.math.BigDecimal
5
 * WARN: be sure that BigDecimal does not contain NaN/Infinity, because they
6
 *       cannot be mapped to java.math.BigDecimal. (Nil is mapped to null)
7
 * *** THIS IS CURRENTLY UNUSED, WE USE OUR OWN BigDecimal CLASS INSTEAD ***
8
 *--------------------------------------------------------------------------*/
9
%define JAVA_MATH_BIGDECIMAL()
10
%typemap(jni) BigDecimal "jobject";
11
%typemap(jtype) BigDecimal "java.math.BigDecimal";
12
%typemap(jstype) BigDecimal "java.math.BigDecimal";
13
%typemap(javain) BigDecimal "$javainput";
14
%typemap(javaout) BigDecimal {
15
   return $jnicall;
16
}
17

  
18
%typemap(in) BigDecimal {
19
   if ($input)
20
   {
21
      jclass cl = jenv->FindClass("java/math/BigDecimal");
22
      jmethodID methodID = jenv->GetMethodID(cl, "toPlainString", "()Ljava/lang/String;");
23
      jstring javaString = (jstring)jenv->CallObjectMethod($input, methodID);
24
      const char *chars = jenv->GetStringUTFChars(javaString, 0);
25
      $1 = BigDecimal::parse(chars);
26
      jenv->ReleaseStringUTFChars(javaString, chars);
27
   }
28
   else
29
   {
30
      $1 = BigDecimal::Nil;
31
   }
32
}
33

  
34
%typemap(out) BigDecimal {
35
   if ($1.isNil())
36
   {
37
      $result = NULL;
38
   }
39
   else
40
   {
41
      jclass cl = jenv->FindClass("java/math/BigDecimal");
42
      jmethodID methodId = jenv->GetMethodID(cl, "<init>", "(Ljava/lang/String;)V");
43
      $result = (jenv->NewObject(cl, methodId, jenv->NewStringUTF($1.str().c_str())));
44
   }
45
}
46
%enddef // JAVA_MATH_BIGDECIMAL
47

  
48

  
49
/*--------------------------------------------------------------------------
50
 * use COMMON_ENGINE_BIGDECIMAL() if you want to map BigDecimals
51
 *                                to org.omnetpp.common.engine.BigDecimal
52
 * The C++ objects are wrapped by the java object, but BigDecimal::Nil
53
 * mapped to null.
54
 *--------------------------------------------------------------------------*/
55
%define COMMON_ENGINE_BIGDECIMAL()
56
class BigDecimal;
57
%typemap(jstype) BigDecimal "org.omnetpp.common.engine.BigDecimal";
58
%typemap(javain) BigDecimal "org.omnetpp.common.engine.BigDecimal.getCPtr($javainput)"
59
%typemap(javaout) BigDecimal {
60
    long cPtr = $jnicall;
61
    return (cPtr == 0) ? null : new org.omnetpp.common.engine.BigDecimal(cPtr, true);
62
}
63
%typemap(in) BigDecimal ($&1_type argp) %{
64
   argp = *($&1_ltype*)(void *)&$input;
65
   if (!argp) {
66
      $1 = BigDecimal::Nil;
67
   }
68
   else {
69
      $1 = *argp;
70
   }
71
%}
72

  
73
%typemap(out) BigDecimal %{
74
   if ($1.isNil())
75
   {
76
      $result = 0;
77
   }
78
   else
79
   {
80
      {*($&1_ltype*)(void *)&$result = new $1_ltype(($1_ltype &)$1); }
81
   }
82
%}
83

  
84
%typemap(jstype) BigDecimal* "org.omnetpp.common.engine.BigDecimal";
85
%typemap(javain) BigDecimal* "org.omnetpp.common.engine.BigDecimal.getCPtr($javainput)"
86
%typemap(javaout) BigDecimal* {
87
    long cPtr = $jnicall;
88
    return (cPtr == 0) ? null : new org.omnetpp.common.engine.BigDecimal(cPtr, $owner);
89
}
90
%typemap(in) BigDecimal* %{
91
   if (!$input) {
92
      $1 = &BigDecimal::Nil;
93
   }
94
   else {
95
      $1 = *($1_ltype*)(void*)&$input;
96
   }
97
%}
98
%typemap(out) BigDecimal* %{
99
   if (!$1 || $1->isNil())
100
   {
101
      $result = 0;
102
   }
103
   else
104
   {
105
      *($1_ltype*)(void *)&$result = $1;
106
   }
107
%}
108

  
109
%typemap(jstype) BigDecimal& "org.omnetpp.common.engine.BigDecimal";
110
%typemap(javain) BigDecimal& "org.omnetpp.common.engine.BigDecimal.getCPtr($javainput)"
111
%typemap(javaout) BigDecimal& {
112
    long cPtr = $jnicall;
113
    return (cPtr == 0) ? null : new org.omnetpp.common.engine.BigDecimal(cPtr, false);
114
}
115
%typemap(in) BigDecimal& %{
116
   if (!$input) {
117
      $1 = ($1_ltype)(void *)&BigDecimal::Nil;
118
   }
119
   else {
120
      $1 = *($1_ltype*)(void *)&$input;
121
   }
122
%}
123
%typemap(out) BigDecimal& %{
124
   if ($1->isNil())
125
   {
126
      $result = 0;
127
   }
128
   else
129
   {
130
      {*($1_ltype*)(void *)&$result = $1; }
131
   }
132
%}
133
%enddef // COMMON_ENGINE_BIGDECIMAL
src/org.omnetpp.ide.nativelibs/build.properties
1
source.. = src/
2
output.. = bin/
3
bin.includes = META-INF/,\
4
               .
5
src.includes = std_vector.i,\
6
               std_set.i,\
7
               std_list.i,\
8
               stacktrace.i,\
9
               scave.i,\
10
               scave.cxx,\
11
               scave-plove.i,\
12
               nedxml.i,\
13
               nedxml.cxx,\
14
               loadlib.i,\
15
               layout.i,\
16
               layout.cxx,\
17
               jprogressmonitor.h,\
18
               jprogressmonitor.cc,\
19
               eventlog.i,\
20
               eventlog.cxx,\
21
               commondefs.i,\
22
               common.i,\
23
               common.cxx
src/org.omnetpp.ide.nativelibs/common.i
1
%module Common
2

  
3
// covariant return type warning disabled
4
#pragma SWIG nowarn=822
5

  
6
%{
7
#include "stringutil.h"
8
#include "patternmatcher.h"
9
#include "unitconversion.h"
10
#include "bigdecimal.h"
11
#include "rwlock.h"
12
%}
13

  
14
%include "commondefs.i"
15
%include "loadlib.i"
16
%include "std_string.i"
17
%include "std_vector.i"
18

  
19
namespace std {
20
   %template(StringVector) vector<string>;
21
   %template(PStringVector) vector<const char *>;
22
}
23

  
24
#define THREADED
25

  
26
// hide export/import macros from swig
27
#define COMMON_API
28
#define OPP_DLLEXPORT
29
#define OPP_DLLIMPORT
30

  
31
#define NAMESPACE_BEGIN
32
#define NAMESPACE_END
33
#define USING_NAMESPACE
34

  
35
%rename(parseQuotedString)   ::opp_parsequotedstr;
36
%rename(quoteString)         ::opp_quotestr;
37
%rename(needsQuotes)         ::opp_needsquotes;
38
%rename(quoteStringIfNeeded) ::opp_quotestr_ifneeded;
39

  
40
std::string opp_parsequotedstr(const char *txt);
41
std::string opp_quotestr(const char *txt);
42
bool opp_needsquotes(const char *txt);
43
std::string opp_quotestr_ifneeded(const char *txt);
44
int strdictcmp(const char *s1, const char *s2);
45

  
46
%ignore UnitConversion::parseQuantity(const char *, std::string&);
47

  
48
%include "patternmatcher.h"
49
%include "unitconversion.h"
50

  
51

  
52
/* -------------------- BigDecimal -------------------------- */
53

  
54

  
55
%ignore _I64_MAX_DIGITS;
56
%ignore BigDecimal::BigDecimal();
57
%ignore BigDecimal::str(char*);
58
%ignore BigDecimal::parse(const char*,const char*&);
59
%ignore BigDecimal::ttoa;
60
%ignore BigDecimal::Nil;
61
%ignore BigDecimal::isNil;
62
%ignore BigDecimal::operator=;
63
%ignore BigDecimal::operator+=;
64
%ignore BigDecimal::operator-=;
65
%ignore BigDecimal::operator*=;
66
%ignore BigDecimal::operator/=;
67
%ignore BigDecimal::operator!=;
68
%ignore operator+;
69
%ignore operator-;
70
%ignore operator*;
71
%ignore operator/;
72
%ignore operator<<;
73
%immutable BigDecimal::Zero;
74
%immutable BigDecimal::NaN;
75
%immutable BigDecimal::PositiveInfinity;
76
%immutable BigDecimal::NegativeInfinity;
77
%rename(equals) BigDecimal::operator==;
78
%rename(less) BigDecimal::operator<;
79
%rename(greater) BigDecimal::operator>;
80
%rename(lessOrEqual) BigDecimal::operator<=;
81
%rename(greaterOrEqual) BigDecimal::operator>=;
82
%rename(toString) BigDecimal::str;
83
%rename(doubleValue) BigDecimal::dbl;
84

  
85
%extend BigDecimal {
86
   const BigDecimal add(const BigDecimal& x) {return *self + x;}
87
   const BigDecimal subtract(const BigDecimal& x) {return *self - x;}
88
}
89

  
90
SWIG_JAVABODY_METHODS(public, public, BigDecimal)
91

  
92
%typemap(javacode) BigDecimal %{
93
    public boolean equals(Object other) {
94
       return other instanceof BigDecimal && equals((BigDecimal)other);
95
    }
96

  
97
    public int hashCode() {
98
       return (int)getIntValue();
99
    }
100

  
101
    public java.math.BigDecimal toBigDecimal() {
102
       long intVal = getIntValue();
103
       int scale = getScale();
104
       java.math.BigDecimal d = new java.math.BigDecimal(intVal);
105
       return (scale == 0 ? d : d.movePointRight(scale));
106
    }
107
%}
108

  
109
%include "bigdecimal.h"
110

  
111

  
112
/* -------------------- rwlock.h -------------------------- */
113
%ignore ReaderMutex;
114
%ignore WriterMutex;
115
SWIG_JAVABODY_METHODS(public, public, ILock)
116

  
117
%include "rwlock.h"
src/org.omnetpp.ide.nativelibs/commondefs.i
1
%{
2
#include "bigdecimal.h"
3
#include "jprogressmonitor.h"
4
%}
5

  
6
%exception {
7
    try {
8
        $action
9
    } catch (std::exception& e) {
10
        SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, const_cast<char*>(e.what()));
11
        return $null;
12
    }
13
}
14

  
15
/*--------------------------------------------------------------------------
16
 * int32 <--> int mapping
17
 *--------------------------------------------------------------------------*/
18
%include "intxtypes.h"
19

  
20
%typemap(jni)    int32_t "jint"
21
%typemap(jtype)  int32_t "int"
22
%typemap(jstype) int32_t "int"
23
%typemap(javain) int32_t "$javainput"
24
%typemap(javaout) int32_t {
25
   return $jnicall;
26
}
27

  
28
/*--------------------------------------------------------------------------
29
 * int64 <--> long mapping
30
 *--------------------------------------------------------------------------*/
31
%typemap(jni)    int64_t "jlong"
32
%typemap(jtype)  int64_t "long"
33
%typemap(jstype) int64_t "long"
34
%typemap(javain) int64_t "$javainput"
35
%typemap(javaout) int64_t {
36
   return $jnicall;
37
}
38

  
39
/*--------------------------------------------------------------------------
40
 * IProgressMonitor
41
 *--------------------------------------------------------------------------*/
42
%typemap(jni)    IProgressMonitor * "jobject"
43
%typemap(jtype)  IProgressMonitor * "org.eclipse.core.runtime.IProgressMonitor"
44
%typemap(jstype) IProgressMonitor * "org.eclipse.core.runtime.IProgressMonitor"
45
%typemap(javain) IProgressMonitor * "$javainput"
46
%typemap(in) IProgressMonitor * (JniProgressMonitor jProgressMonitor) {
47
   if ($input)
48
   {
49
      jProgressMonitor = JniProgressMonitor($input, jenv);
50
      $1 = &jProgressMonitor;
51
   }
52
   else
53
   {
54
      $1 = NULL;
55
   }
56
}
57

  
58
/*
59
 * Macro to add equals() and hashCode() to generated Java classes
60
 */
61
%define ADD_CPTR_EQUALS_AND_HASHCODE(CLASS)
62
%typemap(javacode) CLASS %{
63
  public boolean equals(Object obj) {
64
    if (this == obj)
65
      return true;
66
    if (obj == null || this.getClass() != obj.getClass())
67
      return false;
68
    return getCPtr(this) == getCPtr((CLASS)obj);
69
  }
70

  
71
  public int hashCode() {
72
    return (int)getCPtr(this);
73
  }
74
%}
75
%enddef
76

  
77
/*
78
 * ILock
79
 */
80
%define USE_COMMON_ENGINE_ILOCK()
81
class ILock;
82
%typemap(jstype) ILock "org.omnetpp.common.engine.ILock";
83
%typemap(javaout) ILock {
84
    long cPtr = $jnicall;
85
    return (cPtr == 0) ? null : new org.omnetpp.common.engine.ILock(cPtr, $owner);
86
}
87

  
88
%typemap(jstype) ILock* "org.omnetpp.common.engine.ILock";
89
%typemap(javaout) ILock* {
90
    long cPtr = $jnicall;
91
    return (cPtr == 0) ? null : new org.omnetpp.common.engine.ILock(cPtr, $owner);
92
}
93

  
94
%typemap(jstype) ILock& "org.omnetpp.common.engine.ILock";
95
%typemap(javaout) ILock& {
96
    long cPtr = $jnicall;
97
    return (cPtr == 0) ? null : new org.omnetpp.common.engine.ILock(cPtr, $owner);
98
}
99

  
100
%enddef
src/org.omnetpp.ide.nativelibs/eventlog.i
1
%module EventLogEngine
2

  
3
// covariant return type warning disabled
4
#pragma SWIG nowarn=822
5

  
6
%include "loadlib.i"
7
%include "enumtypeunsafe.swg"
8
%include "commondefs.i"
9
%include "bigdecimal.i"
10
%include "stacktrace.i"
11
%javaconst(1);
12

  
13
COMMON_ENGINE_BIGDECIMAL();
14

  
15
%{
16
#include "ievent.h"
17
#include "ieventlog.h"
18
#include "event.h"
19
#include "filteredevent.h"
20
#include "messagedependency.h"
21
#include "eventlogentry.h"
22
#include "eventlogentries.h"
23
#include "eventlogindex.h"
24
#include "eventlog.h"
25
#include "eventlogfacade.h"
26
#include "eventlogtablefacade.h"
27
#include "sequencechartfacade.h"
28
#include "filteredeventlog.h"
29
#include "filereader.h"
30
%}
31

  
32
// hide export/import macros from swig
33
#define COMMON_API
34
#define EVENTLOG_API
35
#define OPP_DLLEXPORT
36
#define OPP_DLLIMPORT
37

  
38
#define NAMESPACE_BEGIN
39
#define NAMESPACE_END
40
#define USING_NAMESPACE
41

  
42
%include "intxtypes.h"
43
%include "eventlogdefs.h"
44

  
45
/*--------------------------------------------------------------------------
46
 * ptr_t <--> long mapping
47
 *--------------------------------------------------------------------------*/
48

  
49
%typemap(jni)    ptr_t "jlong"
50
%typemap(jtype)  ptr_t "long"
51
%typemap(jstype) ptr_t "long"
52
%typemap(javain) ptr_t "$javainput"
53
%typemap(javaout) ptr_t {
54
   return $jnicall;
55
}
56

  
57
%include "std_common.i"
58
%include "std_string.i"
59
%include "std_set.i"     // our custom version
60
%include "std_list.i"    // our custom version
61
%include "std_vector.i"
62
%include "std_map.i"
63

  
64
namespace std {
65

  
66
   %typemap(javacode) vector<string> %{
67
       public String[] toArray() {
68
           int sz = (int) size();
69
           String[] array = new String[sz];
70
              for (int i=0; i<sz; i++)
71
               array[i] = get(i);
72
           return array;
73
       }
74
       public static StringVector fromArray(String[] array) {
75
           StringVector vector = new StringVector();
76
           for (int i=0; i<array.length; i++)
77
               vector.add(array[i]);
78
           return vector;
79
       }
80
   %}
81

  
82
   %typemap(javacode) set<int> %{
83
       public IntSet(boolean cMemoryOwn) {
84
           this(EventLogEngineJNI.new_IntSet__SWIG_0(), cMemoryOwn);
85
       }
86
   %}
87

  
88
   %extend set<const char *> {
89
       std::vector<const char *> keys() {
90
           std::vector<const char *> vec;
91
           vec.reserve(self->size());
92
           for (std::set<const char *>::iterator it = self->begin(); it!=self->end(); it++)
93
               vec.push_back(*it);
94
           return vec;
95
       }
96
   }
97

  
98
   %extend set<string> {
99
       std::vector<std::string> keys() {
100
           std::vector<std::string> vec;
101
           vec.reserve(self->size());
102
           for (std::set<std::string>::iterator it = self->begin(); it!=self->end(); it++)
103
               vec.push_back(*it);
104
           return vec;
105
       }
106
   }
107

  
108
   %extend map<string,string> {
109
       std::vector<std::string> keys() {
110
           std::vector<std::string> vec;
111
           vec.reserve(self->size());
112
           for (std::map<std::string,std::string>::iterator it = self->begin(); it!=self->end(); it++)
113
               vec.push_back(it->first);
114
           return vec;
115
       }
116
   }
117

  
118
   %template(PStringSet) set<const char *>;
119
   %template(StringSet) set<string>;
120
   %template(StringVector) vector<string>;
121
   %template(PStringVector) vector<const char *>;
122

  
123
   //specialize_std_map_on_both(string,,,,string,,,);
124
   //%template(StringMap) map<string,string>;
125

  
126
   %template(ModuleCreatedEntryList) vector<ModuleCreatedEntry*>;
127
   %template(IMessageDependencyList) vector<IMessageDependency*>;
128
   %template(MessageDependencyList) vector<MessageDependency*>;
129
   %template(FilteredMessageDependencyList) vector<FilteredMessageDependency*>;
130

  
131
   %template(IntSet) set<int>;
132
   %template(PtrSet) set<ptr_t>;
133

  
134
   specialize_std_map_on_both(int,,,,int,,,);
135
   %template(IntIntMap) map<int,int>;
136

  
137
   %template(IntVector) vector<int>;
138
   %template(LongVector) vector<long>;
139
   %template(PtrVector) vector<ptr_t>;
140
};
141

  
142
%ignore EventLog::writeTrace;
143

  
144
%define FIX_STRING_MEMBER(STRUCT,MEMBER,CAPITALIZEDMEMBER)
145
%ignore STRUCT::MEMBER;
146
%extend STRUCT {
147
   std::string get ## CAPITALIZEDMEMBER() {return self->MEMBER;}
148
   void set ## CAPITALIZEDMEMBER(std::string __a) {self->MEMBER = __a;}
149
}
150
%enddef
151

  
152
%define FIX_CHARPTR_MEMBER(STRUCT,MEMBER,CAPITALIZEDMEMBER)
153
%ignore STRUCT::MEMBER;
154
%extend STRUCT {
155
   const char * get ## CAPITALIZEDMEMBER() {return self->MEMBER;}
156
}
157
%enddef
158

  
159
%{
160
   JNIEnv *progressDelegateJenv;
161

  
162
   std::string fromJavaString(JNIEnv *jenv, jstring stringObject)
163
   {
164
      if (!stringObject)
165
        return "<null>";
166
      jboolean isCopy;
167
      const char *buf = jenv->GetStringUTFChars(stringObject, &isCopy);
168
      std::string str = buf ? buf : "";
169
      jenv->ReleaseStringUTFChars(stringObject, buf);
170
      return str;
171
   }
172

  
173
   void delegateProgressToJava(IEventLog *eventLog, void *data)
174
   {
175
      JNIEnv *jenv = progressDelegateJenv;
176
      jobject object = (jobject)data;
177
      jclass clazz = jenv->GetObjectClass(object);
178
      jmethodID progressMethod = jenv->GetMethodID(clazz, "progress", "()V");
179
      jenv->ExceptionClear();
180
      jenv->CallVoidMethod(object, progressMethod);
181

  
182
       jthrowable exceptionObject = jenv->ExceptionOccurred();
183
       if (exceptionObject)
184
       {
185
          jenv->ExceptionDescribe();
186
          jenv->ExceptionClear();
187

  
188
          jclass throwableClass = jenv->GetObjectClass(exceptionObject);
189
          jmethodID method = jenv->GetMethodID(throwableClass, "toString", "()Ljava/lang/String;");
190
          jstring msg = (jstring)jenv->CallObjectMethod(exceptionObject, method);
191
          throw opp_runtime_error(fromJavaString(jenv, msg).c_str());
192
      }
193
   }
194
%}
195

  
196
%extend IEventLog {
197
   void setJavaProgressMonitor(JNIEnv *jenv, jobject object) {
198
      progressDelegateJenv = jenv;
199
      ProgressMonitor newProgressMonitor(object ? &delegateProgressToJava : NULL, object ? jenv->NewGlobalRef(object) : NULL);
200
      ProgressMonitor oldProgressMonitor = self->setProgressMonitor(newProgressMonitor);
201
      jobject oldObject = (jobject)oldProgressMonitor.data;
202
      if (oldObject)
203
         jenv->DeleteGlobalRef(oldObject);
204
   }
205
}
206

  
207
%typemap(in) JNIEnv * {
208
  $1 = jenv;
209
}
210

  
211
%typemap(javaout) EventLogEntry * {
212
   return EventLogEntry.newEventLogEntry($jnicall, $owner);
213
}
214

  
215
%typemap(javaimports) EventLogEntry %{
216
import java.lang.reflect.Constructor;
217
%}
218

  
219
%typemap(javacode) EventLogEntry %{
220

  
221
   @SuppressWarnings("unchecked")
222
   private static Constructor[] eventLogEntryConstructors = new Constructor[100];
223

  
224
   public long getCPtr() {
225
      return swigCPtr;
226
   }
227

  
228
   public boolean equals(Object obj) {
229
      return (obj instanceof EventLogEntry) && getCPtr(this)==getCPtr((EventLogEntry)obj);
230
   }
231

  
232
   public int hashCode() {
233
      return (int)getCPtr(this);
234
   }
235

  
236
   @SuppressWarnings("unchecked")
237
   public static EventLogEntry newEventLogEntry(long cPtr, boolean isOwner) {
238
      try {
239
         if (cPtr == 0)
240
            return null;
241

  
242
         int index = EventLogEngineJNI.EventLogEntry_getClassIndex(cPtr, null);
243
         Constructor constructor = eventLogEntryConstructors[index];
244

  
245
         if (constructor == null)
246
         {
247
            String name = "org.omnetpp.eventlog.engine." + EventLogEngineJNI.EventLogEntry_getClassName(cPtr, null);
248
            Class clazz = Class.forName(name);
249
            constructor = clazz.getDeclaredConstructor(long.class, boolean.class);
250
            eventLogEntryConstructors[index] = constructor;
251
         }
252

  
253
         return (EventLogEntry)constructor.newInstance(cPtr, isOwner);
254
      }
255
      catch (Exception e) {
256
         throw new RuntimeException(e);
257
      }
258
   }
259
%}
260

  
261
%typemap(javaout) IMessageDependency * {
262
   return IMessageDependency.newIMessageDependency($jnicall, $owner);
263
}
264

  
265
%typemap(javaimports) IMessageDependency %{
266
import java.lang.reflect.Constructor;
267
%}
268

  
269
%typemap(javacode) IMessageDependency %{
270

  
271
   @SuppressWarnings("unchecked")
272
   private static Constructor[] messageDependencyConstructors = new Constructor[100];
273

  
274
   public long getCPtr() {
275
       return swigCPtr;
276
   }
277

  
278
   public boolean equals(Object obj) {
279
      return (obj instanceof IMessageDependency) && getCPtr(this)==getCPtr((IMessageDependency)obj);
280
   }
281

  
282
   public int hashCode() {
283
      return (int)getCPtr(this);
284
   }
285

  
286
   @SuppressWarnings("unchecked")
287
   public static IMessageDependency newIMessageDependency(long cPtr, boolean isOwner) {
288
      try {
289
         if (cPtr == 0)
290
            return null;
291

  
292
         int index = EventLogEngineJNI.IMessageDependency_getClassIndex(cPtr, null);
293
         Constructor constructor = messageDependencyConstructors[index];
294

  
295
         if (constructor == null)
296
         {
297
            String name = "org.omnetpp.eventlog.engine." + EventLogEngineJNI.IMessageDependency_getClassName(cPtr, null);
298
            Class clazz = Class.forName(name);
299
            constructor = clazz.getDeclaredConstructor(long.class, boolean.class);
300
            messageDependencyConstructors[index] = constructor;
301
         }
302

  
303
         return (IMessageDependency)constructor.newInstance(cPtr, isOwner);
304
      }
305
      catch (Exception e) {
306
         throw new RuntimeException(e);
307
      }
308
   }
309
%}
310

  
311
%typemap(javacode) IEventLog %{
312
    public IEventLog own() {
313
        swigCMemOwn = true;
314
        return this;
315
    }
316

  
317
    public IEventLog disown() {
318
        swigCMemOwn = false;
319
        return this;
320
    }
321

  
322
    public boolean equals(Object obj) {
323
        return (obj instanceof IEventLog) && getCPtr(this)==getCPtr((IEventLog)obj);
324
    }
325
%}
326

  
327
%typemap(javacode) FileReader %{
328
    public FileReader(String fileName, boolean cMemoryOwn) {
329
        this(fileName);
330
        this.swigCMemOwn = cMemoryOwn;
331
    }
332
%}
333

  
334
%typemap(javacode) IEvent %{
335
    public long getCPtr() {
336
        return swigCPtr;
337
    }
338

  
339
    public boolean equals(Object obj) {
340
        return (obj instanceof IEvent) && getCPtr(this)==getCPtr((IEvent)obj);
341
    }
342
%}
343

  
344
%newobject SequenceChartFacade::getModuleMethodBeginEntries;
345
%newobject SequenceChartFacade::getIntersectingMessageDependencies;
346

  
347
%ignore eventLogStringPool;
348
%ignore FILE;
349
%ignore *::parse;
350
%ignore *::print(FILE *);
351
%ignore *::print(FILE *, bool);
352
%ignore *::print(FILE *, long);
353
%ignore *::print(FILE *, long, long);
354
%ignore *::print(FILE *, long, long, bool);
355
%ignore *::print(FILE *, long, long, bool, bool);
356
%ignore *::printInitializationLogEntries(FILE *);
357
%ignore *::printEvents(FILE *);
358
%ignore *::printEvents(FILE *, long);
359
%ignore *::printEvents(FILE *, long, long);
360
%ignore *::printEvents(FILE *, long, long, bool);
361
%ignore *::printCause(FILE *);
362
%ignore *::printConsequence(FILE *);
363
%ignore *::printMiddle(FILE *);
364

  
365
FIX_CHARPTR_MEMBER(EventLogMessageEntry, text, Text);
366
FIX_CHARPTR_MEMBER(SimulationBeginEntry, runId, RunId);
367
FIX_CHARPTR_MEMBER(BubbleEntry, text, Text);
368
FIX_CHARPTR_MEMBER(ModuleMethodBeginEntry, method, Method);
369
FIX_CHARPTR_MEMBER(ModuleCreatedEntry, moduleClassName, ModuleClassName);
370
FIX_CHARPTR_MEMBER(ModuleCreatedEntry, fullName, FullName);
371
FIX_CHARPTR_MEMBER(GateCreatedEntry, name, Name);
372
FIX_CHARPTR_MEMBER(ConnectionDisplayStringChangedEntry, displayString, DisplayString);
373
FIX_CHARPTR_MEMBER(ModuleDisplayStringChangedEntry, displayString, DisplayString);
374
FIX_CHARPTR_MEMBER(BeginSendEntry, messageClassName, MessageClassName);
375
FIX_CHARPTR_MEMBER(BeginSendEntry, messageFullName, MessageFullName);
376
FIX_CHARPTR_MEMBER(BeginSendEntry, detail, Detail);
377

  
378
%include "ievent.h"
379
%include "ieventlog.h"
380
%include "event.h"
381
%include "filteredevent.h"
382
%include "messagedependency.h"
383
%include "eventlogentry.h"
384
%include "eventlogentries.h"
385
%include "eventlogindex.h"
386
%include "eventlog.h"
387
%include "eventlogfacade.h"
388
%include "eventlogtablefacade.h"
389
%include "sequencechartfacade.h"
390
%include "filteredeventlog.h"
391
%include "filereader.h"
src/org.omnetpp.ide.nativelibs/idlist.i
1
%ignore IDList::IDList(unsigned int);
2
%ignore IDList::IDList(const IDList&);
3

  
4
%ignore IDList::clear;
5
%ignore IDList::set(const IDList&);
6
%ignore IDList::erase;
7
%ignore IDList::dup;
8
%ignore IDList::sortByFileAndRun;
9
%ignore IDList::sortByRunAndFile;
10
%ignore IDList::getItemTypes;
11
%ignore IDList::reverse;
12
%ignore IDList::toByteArray;
13
%ignore IDList::fromByteArray;
14
%ignore IDList::getSubsetByIndeces;
15

  
16

  
17
%typemap(javaimports) IDList %{
18
import java.util.ArrayList;
19
import java.util.EventListener;
20
%}
21

  
22

  
23
%typemap(javacode) IDList %{
24

  
25
  public static interface IChangeListener extends EventListener {
26
	public void idlistChanged(IDList idlist);
27
  }
28

  
29
  private ArrayList<IChangeListener> listeners = new ArrayList<IChangeListener>();
30

  
31
  // TODO ensure that immutable
32
  public static final IDList EMPTY = new IDList();
33

  
34
  public void addListener(IChangeListener listener) {
35
  	listeners.add(listener);
36
  }
37

  
38
  public void removeListener(IChangeListener listener) {
39
  	listeners.remove(listener);
40
  }
41

  
42
  protected void notifyListeners() {
43
  	for (IChangeListener listener : listeners.toArray(new IChangeListener[listeners.size()]))
44
  		listener.idlistChanged(this);
45
  }
46

  
47
  public void swigDisown() {
48
      swigCMemOwn = false;
49
  }
50

  
51
  public static IDList fromArray(Long[] array) {
52
      IDList list = new IDList();
53
      for (int i=0; i<array.length; i++)
54
          list.add(array[i].longValue());
55
      return list;
56
  }
57

  
58
  public Long[] toArray() {
59
      int sz = (int) size();
60
      Long[] array = new Long[sz];
61
      for (int i=0; i<sz; i++)
62
          array[i] = Long.valueOf(get(i));
63
      return array;
64
  }
65
%}
66

  
67
%define ADD_NOTIFY(METHOD)
68
%typemap(javaout) void IDList::METHOD {
69
    $jnicall;
70
    notifyListeners();
71
  }
72
%enddef
73

  
74
ADD_NOTIFY(add);
75
ADD_NOTIFY(intersect);
76
ADD_NOTIFY(merge);
77
ADD_NOTIFY(substract);
78
ADD_NOTIFY(sortByDirectory);
79
ADD_NOTIFY(sortByFileName);
80
ADD_NOTIFY(sortByModule);
81
ADD_NOTIFY(sortByName);
82
ADD_NOTIFY(sortByRun);
83
ADD_NOTIFY(sortScalarsByValue);
84
ADD_NOTIFY(sortVectorsByLength);
85
ADD_NOTIFY(sortVectorsByMean);
86
ADD_NOTIFY(sortVectorsByStdDev);
87
ADD_NOTIFY(sortVectorsByVectorId);
88
ADD_NOTIFY(sortVectorsByMin);
89
ADD_NOTIFY(sortVectorsByMax);
90
ADD_NOTIFY(sortVectorsByStartTime);
91
ADD_NOTIFY(sortVectorsByEndTime);
92
ADD_NOTIFY(sortByRunAttribute);
93

  
94
%include "idlist.h"
src/org.omnetpp.ide.nativelibs/jprogressmonitor.cc
1
//=========================================================================
2
//  JPROGRESSMONITOR.CC - part of
3
//                  OMNeT++/OMNEST
4
//           Discrete System Simulation in C++
5
//
6
//=========================================================================
7

  
8
/*--------------------------------------------------------------*
9
  Copyright (C) 1992-2005 Andras Varga
10

  
11
  This file is distributed WITHOUT ANY WARRANTY. See the file
12
  `license' for details on this and other legal matters.
13
*--------------------------------------------------------------*/
14

  
15
#include <jni.h>
16
#include "jprogressmonitor.h"
17

  
18
JniProgressMonitor::JniProgressMonitor(jobject jProgressMonitor, JNIEnv *env)
19
	: jProgressMonitor(jProgressMonitor), env(env)
20
{
21
	jclass clazz = env->FindClass("org/eclipse/core/runtime/IProgressMonitor");
22
	if (clazz) {
23
		this->beginTaskID = env->GetMethodID(clazz, "beginTask", "(Ljava/lang/String;I)V");
24
		this->doneID = env->GetMethodID(clazz, "done", "()V");
25
		this->isCanceledID = env->GetMethodID(clazz, "isCanceled", "()Z");
26
		this->setCanceledID = env->GetMethodID(clazz, "setCanceled", "(Z)V");
27
		this->subTaskID = env->GetMethodID(clazz, "subTask", "(Ljava/lang/String;)V");
28
		this->workedID = env->GetMethodID(clazz, "worked", "(I)V");
29
	}
30
	if (!beginTaskID || !doneID || !isCanceledID || ! setCanceledID || !subTaskID || !workedID)
31
		env = NULL;
32
}
33

  
34
JniProgressMonitor::~JniProgressMonitor()
35
{
36
}
37

  
38
void JniProgressMonitor::beginTask(std::string name, int totalWork)
39
{
40
	if (env)
41
	{
42
		jstring jname = env->NewStringUTF(name.c_str());
43
		env->CallVoidMethod(jProgressMonitor, beginTaskID, jname, (jint)totalWork);
44
	}
45
}
46

  
47
void JniProgressMonitor::done()
48
{
49
	if (env)
50
	{
51
		env->CallVoidMethod(jProgressMonitor, doneID);
52
	}
53
}
54

  
55
bool JniProgressMonitor::isCanceled()
56
{
57
	if (env)
58
	{
59
		return env->CallBooleanMethod(jProgressMonitor, isCanceledID);
60
	}
61
	return false;
62
}
63

  
64
void JniProgressMonitor::setCanceled(bool value)
65
{
66
	if (env)
67
	{
68
		env->CallVoidMethod(jProgressMonitor, setCanceledID, (jboolean)value);
69
	}
70
}
71

  
72
void JniProgressMonitor::subTask(std::string name)
73
{
74
	if (env)
75
	{
76
		jstring jname = env->NewStringUTF(name.c_str());
77
		env->CallVoidMethod(jProgressMonitor, subTaskID, jname);
78
	}
79
}
80

  
81
void JniProgressMonitor::worked(int work)
82
{
83
	if (env)
84
	{
85
		env->CallVoidMethod(jProgressMonitor, workedID, (jint)work);
86
	}
87
}
88

  
src/org.omnetpp.ide.nativelibs/jprogressmonitor.h
1
//=========================================================================
2
//  JPROGRESSMONITOR.H - part of
3
//
4
//                  OMNeT++/OMNEST
5
//           Discrete System Simulation in C++
6
//
7
//=========================================================================
8

  
9
/*--------------------------------------------------------------*
10
  Copyright (C) 1992-2005 Andras Varga
11

  
12
  This file is distributed WITHOUT ANY WARRANTY. See the file
13
  `license' for details on this and other legal matters.
14
*--------------------------------------------------------------*/
15

  
16
#ifndef _JPROGRESSMONITOR_H_
17
#define _JPROGRESSMONITOR_H_
18

  
19
#include <jni.h>
20
#include "progressmonitor.h"
21

  
22
/*
23
 * Implementation of the IProgressMonitor interface
24
 * that delegates to an org.eclipse.core.runtime.IProgressMonitor
25
 * java object.
26
 */
27
class JniProgressMonitor : public IProgressMonitor
28
{
29
	private:
30
		jobject jProgressMonitor;
31
		jmethodID beginTaskID, doneID, isCanceledID,
32
					setCanceledID, subTaskID, workedID;
33

  
34
		JNIEnv *env;
35
	public:
36

  
37
	JniProgressMonitor() : env(NULL) {}
38
	JniProgressMonitor(jobject jProgressMonitor, JNIEnv *env);
39
	virtual ~JniProgressMonitor();
40

  
41
	virtual void beginTask(std::string name, int totalWork);
42
	virtual void done();
43
	virtual bool isCanceled();
44
	virtual void setCanceled(bool value);
45
	virtual void subTask(std::string name);
46
	virtual void worked(int work);
47
};
48

  
49
#endif
50

  
src/org.omnetpp.ide.nativelibs/layout.i
1
%module LayoutEngine
2

  
3
// covariant return type warning disabled
4
#pragma SWIG nowarn=822
5

  
6
%include "loadlib.i"
7
%include "enumtypeunsafe.swg"
8
%include "commondefs.i"
9
%javaconst(1);
10

  
11
%{
12
#include "graphlayouter.h"
13
#include "basicspringembedderlayout.h"
14
#include "forcedirectedgraphlayouter.h"
15
#include "geometry.h"
16
#include "forcedirectedparametersbase.h"
17
#include "forcedirectedparameters.h"
18
#include "forcedirectedembedding.h"
19
%}
20

  
21
// hide export/import macros from swig
22
#define COMMON_API
23
#define LAYOUT_API
24
#define OPP_DLLEXPORT
25
#define OPP_DLLIMPORT
26

  
27
#define NAMESPACE_BEGIN
28
#define NAMESPACE_END
29
#define USING_NAMESPACE
30

  
31
%typemap(jni)    cModule* "jobject"
32
%typemap(jtype)  cModule* "Object"
33
%typemap(jstype) cModule* "Object"
34
%typemap(javain) cModule* "$javainput"
35

  
36
%include "std_common.i"
37
%include "std_string.i"
38
%include "std_vector.i"
39

  
40
%typemap(javacode) Variable %{
41
    protected Variable disown() {
42
        swigCMemOwn = false;
43
        return this;
44
    }
45

  
46
    public boolean equals(Object obj) {
47
        return (obj instanceof Variable) && getCPtr(this)==getCPtr((Variable)obj);
48
    }
49
    public int hashCode() {
50
        return (int)getCPtr(this);
51
    }
52
%}
53

  
54
%typemap(javain) Variable * "Variable.getCPtr($javainput.disown())";
55

  
56
%typemap(javain) IBody * "IBody.getCPtr($javainput.disown())";
57

  
58
%typemap(javaimports) IBody %{
59
import java.lang.reflect.Constructor;
60
%}
61

  
62
%typemap(javaout) IBody * {
63
   return IBody.newIBody($jnicall, $owner);
64
}
65

  
66
%typemap(javacode) IBody %{
67
   protected IBody disown() {
68
      swigCMemOwn = false;
69
      return this;
70
   }
71

  
72
   @SuppressWarnings("unchecked")
73
   private static java.util.ArrayList<Constructor> bodyConstructors = new java.util.ArrayList<Constructor>();
74

  
75
   @SuppressWarnings("unchecked")
76
   public static IBody newIBody(long cPtr, boolean isOwner) {
77
      try {
78
         if (cPtr == 0)
79
            return null;
80

  
81
         String className = LayoutEngineJNI.IBody_getClassName(cPtr, null);
82
         Constructor constructor = null;
83
         for (int i = 0; i < bodyConstructors.size(); i++)
84
            if (bodyConstructors.get(i).getName().equals(className))
85
               constructor = bodyConstructors.get(i);
86

  
87
         if (constructor == null)
88
         {
89
            String name = "org.omnetpp.common.engine." + className;
90
            Class clazz = Class.forName(name);
91
            constructor = clazz.getDeclaredConstructor(long.class, boolean.class);
92
            bodyConstructors.add(constructor);
93
         }
94

  
95
         return (IBody)constructor.newInstance(cPtr, isOwner);
96
      }
97
      catch (Exception e) {
98
         throw new RuntimeException(e);
99
      }
100
   }
101
%}
102

  
103
%typemap(javain) IForceProvider * "IForceProvider.getCPtr($javainput.disown())";
104

  
105
%typemap(javaimports) IForceProvider %{
106
import java.lang.reflect.Constructor;
107
%}
108

  
109
%typemap(javaout) IForceProvider * {
110
   return IForceProvider.newIForceProvider($jnicall, $owner);
111
}
112

  
113
%typemap(javacode) IForceProvider %{
114
   protected IForceProvider disown() {
115
      swigCMemOwn = false;
116
      return this;
117
   }
118

  
119
   @SuppressWarnings("unchecked")
120
   private static java.util.ArrayList<Constructor> forceProviderConstructors = new java.util.ArrayList<Constructor>();
121

  
122
   @SuppressWarnings("unchecked")
123
   public static IForceProvider newIForceProvider(long cPtr, boolean isOwner) {
124
      try {
125
         if (cPtr == 0)
126
            return null;
127

  
128
         // we implement polymorphic return types:
129
         String className = LayoutEngineJNI.IForceProvider_getClassName(cPtr, null);
130
         Constructor constructor = null;
131
         for (int i = 0; i < forceProviderConstructors.size(); i++)
132
            if (forceProviderConstructors.get(i).getName().equals(className))
133
               constructor = forceProviderConstructors.get(i);
134

  
135
         if (constructor == null)
136
         {
137
            String name = "org.omnetpp.common.engine." + className;
138
            Class clazz = Class.forName(name);
139
            constructor = clazz.getDeclaredConstructor(long.class, boolean.class);
140
            forceProviderConstructors.add(constructor);
141
         }
142

  
143
         return (IForceProvider)constructor.newInstance(cPtr, isOwner);
144
      }
145
      catch (Exception e) {
146
         throw new RuntimeException(e);
147
      }
148
   }
149
%}
150

  
151
namespace std {
152
   %template(CcList) vector<Cc>;
153
   %template(IBodyList) vector<IBody *>;
154
   %template(IForceProviderList) vector<IForceProvider *>;
155
   %template(PtList) vector<Pt>;
156
   %template(VariableList) vector<Variable *>;
157
};
158

  
159
%define FIXUP_GETNODEPOSITION(CLASS)
160
%ignore CLASS::getNodePosition;
161
%extend CLASS {
162
   int getNodePositionX(cModule *mod) {int x,y; self->getNodePosition(mod, x, y); return x;}
163
   int getNodePositionY(cModule *mod) {int x,y; self->getNodePosition(mod, x, y); return y;}
164
}
165
%enddef
166

  
167
FIXUP_GETNODEPOSITION(GraphLayouter);
168
FIXUP_GETNODEPOSITION(BasicSpringEmbedderLayout);
169
FIXUP_GETNODEPOSITION(ForceDirectedGraphLayouter);
170

  
171
/*
172
XXX to ignore:
173
  getDistanceAndVector()
174
  getStandardVerticalDistanceAndVector()
175
  getSlipperyDistanceAndVector()
176
*/
177

  
178
%ignore zero;
179
%ignore NaN;
180
%ignore POSITIVE_INFINITY;
181
%ignore isNaN;
182
%ignore ForceDirectedEmbedding::parameters;
183
%ignore ForceDirectedEmbedding::writeDebugInformation;
184
%ignore LeastExpandedSpring::LeastExpandedSpring;   //XXX takes std::vector<AbstractSpring*>
185

  
186
%include "graphlayouter.h"
187
%include "basicspringembedderlayout.h"
188
%include "forcedirectedgraphlayouter.h"
189
%include "geometry.h"
190
%include "forcedirectedparametersbase.h"
191
%include "forcedirectedparameters.h"
192
%include "forcedirectedembedding.h"
193

  
src/org.omnetpp.ide.nativelibs/loadlib.i
1
//
2
// Load the native library when any method from it is referenced.
3
//
4
// Note: check exceptions before. gcc shared libs must NOT be linked with "-static",
5
// because throw/catch won't work (program exits with "terminate called...").
6
// See http://www.gnu.org/software/gcc/faq.html#dso
7
// As a safeguard against incorrectly built libs, we test exceptions first thing
8
// after loading the library.
9
// --Andras
10
//
11

  
12
%{
13
#include "exception.h"
14
static void testExceptionHandling() {
15
    try {
16
        throw opp_runtime_error("if you see this exception, omnetpp's native library (\"opplibs\") was built incorrectly");
17
    } catch (std::exception&) { /*OK!*/ }
18
}
19
%}
20
void testExceptionHandling();
21

  
22
%pragma(java) jniclassimports=%{
23
import org.eclipse.core.runtime.Platform;
24
import org.eclipse.jface.dialogs.MessageDialog;
25
import org.eclipse.swt.widgets.Display;
26
%}
27

  
28
%pragma(java) jniclasscode=%{
29
  static {
30
      if (Platform.getOS().equals(Platform.OS_WIN32)) {
31
          try {
32
              // mingwm10.dll is a dependency of opplibs.dll. We need to load it
33
              // explicitly, because for some reason it is not found otherwise
34
              // when placed next to opplibs.dll. --Andras
35
              System.loadLibrary("mingwm10");
36
          }
37
          catch (UnsatisfiedLinkError e) {
38
              System.err.println("Warning: could not load mingwm10.dll: " + e.getClass().getName() + ": " + e.toString());
39
          }
40
      }
41
      try {
42
          System.loadLibrary("opplibs");
43
      }
44
      catch (UnsatisfiedLinkError e) {
45
          displayError(e);
46
          throw e;
47
      }
48
      testExceptionHandling();
49
      testThreads();
50
  }
51

  
52
  private static void testThreads() {
53
      // test that exception handling is thread-safe in our shared lib (gcc -mthreads)
54
      for (int i=0; i<3; i++) {
55
          Thread t = new Thread() {
56
              @Override
57
              public void run() {
58
                  long start = System.currentTimeMillis();
59
                  while (System.currentTimeMillis() - start < 50)
60
                      testExceptionHandling();
61
              }
62
          };
63
          t.start();
64
      }
65
  }
66

  
67
  private static void displayError(final UnsatisfiedLinkError e) {
68
      runNowOrSyncInUIThread(new Runnable() {
69
          public void run() {
70
              MessageDialog.openError(null, "Fatal Error",
71
                      "FATAL: The OMNeT++ IDE native library failed to load, " +
72
                      "all OMNeT++-related functionality will be unaccessible.\n\n" +
73
                      "Details:\n\n" +
74
                      e.getClass().getSimpleName() + ": " + e.getMessage() + "\n\n" +
75
                      (Platform.getOS().equals(Platform.OS_LINUX) ?
76
                              "Try upgrading your Linux installation to a more recent version, " +
77
                              "or installing newer versions of libc and libstdc++." : "")
78
              );
79
          }
80
      });
81
  }
82

  
83
  private static void runNowOrSyncInUIThread(Runnable runnable) {
84
      if (Display.getCurrent() == null)
85
          Display.getDefault().syncExec(runnable);
86
      else
87
          runnable.run();
88
  }
89
%}
90

  
91

  
src/org.omnetpp.ide.nativelibs/nedxml.i
1
%module nedxml
2

  
3
// covariant return type warning disabled
4
#pragma SWIG nowarn=822
5

  
6
%include "loadlib.i"
7
%include "std_string.i"
8
%include "enums.swg"
9
%include "commondefs.i"
10

  
11
%javaconst(1);
12

  
13
%{
14
#include "nedelement.h"
15
#include "nederror.h"
16
#include "nedparser.h"
17
#include "ned2generator.h"
18
#include "ned1generator.h"
19
#include "xmlgenerator.h"
20
#include "nedelements.h"
21

  
22
#include "neddtdvalidator.h"
23
#include "nedtools.h"
24
#include "nedsyntaxvalidator.h"
25

  
26
// #include "nedcompiler.h"
27
#include "nedfilebuffer.h"
28
// #include "nedsemanticvalidator.h"
29
// #include "cppgenerator.h"
30
%}
31

  
32
// hide export/import macros from swig
33
#define COMMON_API
34
#define NEDXML_API
35
#define OPP_DLLEXPORT
36
#define OPP_DLLIMPORT
37

  
38
#define NAMESPACE_BEGIN
39
#define NAMESPACE_END
40
#define USING_NAMESPACE
41

  
42
namespace std {
43
//class ostream;
44
};
45

  
46
// parse functions return new objects, supposed to be deleted from Java
47
%newobject NEDParser::parseNEDText(const char *);
48
%newobject NEDParser::parseNEDFile(const char *);
49
%newobject NEDParser::parseNEDExpression(const char *);
50
%newobject createElementWithTag(int tagcode, NEDElement *parent);
51

  
52
// These are only public for technical reasons, shouldn't be wrapped
53
%ignore NEDParser::getSource();
54
%ignore NEDParser::getErrors();
55
%ignore NEDParser::error(const char *, int);
56

  
57
%ignore np;
58

  
59
%ignore NEDElementUserData;
60
%ignore NEDElement::setUserData(NEDElementUserData *);
61
%ignore NEDElement::getUserData() const;
62

  
63
%ignore generateNED1(std::ostream&, NEDElement *, NEDErrorStore *);
64
%ignore generateNED2(std::ostream&, NEDElement *, NEDErrorStore *);
65
%ignore generateXML(std::ostream&, NEDElement *, bool, int);
66
%ignore NEDInternalError;
67

  
68
// XXX for some reason, SWIG doesn't give a s&%$# about the following ignores:
69
%ignore NEDElementStore::add(NEDElement *, const char *, ...);
70
%ignore NEDElementStore::add(NEDElement *, int, const char *, ...);
71
%ignore NEDGenerator1::generate(std::ostream&, NEDElement *, const char *);
72
%ignore NEDGenerator2::generate(std::ostream&, NEDElement *, const char *);
73
%ignore NEDXMLGenerator::generate(std::ostream&, NEDElement *);
74

  
75
%ignore ltstr;
76

  
77
%ignore  FilesElement;
78
%ignore  NedFileElement;
79
%ignore  CommentElement;
80
%ignore  ImportElement;
81
%ignore  PropertyDeclElement;
82
%ignore  ExtendsElement;
83
%ignore  InterfaceNameElement;
84
%ignore  SimpleModuleElement;
85
%ignore  ModuleInterfaceElement;
86
%ignore  CompoundModuleElement;
87
%ignore  ChannelInterfaceElement;
88
%ignore  ChannelElement;
89
%ignore  ParametersElement;
90
%ignore  ParamGroupElement;
91
%ignore  ParamElement;
92
%ignore  PatternElement;
93
%ignore  PropertyElement;
94
%ignore  PropertyKeyElement;
95
%ignore  GatesElement;
96
%ignore  GateGroupElement;
97
%ignore  GateElement;
98
%ignore  TypesElement;
99
%ignore  SubmodulesElement;
100
%ignore  SubmoduleElement;
101
%ignore  ConnectionsElement;
102
%ignore  ConnectionElement;
103
%ignore  ChannelSpecElement;
104
%ignore  ConnectionGroupElement;
105
%ignore  LoopElement;
106
%ignore  ConditionElement;
107
%ignore  ExpressionElement;
108
%ignore  OperatorElement;
109
%ignore  FunctionElement;
110
%ignore  IdentElement;
111
%ignore  LiteralElement;
112
%ignore  MsgFileElement;
113
%ignore  NamespaceDeclElement;
114
%ignore  CplusplusElement;
115
%ignore  StructDeclElement;
116
%ignore  ClassDeclElement;
117
%ignore  MessageDeclElement;
118
%ignore  EnumDeclElement;
119
%ignore  EnumElement;
120
%ignore  EnumFieldsElement;
121
%ignore  EnumFieldElement;
122
%ignore  MessageElement;
123
%ignore  ClassElement;
124
%ignore  StructElement;
125
%ignore  FieldsElement;
126
%ignore  FieldElement;
127
%ignore  PropertiesElement;
128
%ignore  MsgpropertyElement;
129
%ignore  UnknownElement;
130

  
131

  
132
/* Let's just grab the original header file here */
133
%include "nedxmldefs.h"
134
%include "nedelement.h"
135
%include "nederror.h"
136
%include "nedparser.h"
137
%include "ned2generator.h"
138
%include "ned1generator.h"
139
%include "xmlgenerator.h"
140
%include "nedelements.h"
141

  
142
%include "nedvalidator.h"
143
%include "neddtdvalidatorbase.h"
144
%include "neddtdvalidator.h"
145
%include "nedtools.h"
146
%include "nedsyntaxvalidator.h"
147

  
148
//%include "nedcompiler.h"
149
//%include "nedfilebuffer.h"
150
//%include "nedsemanticvalidator.h"
151
//%include "cppgenerator.h"
152

  
src/org.omnetpp.ide.nativelibs/scave-plove.i
1
%{
2
#include "node.h"
3
#include "dataflowmanager.h"
4
#include "nodetype.h"
5
#include "nodetyperegistry.h"
6
#include "arraybuilder.h"
7
#include "xyarray.h"
8
%}
9

  
10
// covariant return type warning disabled
11
#pragma SWIG nowarn=822
12

  
13
%include "commondefs.i"
14
%include "std_common.i"
15
%include "std_string.i"
16
%include "std_map.i"
17
%include "std_vector.i"
18
%include "std_list.i"    // our custom version
19

  
20
namespace std {
21

  
22
   //
23
   // Without the following macro (defined in std_map.i in the swig library),
24
   // get() returns string *pointer* (because of T& retval); this macro defines
25
   // get() to return T so it'll be just string. Same with NodeType*.
26
   //
27
   specialize_std_map_on_both(std::string,,,,std::string,,,);
28

  
29
   // generate needed template specializations
30
   %template(StringMap) map<string,string>;
31
   %template(NodeTypeVector) vector<NodeType*>;
32
};
33

  
34
//
35
// We publish very little of the Node and Port classes into Java,
36
// just enough to assemble the data-flow engine. We hide Channel and
37
// Datum altogether.
38
//
39

  
40
class NodeType;
41
class XYArray;
42

  
43
class Port
44
{
45
  private:
46
    Port(); // prevent generating a default public one
47
    ~Port();
48
  public:
49
    Node *getNode();
50
};
51

  
52
%newobject Node::getArray;
53

  
54
class Node
55
{
56
  private:
57
    Node(); // prevent generating a default public one
58
    ~Node();
59
  public:
60
    NodeType *getNodeType() const;
61
    %extend {
62
        XYArray *getArray() {
63
            ArrayBuilderNode *abNode = dynamic_cast<ArrayBuilderNode *>(self);
64
            return abNode ? abNode->getArray() : NULL;
65
        }
66
    }
67
};
68

  
69

  
70
%ignore DataflowManager::addNode; // it's included in NodeType::create()
71

  
72
%ignore XYArray::XYArray;
73

  
74
%ignore NodeTypeRegistry::parseFilterSpec;
75
//
76
// NodeType, NodeTypeRegistry and DataflowManager are published in their entirety
77
// to Java.
78
//
79
%include "nodetype.h"
80
%include "nodetyperegistry.h"
81
%include "dataflowmanager.h"
82
%include "xyarray.h"
83

  
84

  
src/org.omnetpp.ide.nativelibs/scave.i
1
%module ScaveEngine
2

  
3
// covariant return type warning disabled
4
#pragma SWIG nowarn=822
5

  
6
%include "loadlib.i"
7
#%include "enums.swg"
8
#%javaconst(1);
9

  
10
%{
11
#include "scavedefs.h"
12
#include "enumtype.h"
13
#include "statistics.h"
14
#include "idlist.h"
15
#include "resultfilemanager.h"
16
#include "fields.h"
17
#include "datasorter.h"
18
#include "stringutil.h"   // strdictcmp
19
#include "indexfile.h"
20
#include "commonnodes.h"
21
#include "indexedvectorfile.h"
22
#include "vectorfileindexer.h"
23
#include "vectorfilereader.h"
24
#include "indexedvectorfilereader.h"
25
#include "scaveexception.h"
26
#include "export.h"
27
%}
28

  
29
#define THREADED
30

  
31
%include "commondefs.i"
32
%include "bigdecimal.i"
33

  
34
// hide export/import macros from swig
35
#define COMMON_API
36
#define OPP_DLLEXPORT
37
#define OPP_DLLIMPORT
38

  
39
#define NAMESPACE_BEGIN
40
#define NAMESPACE_END
41
#define USING_NAMESPACE
42

  
43
%include "intxtypes.h"
44
%include "scavedefs.h"
45

  
46
%typemap(jni) ID "jlong";
47

  
48
COMMON_ENGINE_BIGDECIMAL();
49

  
50
USE_COMMON_ENGINE_ILOCK();
51

  
52
%include "std_common.i"
53
%include "std_string.i"
54
%include "std_set.i"     // our custom version
55
%include "std_list.i"    // our custom version
56
%include "std_vector.i"
57
%include "std_map.i"
58

  
59
namespace std {
60
   %typemap(javacode) vector<string> %{
61
       public String[] toArray() {
62
           int sz = (int) size();
63
           String[] array = new String[sz];
64
           for (int i=0; i<sz; i++)
65
               array[i] = get(i);
66
           return array;
67
       }
68
       public static StringVector fromArray(String[] array) {
69
           StringVector vector = new StringVector();
70
           for (int i=0; i<array.length; i++)
71
               vector.add(array[i]);
72
           return vector;
73
       }
74

  
75
   %}
76

  
77
   %typemap(javacode) vector<double> %{
78
       public double[] toArray() {
79
           int sz = (int) size();
80
           double[] array = new double[sz];
81
           for (int i=0; i<sz; i++)
82
               array[i] = get(i);
83
           return array;
84
       }
85

  
86
   %}
87

  
88
   %typemap(javacode) vector<Run*> %{
89
        public Run[] toArray() {
90
            int sz = (int)size();
91
            Run[] array = new Run[sz];
92
            for (int i=0; i<sz; i++)
93
                array[i] = get(i);
94
            return array;
95
        }
96
   %}
97

  
98
   %typemap(javacode) vector<ResultFile*> %{
99
        public ResultFile[] toArray() {
100
            int sz = (int)size();
101
            ResultFile[] array = new ResultFile[sz];
102
            for (int i=0; i<sz; i++)
103
                array[i] = get(i);
104
            return array;
105
        }
106
   %}
107

  
108
   %typemap(javacode) vector<FileRun*> %{
109
        public FileRun[] toArray() {
110
            int sz = (int)size();
111
            FileRun[] array = new FileRun[sz];
112
            for (int i=0; i<sz; i++)
113
                array[i] = get(i);
114
            return array;
115
        }
116
   %}
117

  
118
   %typemap(javacode) vector<ID> %{
119
        public Long[] toArray() {
120
            int sz = (int)size();
121
            Long[] array = new Long[sz];
122
            for (int i=0; i<sz; i++)
123
                array[i] = Long.valueOf(get(i));
124
            return array;
125
        }
126
   %}
127

  
128
   %extend set<string> {
129
       std::vector<std::string> keys() {
130
           std::vector<std::string> vec;
131
           vec.reserve(self->size());
132
           for (std::set<std::string>::iterator it = self->begin(); it!=self->end(); it++)
133
               vec.push_back(*it);
134
           return vec;
135
       }
136
   }
137

  
138
   %extend map<string,string> {
139
       std::vector<std::string> keys() {
140
           std::vector<std::string> vec;
141
           vec.reserve(self->size());
142
           for (std::map<std::string,std::string>::iterator it = self->begin(); it!=self->end(); it++)
143
               vec.push_back(it->first);
144
           return vec;
145
       }
146
   }
147

  
148
   %template(StringSet) set<string>;
149
   %template(StringVector) vector<string>;
150

  
151
   //specialize_std_map_on_both(string,,,,string,,,);
152

  
153
   //%template(StringMap) map<string,string>;
154

  
155
   %template(IDVector) vector<ID>;
156
   %template(IDVectorVector) vector<vector<ID> >;
157
   %template(RunList) vector<Run*>;
158
   %template(ResultFileList) vector<ResultFile*>;
159
   %template(FileRunList) vector<FileRun*>;
160
   %template(DoubleVector) vector<double>;
161
   %template(XYDatasetVector) vector<XYDataset>;
162
};
163

  
164
%rename(toString) EnumType::str;
165
%ignore EnumType::insert;
166
%ignore EnumType::parseFromString;
167
%ignore EnumType::operator=;
168
%include "enumtype.h"
169

  
170

  
171

  
172
/*---------------------------------------------------------------------------
173
 *                    ResultFileManager
174
 *---------------------------------------------------------------------------*/
175

  
176

  
177
//
178
// The following code is for IDList::getSubsetByIndices():
179
//
180
%typemap(in) (int *array, int n) {
181
    $2 = jenv->GetArrayLength($input);
182
    jint *a = jenv->GetIntArrayElements($input, 0);
183
    $1 = new int[$2];
184
    for (int i=0; i<$2; i++)  $1[i] = a[i];
185
    jenv->ReleaseIntArrayElements($input, a, 0);
186
}
187

  
188
%typemap(freearg) (int *array, int n) {
189
    delete [] $1;
190
}
191

  
192
%typemap(jni)    (int *array, int n) "jintArray"
193
%typemap(jtype)  (int *array, int n) "int[]"
194
%typemap(jstype) (int *array, int n) "int[]"
195
%typemap(javain) (int *array, int n) "$javainput"
196

  
197
//
198
// The following code is for IDList::toByteArray()/fromByteArray()
199
//
200
%typemap(in) (char *array, int n) {
201
    $2 = jenv->GetArrayLength($input);
202
    $1 = (char *) jenv->GetByteArrayElements($input, 0);
203
}
204

  
205
%typemap(freearg) (char *array, int n) {
206
    jenv->ReleaseByteArrayElements($input, (jbyte *)$1, 0);
207
}
208

  
209
%typemap(jni)    (char *array, int n) "jbyteArray"
210
%typemap(jtype)  (char *array, int n) "byte[]"
211
%typemap(jstype) (char *array, int n) "byte[]"
212
%typemap(javain) (char *array, int n) "$javainput"
213

  
214

  
215
// FIXME add %newobject where needed!
216

  
217
//
218
// By default, string members get wrapped with get/set using *pointers* to strings.
219
// This is not too nice, so override it by defining proper getter/setter methods,
220
// and hiding (ignoring) the class member
221
//
222
%define FIX_STRING_MEMBER(STRUCT,MEMBER,CAPITALIZEDMEMBER)
223
%ignore STRUCT::MEMBER;
224
%extend STRUCT {
225
   std::string get ## CAPITALIZEDMEMBER() {return self->MEMBER;}
226
   void set ## CAPITALIZEDMEMBER(std::string __a) {self->MEMBER = __a;}
227
}
228
%enddef
229

  
230
%define FIX_CHARPTR_MEMBER(STRUCT,MEMBER,CAPITALIZEDMEMBER)
231
%ignore STRUCT::MEMBER;
232
%extend STRUCT {
233
   const char * get ## CAPITALIZEDMEMBER() {return self->MEMBER;}
234
}
235
%enddef
236

  
237

  
238
//
239
// addComputedVector
240
//
241

  
242
%typemap(jni)    ComputationNode "jobject"
243
%typemap(jtype)  ComputationNode "Object"
244
%typemap(jstype) ComputationNode "Object"
245
%typemap(javain) ComputationNode "$javainput"
246
%typemap(javaout) ComputationNode {
247
   return $jnicall;
248
}
249

  
250
%typemap(in) ComputationNode {
251
  $1 = (ComputationNode)jenv->NewGlobalRef($input);
252
}
253

  
254
// XXX call DeleteGlobalRef
255

  
256
%typemap(out) ComputationNode {
257
  if ($1)
258
    $result = (jobject)$1;
259
  else
260
    $result = $null;
261
}
262

  
263

  
264
/*--------------------------------------------------------------------------
265
 *                     check ResultFileFormatException
266
 *--------------------------------------------------------------------------*/
267
%define CHECK_RESULTFILE_FORMAT_EXCEPTION(METHOD)
268
%exception METHOD {
269
    try {
270
        $action
271
    } catch (ResultFileFormatException& e) {
272
    jclass clazz = jenv->FindClass("org/omnetpp/scave/engineext/ResultFileFormatException");
273
    jmethodID methodId = jenv->GetMethodID(clazz, "<init>", "(Ljava/lang/String;Ljava/lang/String;I)V");
274
    jthrowable exception = (jthrowable)(jenv->NewObject(clazz, methodId, jenv->NewStringUTF(e.what()), jenv->NewStringUTF(e.getFileName()), e.getLine()));
275
        jenv->Throw(exception);
276
        return $null;
277
    } catch (std::exception& e) {
278
        SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, const_cast<char*>(e.what()));
279
        return $null;
280
    }
281
}
282
%enddef
283

  
284

  
285

  
286
// Java doesn't appear to have dictionary sort, export it
287
int strdictcmp(const char *s1, const char *s2);
288

  
289
/* ------------- statistics.h  ----------------- */
290
%ignore Statistics::operator=;
291
%include "statistics.h"
292

  
293
/* ------------- idlist.h  ----------------- */
294
%include "idlist.i"
295

  
296
/* ------------- resultfilemanager.h  ----------------- */
297
%ignore ResultFileManager::dump;
298
%ignore VectorResult::stat;
299
%ignore ResultFile::id;
300
%ignore ResultFile::scalarResults;
301
%ignore ResultFile::vectorResults;
302
%ignore ResultFile::histogramResults;
303

  
304
%rename FileRun::fileRef file;
305
%rename FileRun::runRef run;
306
%rename ResultItem::fileRunRef fileRun;
307

  
308
%ignore ResultItem::moduleNameRef;
309
%ignore ResultItem::nameRef;
310

  
311
// do not allow direct access to unwrapped ResultFileManager
312
%ignore ResultFile::resultFileManager;
313
%ignore Run::resultFileManager;
314

  
315
// unused methods
316
%ignore ResultFileManager::filterRunList;
317
%ignore ResultFileManager::filterFileList;
318
%ignore ResultFileManager::getFileRuns;
319
%ignore ResultFileManager::getUniqueFileRuns;
320
%ignore ResultFileManager::getScalarsInFileRun;
321
%ignore ResultFileManager::getHistogramsInFileRun;
322
%ignore ResultFileManager::getUniqueRunAttributeValues;
323
%ignore ResultFileManager::getUniqueModuleParamValues;
324
//%ignore ResultFileManager::getUniqueModuleNames;
325
//%ignore ResultFileManager::getUniqueNames;
326
//%ignore ResultFileManager::getUniqueAttributeValues;
327
//%ignore ResultFileManager::getFileAndRunNumberFilterHints;
328

  
329
%newobject ResultItem::getEnum() const;
330

  
331
%extend ResultItem {
332
   std::string getModuleName() {return *self->moduleNameRef;}
333
   std::string getName() {return *self->nameRef;}
334
}
335

  
336
//
337
// Add polymorphic return type to ResultFileManager::getItem(),
338
// because plain ResultItem does not contain the type (VECTOR, SCALAR, etc).
339
//
340
%ignore ResultFileManager::getItem;
341
%typemap(javacode) ResultFileManager %{
342

  
343
  public ResultItem getItem(long id) {
344
      int type = getTypeOf(id);
345
      if (type==SCALAR)
346
          return getScalar(id);
347
      else if (type==VECTOR)
348
          return getVector(id);
349
      else if (type==HISTOGRAM)
350
          return getHistogram(id);
351
      else
352
          throw new RuntimeException("unknown ID type");
353
  }
354

  
355
  public static <T> T callWithReadLock(ResultFileManager manager, java.util.concurrent.Callable<T> callable) {
356
    return callWithLock(manager != null ? manager.getReadLock() : null, callable);
357
  }
358

  
359
  public static <T> T callWithWriteLock(ResultFileManager manager, java.util.concurrent.Callable<T> callable) {
360
    return callWithLock(manager != null ? manager.getWriteLock() : null, callable);
361
  }
362

  
363
  private static <T> T callWithLock(org.omnetpp.common.engine.ILock lock, java.util.concurrent.Callable<T> callable) {
364
    if (lock != null)
365
      lock.lock();
366
    try {
367
      return callable.call();
368
    }
369
    catch (RuntimeException e) {
370
      throw e;
371
    }
372
    catch (Exception e) {
373
      throw new RuntimeException(e);
374
    }
375
    finally {
376
      if (lock != null)
377
        lock.unlock();
378
    }
379
  }
380

  
381

  
382
  public void checkReadLock() {
383
    org.eclipse.core.runtime.Assert.isTrue(getReadLock().hasLock(), "Missing read lock.");
384
  }
385

  
386
  public void checkWriteLock() {
387
    org.eclipse.core.runtime.Assert.isTrue(getWriteLock().hasLock(), "Missing write lock.");
388
  }
389

  
390
  public boolean equals(Object obj) {
391
    if (this == obj)
392
      return true;
393
    if (obj == null || this.getClass() != obj.getClass())
394
      return false;
395
    return getCPtr(this) == getCPtr((ResultFileManager)obj);
396
  }
397

  
398
  public int hashCode() {
399
    return (int)getCPtr(this);
400
  }
401
%}
402

  
403
FIX_STRING_MEMBER(ResultFile, filePath, FilePath);
404
FIX_STRING_MEMBER(ResultFile, directory, Directory);
405
FIX_STRING_MEMBER(ResultFile, fileName, FileName);
406
FIX_STRING_MEMBER(ResultFile, fileSystemFilePath, FileSystemFilePath);
407
//FIX_STRING_MEMBER(Run, networkName, NetworkName);
408
//FIX_STRING_MEMBER(Run, date, Date);
409
FIX_STRING_MEMBER(Run, runName, RunName);
410
//FIX_STRING_MEMBER(Run, fileAndRunName, FileAndRunName);
411
//FIX_STRING_MEMBER(Run, experimentName, ExperimentName);
412
//FIX_STRING_MEMBER(Run, measurementName, MeasurementName);
413
//FIX_STRING_MEMBER(Run, replicationName, ReplicationName);
414
FIX_STRING_MEMBER(VectorResult, columns, Columns);
415

  
416
ADD_CPTR_EQUALS_AND_HASHCODE(ResultFile);
417
ADD_CPTR_EQUALS_AND_HASHCODE(Run);
418
ADD_CPTR_EQUALS_AND_HASHCODE(FileRun);
419
ADD_CPTR_EQUALS_AND_HASHCODE(ResultItem);
420
CHECK_RESULTFILE_FORMAT_EXCEPTION(ResultFileManager::loadFile)
421

  
422
%newobject ResultFileManager::getUniqueFiles(const IDList&) const;
423
%newobject ResultFileManager::getUniqueRuns(const IDList&) const;
424
%newobject ResultFileManager::getUniqueFileRuns(const IDList&) const;
425
%newobject ResultFileManager::getUniqueModuleNames(const IDList&) const;
426
%newobject ResultFileManager::getUniqueNames(const IDList&) const;
427
%newobject ResultFileManager::getUniqueAttributeNames(const IDList&) const;
428
%newobject ResultFileManager::getUniqueRunAttributeNames(const RunList *) const;
429
%newobject ResultFileManager::getUniqueModuleParamNames(const RunList *) const;
430
%newobject ResultFileManager::getUniqueAttributeValues(const IDList &, const char *) const;
431
%newobject ResultFileManager::getUniqueRunAttributeValues(const RunList&, const char *) const;
432
%newobject ResultFileManager::getUniqueModuleParamValues(const RunList&, const char *) const;
433

  
434
%newobject ResultFileManager::getFileAndRunNumberFilterHints(const IDList&) const;
435
%newobject ResultFileManager::getFilePathFilterHints(const ResultFileList&) const;
436
%newobject ResultFileManager::getRunNameFilterHints(const RunList&) const;
437
%newobject ResultFileManager::getModuleFilterHints(const IDList&) const;
438
%newobject ResultFileManager::getNameFilterHints(const IDList&) const;
439
%newobject ResultFileManager::getResultItemAttributeFilterHints(const IDList&, const char*) const;
440
%newobject ResultFileManager::getRunAttributeFilterHints(const RunList&, const char*) const;
441
%newobject ResultFileManager::getModuleParamFilterHints(const RunList&, const char*) const;
442

  
443
%include "resultfilemanager.h"
444

  
445
/* ------------- datasorter.h  ----------------- */
446
%include "datasorter.h"
447

  
448

  
449
/* ------------- dataflownetwork.h  ----------------- */
450
// wrap the data-flow engine as well
451
CHECK_RESULTFILE_FORMAT_EXCEPTION(DataflowManager::execute)
452
%include scave-plove.i
453

  
454
/* ------------- indexfile.h  ----------------- */
455
// %include "indexfile.h"
456

  
457
%javamethodmodifiers IndexFile::isIndexFileUpToDate "protected";
458

  
459
class IndexFile
460
{
461
    public:
462
        static bool isIndexFile(const char *indexFileName);
463
        static bool isVectorFile(const char *vectorFileName);
464
        static std::string getIndexFileName(const char *vectorFileName);
465
        static std::string getVectorFileName(const char *indexFileName);
466
        static bool isIndexFileUpToDate(const char *fileName);
467
};
468

  
469
/* ------------- vectorfileindexer.h  ----------------- */
470
CHECK_RESULTFILE_FORMAT_EXCEPTION(VectorFileIndexer::generateIndex)
471
%include "vectorfileindexer.h"
472

  
473
/* ------------- indexedvectorfile.h  ----------------- */
474
%typemap(javacode) OutputVectorEntry %{
475
   public boolean equals(Object obj) {
476
      return (obj instanceof OutputVectorEntry) && getSerial() == ((OutputVectorEntry)obj).getSerial();
477
   }
478

  
479
   public int hashCode() {
480
      return getSerial();
481
   }
482
%}
483

  
484
namespace std {
485
  %template(EntryVector) vector<OutputVectorEntry>;
486
};
487
%ignore IndexedVectorFileWriterNode;
488
%ignore IndexedVectorFileWriterNodeType;
489
%include "indexedvectorfile.h"
490

  
491
/* ------------- vectorfilereader.h  ----------------- */
492
%ignore SingleSourceNode;
493
%ignore SingleSinkNode;
494
%ignore FilterNode;
495
%ignore ReaderNode;
496
%ignore SingleSourceNodeType;
497
%ignore SingleSinkNodeType;
498
%ignore FilterNodeType;
499
%ignore ReaderNodeType;
500
%include "commonnodes.h"
501

  
502
%extend VectorFileReaderNode {
503
    static VectorFileReaderNode *cast(Node* node) { return dynamic_cast<VectorFileReaderNode*>(node); }
504
};
505

  
506
%ignore VectorFileReaderNodeType;
507
%ignore parseColumns;
508
%include "vectorfilereader.h"
509

  
510
/* ------------- indexedvectorfilereader.h  ----------------- */
511
%include "indexedvectorfilereader.h"
512

  
513

  
514
%extend IndexedVectorFileReaderNode {
515
    static IndexedVectorFileReaderNode *cast(Node* node) { return dynamic_cast<IndexedVectorFileReaderNode*>(node); }
516
};
517

  
518
/* ------------------ fields.h --------------------- */
519
%ignore ResultItemFieldsEqual;
520
%ignore ResultItemFieldsLess;
521
%ignore IDFieldsEqual;
522
%ignore IDFieldsLess;
523
%ignore getAttribute;
524
%ignore ResultItemFields::begin;
525
%ignore ResultItemFields::end;
526

  
527
%typemap(javacode) ResultItemField %{
528

  
529
  public static final String FILE   = getFILE();
530
  public static final String RUN    = getRUN();
531
  public static final String MODULE = getMODULE();
532
  public static final String NAME   = getNAME();
533

  
534
  public boolean equals(Object other) {
535
    if (this == other)
536
      return true;
537
    if (other == null || this.getClass() != other.getClass())
538
      return false;
539
    ResultItemField otherField = (ResultItemField)other;
540
    return this.getID() == otherField.getID() && this.getName().equals(otherField.getName());
541
  }
542

  
543
  public int hashCode() {
544
    return 37 * getID() + getName().hashCode();
545
  }
546
%}
547

  
548
%typemap(javacode) RunAttribute %{
549

  
550
  public static final String INIFILE           = getINIFILE();
551
  public static final String CONFIGNAME        = getCONFIGNAME();
552
  public static final String RUNNUMBER         = getRUNNUMBER();
553
  public static final String NETWORK           = getNETWORK();
554
  public static final String EXPERIMENT        = getEXPERIMENT();
555
  public static final String MEASUREMENT       = getMEASUREMENT();
556
  public static final String REPLICATION       = getREPLICATION();
557
  public static final String PROCESSID         = getPROCESSID();
558
  public static final String DATETIME          = getDATETIME();
559
  public static final String RESULTDIR         = getRESULTDIR();
560
  public static final String REPETITION        = getREPETITION();
561
  public static final String SEEDSET           = getSEEDSET();
562
  public static final String ITERATIONVARS     = getITERATIONVARS();
563
  public static final String ITERATIONVARS2    = getITERATIONVARS2();
564

  
565
%}
566

  
567
%typemap(javacode) ResultItemFields %{
568

  
569
  public ResultItemFields(String... fieldNames) {
570
    this(StringVector.fromArray(fieldNames));
571
  }
572
%}
573

  
574
%include "fields.h"
575

  
576
/* ------------------ datasorter.h --------------------- */
577
%include "datasorter.h"
578

  
579
/* ------------------ export.h ----------------------- */
580
%ignore Column;
581
%ignore DataTable;
582
%ignore XYDataTable;
583
%ignore ScalarDataTable;
584
%ignore ScatterDataTable;
585
%ignore JoinedDataTable;
586
%ignore MatlabStructExport;
587
%ignore MatlabScriptExport;
588
%ignore OctaveTextExport;
589
%rename(EOL)    CsvExport::eol;
590
%newobject ExporterFactory::createExporter;
591
%include "export.h"
src/org.omnetpp.ide.nativelibs/stacktrace.i
1
%{
2

  
3
int printStackTrace(JNIEnv *env)
4
{
5
	jclass clazz = env->FindClass("java/lang/Thread");
6
	if (!clazz)
7
		return -1;
8

  
9
	jmethodID method = env->GetStaticMethodID(clazz, "dumpStack", "()V");
10
	if (!method)
11
		return -2;
12

  
13
	env->CallStaticVoidMethod(clazz, method);
14
	return 0;
15
}
16

  
17
%}
src/org.omnetpp.ide.nativelibs/std_list.i
1
//
2
// SWIG typemaps for std::list
3
// Andras Varga
4
// 2005
5
//
6
// Java implementation
7

  
8

  
9
%include exception.i
10

  
11
// containers
12

  
13
// methods which can raise are caused to throw an IndexError
14
%exception std::list::get {
15
    try {
16
        $action
17
    } catch (std::out_of_range& e) {
18
        SWIG_JavaThrowException(jenv, SWIG_JavaIndexOutOfBoundsException, const_cast<char*>(e.what()));
19
        return $null;
20
    }
21
}
22

  
23
%exception std::list::set {
24
    try {
25
        $action
26
    } catch (std::out_of_range& e) {
27
        SWIG_JavaThrowException(jenv, SWIG_JavaIndexOutOfBoundsException, const_cast<char*>(e.what()));
28
        return $null;
29
    }
30
}
31

  
32

  
33
// ------------------------------------------------------------------------
34
// std::list
35
//
36
// The aim of all that follows would be to integrate std::list with
37
// Java as much as possible, namely, to allow the user to pass and
38
// be returned Java (arrays? containers?)
39
// const declarations are used to guess the intent of the function being
40
// exported; therefore, the following rationale is applied:
41
//
42
//   -- f(std::list<T>), f(const std::list<T>&), f(const std::list<T>*):
43
//      the parameter being read-only, either a Java sequence or a
44
//      previously wrapped std::list<T> can be passed.
45
//   -- f(std::list<T>&), f(std::list<T>*):
46
//      the parameter must be modified; therefore, only a wrapped std::list
47
//      can be passed.
48
//   -- std::list<T> f():
49
//      the list is returned by copy; therefore, a Java sequence of T:s
50
//      is returned which is most easily used in other Java functions
51
//   -- std::list<T>& f(), std::list<T>* f(), const std::list<T>& f(),
52
//      const std::list<T>* f():
53
//      the list is returned by reference; therefore, a wrapped std::list
54
//      is returned
55
// ------------------------------------------------------------------------
56

  
57
%{
58
#include <list>
59
#include <algorithm>
60
#include <stdexcept>
61
%}
62

  
63
// exported class
64

  
65
namespace std {
66

  
67
    template<class T> class list {
68
        // add generic typemaps here
69
        %typemap(javacode) list<T> %{
70
          public T[] toArray() {
71
            int sz = (int)size();
72
            T[] array = new T[sz];
73
            for (int i=0; i<sz; i++)
74
              array[i] = get(i);
75
            return array;
76
          }
77
        %}
78
      public:
79
        list();
80
        unsigned int size() const;
81
        %rename(isEmpty) empty;
82
        bool empty() const;
83
        void clear();
84
        %rename(add) push_back;
85
        void push_back(const T& x);
86
        void push_front(const T& x);
87
        const T& back();
88
        const T& front();
89
        %extend {
90
            T& pop_back() {
91
                if (self->empty())
92
                    throw std::out_of_range("pop invoked on empty list");
93
                T& x = self->back();
94
                self->pop_back();
95
                return x;
96
            }
97
            T& pop_front() {
98
                if (self->empty())
99
                    throw std::out_of_range("pop invoked on empty list");
100
                T& x = self->back();
101
                self->pop_back();
102
                return x;
103
            }
104
            T& get(int i) {
105
                int size = int(self->size());
106
                if (i<0 || i>=size)
107
                    throw std::out_of_range("list index out of range");
108
                std::list<T>::iterator it = self->begin();
109
                for (; i>0; i--) it++;  // linear time!
110
                return (*it);
111
            }
112
            void set(int i, const T& x) {
113
                int size = int(self->size());
114
                if (i<0 || i>=size)
115
                    throw std::out_of_range("list index out of range");
116
                std::list<T>::iterator it = self->begin();
117
                for (; i>0; i--) it++;  // linear time!
118
                (*it) = x;
119
            }
120
            void insert(int i, const T& x) {
121
                int size = int(self->size());
122
                if (i<0 || i>size)  // i==size allowed, for append operation
123
                    throw std::out_of_range("list index out of range");
124
                std::list<T>::iterator it = self->begin();
125
                for (; i>0; i--) it++;  // linear time!
126
                self->insert(it, x);
127
            }
128
            void del(int i) {
129
                int size = int(self->size());
130
                if (i<0 || i>=size)
131
                    throw std::out_of_range("list index out of range");
132
                std::list<T>::iterator it = self->begin();
133
                for (; i>0; i--) it++;  // linear time!
134
                self->erase(it);
135
            }
136
        }
137
    };
138

  
139

  
140
    // specializations for built-ins
141

  
142
    %define specialize_std_list(T)
143
    template<> class list<T> {
144
        // add generic typemaps here
145
        %typemap(javacode) list<T> %{
146
          public T[] toArray() {
147
            int sz = (int)size();
148
            T[] array = new T[sz];
149
            for (int i=0; i<sz; i++)
150
              array[i] = get(i);
151
            return array;
152
          }
153
        %}
154
      public:
155
        list();
156
        unsigned int size() const;
157
        %rename(isEmpty) empty;
158
        bool empty() const;
159
        void clear();
160
        %rename(add) push_back;
161
        void push_back(T x);
162
        void push_front(T x);
163
        T back();
164
        T front();
165
        %extend {
166
            T pop_back() {
167
                if (self->empty())
168
                    throw std::out_of_range("pop invoked on empty list");
169
                T x = self->back();
170
                self->pop_back();
171
                return x;
172
            }
173
            T pop_front() {
174
                if (self->empty())
175
                    throw std::out_of_range("pop invoked on empty list");
176
                T x = self->back();
177
                self->pop_back();
178
                return x;
179
            }
180
            T get(int i) {
181
                int size = int(self->size());
182
                if (i<0 || i>=size)
183
                    throw std::out_of_range("list index out of range");
184
                std::list<T>::iterator it = self->begin();
185
                for (; i>0; i--) it++;  // linear time!
186
                return (*it);
187
            }
188
            void set(int i, T x) {
189
                int size = int(self->size());
190
                if (i<0 || i>=size)
191
                    throw std::out_of_range("list index out of range");
192
                std::list<T>::iterator it = self->begin();
193
                for (; i>0; i--) it++;  // linear time!
194
                (*it) = x;
195
            }
196
            void insert(int i, T x) {
197
                int size = int(self->size());
198
                if (i<0 || i>size)  // i==size allowed, for append operation
199
                    throw std::out_of_range("list index out of range");
200
                std::list<T>::iterator it = self->begin();
201
                for (; i>0; i--) it++;  // linear time!
202
                self->insert(it, x);
203
            }
204
            void del(int i) {
205
                int size = int(self->size());
206
                if (i<0 || i>=size)
207
                    throw std::out_of_range("list index out of range");
208
                std::list<T>::iterator it = self->begin();
209
                for (; i>0; i--) it++;  // linear time!
210
                self->erase(it);
211
            }
212
        }
213
    };
214
    %enddef
215

  
216
    specialize_std_list(bool);
217
    specialize_std_list(char);
218
    specialize_std_list(int);
219
    specialize_std_list(short);
220
    specialize_std_list(long);
221
    specialize_std_list(unsigned char);
222
    specialize_std_list(unsigned int);
223
    specialize_std_list(unsigned short);
224
    specialize_std_list(unsigned long);
225
    specialize_std_list(float);
226
    specialize_std_list(double);
227
    specialize_std_list(std::string);
228

  
229
}
230

  
src/org.omnetpp.ide.nativelibs/std_set.i
1
//
2
// SWIG typemaps for std::set
3
// Andras Varga
4
// Aug. 2005
5
//
6
// Common implementation
7

  
8
%include std_common.i
9
%include exception.i
10

  
11
%exception std::set::del  {
12
    try {
13
        $action
14
    } catch (std::out_of_range& e) {
15
        SWIG_JavaThrowException(jenv, SWIG_JavaIndexOutOfBoundsException, const_cast<char*>(e.what()));
16
        return $null;
17
    }
18
}
19

  
20
// ------------------------------------------------------------------------
21
// std::set
22
// ------------------------------------------------------------------------
23

  
24
%{
25
#include <set>
26
#include <algorithm>
27
#include <stdexcept>
28
%}
29

  
30
// exported class
31

  
32
namespace std {
33

  
34
    template<class T> class set {
35
        // add typemaps here
36
      public:
37
        set();
38
        set(const set<T> &);
39

  
40
        unsigned int size() const;
41
        bool empty() const;
42
        void clear();
43
        %extend {
44
            void insert(const T& key) {
45
                self->insert(key);
46
            }
47
            void del(const T& key) {
48
                std::set<T>::iterator i = self->find(key);
49
                if (i != self->end())
50
                    self->erase(i);
51
                else
52
                    throw std::out_of_range("key not found");
53
            }
54
            bool has_key(const T& key) {
55
                std::set<T>::iterator i = self->find(key);
56
                return i != self->end();
57
            }
58
        }
59
    };
60

  
61
    // specializations for built-ins
62

  
63
    %define specialize_std_set(T)
64

  
65
    template<> class set<T> {
66
        // add typemaps here
67
      public:
68
        set();
69
        set(const set<T> &);
70

  
71
        unsigned int size() const;
72
        bool empty() const;
73
        void clear();
74
        %extend {
75
            void insert(T key) {
76
                self->insert(key);
77
            }
78
            void del(T key) {
79
                std::set<T>::iterator i = self->find(key);
80
                if (i != self->end())
81
                    self->erase(i);
82
                else
83
                    throw std::out_of_range("key not found");
84
            }
85
            bool has_key(T key) {
86
                std::set<T>::iterator i = self->find(key);
87
                return i != self->end();
88
            }
89
        }
90
    };
91

  
92

  
93
    %enddef
94

  
95
    // add specializations here
96

  
97
    specialize_std_set(bool);
98
    specialize_std_set(char);
99
    specialize_std_set(int);
100
    specialize_std_set(short);
101
    specialize_std_set(long);
102
    specialize_std_set(unsigned char);
103
    specialize_std_set(unsigned int);
104
    specialize_std_set(unsigned short);
105
    specialize_std_set(unsigned long);
106
    specialize_std_set(float);
107
    specialize_std_set(double);
108
    specialize_std_set(std::string);
109
}
src/org.omnetpp.ide.nativelibs/std_vector.i
1
/* -----------------------------------------------------------------------------
2
 * See the LICENSE file for information on copyright, usage and redistribution
3
 * of SWIG, and the README file for authors - http://www.swig.org/release.html.
4
 *
5
 * std_vector.i
6
 * ----------------------------------------------------------------------------- */
7

  
8
%include <std_common.i>
9

  
10
%{
11
#include <vector>
12
#include <stdexcept>
13
%}
14

  
15
namespace std {
16

  
17
    template<class T> class vector {
18
      public:
19
        typedef size_t size_type;
20
        typedef T value_type;
21
        typedef const value_type& const_reference;
22
        vector();
23
        vector(size_type n);
24
        size_type size() const;
25
        size_type capacity() const;
26
        void reserve(size_type n);
27
        %rename(isEmpty) empty;
28
        bool empty() const;
29
        void clear();
30
        %rename(add) push_back;
31
        void push_back(const value_type& x);
32
        %extend {
33
            /*const_reference*/T get(int i) throw (std::out_of_range) {
34
                int size = int(self->size());
35
                if (i>=0 && i<size)
36
                    return (*self)[i];
37
                else
38
                    throw std::out_of_range("vector index out of range");
39
            }
40
            void set(int i, const value_type& x) throw (std::out_of_range) {
41
                int size = int(self->size());
42
                if (i>=0 && i<size)
43
                    (*self)[i] = x;
44
                else
45
                    throw std::out_of_range("vector index out of range");
46
            }
47
        }
48
    };
49
}
50

  
51
%define specialize_std_vector(T)
52
#warning "specialize_std_vector - specialization for type T no longer needed"
53
%enddef
54

  

Also available in: Unified diff