Statistics
| Branch: | Revision:

root / src / org.omnetpp.ide.nativelibs / scave.i @ 0418c1a0

History | View | Annotate | Download (18.4 KB)

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"