scilab; new example scilab_const

This commit is contained in:
Simon Marchetto 2014-07-24 17:13:33 +02:00
commit 20987c42d0
6 changed files with 131 additions and 0 deletions

View file

@ -7,6 +7,7 @@ funcptr
matrix
matrix2
pointer
scilab_const
simple
std_list
std_vector

View file

@ -0,0 +1,15 @@
TOP = ../..
SWIG = $(TOP)/../preinst-swig
SRCS = example.cxx
TARGET = example
INTERFACE = example.i
check: build
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' scilab_run
build:
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' SWIG='$(SWIG)' \
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' scilab_cpp
clean:
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' scilab_clean

View file

@ -0,0 +1,37 @@
/* File : example.c */
#include "example.h"
#include <stdio.h>
void Foo::enum_test(speed s) {
if (s == IMPULSE) {
printf("IMPULSE speed\n");
} else if (s == WARP) {
printf("WARP speed\n");
} else if (s == LUDICROUS) {
printf("LUDICROUS speed\n");
} else {
printf("Unknown speed\n");
}
}
void enum_test(color c, Foo::speed s) {
if (c == RED) {
printf("color = RED, ");
} else if (c == BLUE) {
printf("color = BLUE, ");
} else if (c == GREEN) {
printf("color = GREEN, ");
} else {
printf("color = Unknown color!, ");
}
if (s == Foo::IMPULSE) {
printf("speed = IMPULSE speed\n");
} else if (s == Foo::WARP) {
printf("speed = WARP speed\n");
} else if (s == Foo::LUDICROUS) {
printf("speed = LUDICROUS speed\n");
} else {
printf("speed = Unknown speed!\n");
}
}

View file

@ -0,0 +1,20 @@
/* File : example.h */
// Constants
#define ICONST 42
#define FCONST 2.1828
#define SCONST "Hello World"
#define EXPR ICONST + 3 * FCONST
// Enums
enum color { RED, BLUE, GREEN };
class Foo {
public:
Foo() { }
enum speed { IMPULSE, WARP, LUDICROUS };
void enum_test(speed s);
};
void enum_test(enum color c, Foo::speed s);

View file

@ -0,0 +1,15 @@
/* File : example.i */
%module example
%{
#include "example.h"
%}
/* Wraps enums and constants as Scilab variables (instead of functions) */
%scilabconst(1);
%include "example.h"
%constant int iconst = 37;
%constant double fconst = 42.2;

View file

@ -0,0 +1,43 @@
lines(0);
ilib_verbose(0);
exec loader.sce;
example_Init();
printf("\nTest %%scilab_const(1) feature: constants and enums are wrapped as Scilab variables\n");
printf("\nTest enums\n");
printf("*** color ***\n");
printf(" RED = %i\n", RED);
printf(" BLUE = %i\n", BLUE);
printf(" GREEN = %i\n", GREEN);
printf("\n*** Foo::speed ***\n")
printf(" Foo_IMPULSE = %i\n", Foo_IMPULSE);
printf(" Foo_WARP = %i\n", Foo_WARP);
printf(" Foo_LUDICROUS = %i\n", Foo_LUDICROUS);
printf("\nTest enums as argument of functions\n");
enum_test(RED, Foo_IMPULSE);
enum_test(BLUE, Foo_WARP);
enum_test(GREEN, Foo_LUDICROUS);
enum_test(1234, 5678);
printf("\nTest enums as argument of class methods\n");
f = new_Foo();
Foo_enum_test(f, Foo_IMPULSE);
Foo_enum_test(f, Foo_WARP);
Foo_enum_test(f, Foo_LUDICROUS);
delete_Foo(f);
printf("\nTest constants\n");
printf("ICONST = %i (should be 42)\n", ICONST);
printf("FCONST = %5.4f (should be 2.1828)\n", FCONST);
printf("SCONST = ''%s'' (should be ''Hello World'')\n", SCONST);
printf("EXPR = %5.4f (should be 48.5484)\n", EXPR);
printf("iconst = %i (should be 37)\n", iconst);
printf("fconst = %3.2f (should be 42.20)\n", fconst);
exit