Many major improvements. Almost all testsuite compiles now.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@11189 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
a2dc2756c8
commit
32e03aa13d
25 changed files with 1052 additions and 609 deletions
|
|
@ -1,4 +1,5 @@
|
|||
# see top-level Makefile.in
|
||||
class
|
||||
simple
|
||||
class
|
||||
std_vector
|
||||
exception
|
||||
|
|
|
|||
30
Examples/c/std_vector/Makefile
Normal file
30
Examples/c/std_vector/Makefile
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
TOP = ../..
|
||||
SWIG = $(TOP)/../preinst-swig -debug-module 4 > tree.txt
|
||||
CXXSRCS = example.cxx
|
||||
TARGET = example
|
||||
INTERFACE = example.i
|
||||
RUNME = runme.c
|
||||
PROXY = example_proxy.c
|
||||
INCLUDES =
|
||||
MEMTOOL = valgrind --leak-check=full
|
||||
|
||||
all::
|
||||
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
|
||||
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' INCLUDES='$(INCLUDES)' c_cpp
|
||||
$(MAKE) -f $(TOP)/Makefile RUNME='$(RUNME)' PROXY='$(PROXY)' \
|
||||
TARGET='$(TARGET)' c_compile
|
||||
|
||||
run:
|
||||
env LD_LIBRARY_PATH=. ./runme
|
||||
|
||||
memchk:
|
||||
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
|
||||
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' CXXFLAGS='-g' INCLUDES='$(INCLUDES)' c_cpp
|
||||
$(MAKE) -f $(TOP)/Makefile RUNME='$(RUNME)' PROXY='$(PROXY)' \
|
||||
TARGET='$(TARGET)' CFLAGS='-g' c_compile
|
||||
env LD_LIBRARY_PATH=. $(MEMTOOL) ./runme
|
||||
|
||||
clean:
|
||||
rm -f *.o *.out *.so *.a *.dll *.dylib *.exe *_wrap* *_proxy* *~ runme
|
||||
|
||||
check: all
|
||||
2
Examples/c/std_vector/example.cxx
Normal file
2
Examples/c/std_vector/example.cxx
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
/* File : example.c */
|
||||
|
||||
18
Examples/c/std_vector/example.h
Normal file
18
Examples/c/std_vector/example.h
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
/* File : example.h */
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class A {
|
||||
public:
|
||||
A() : name(""), value(0) {}
|
||||
A(std::string str, int i) : name(str), value(i) {}
|
||||
std::string name;
|
||||
int value;
|
||||
};
|
||||
|
||||
class Klass {
|
||||
public:
|
||||
std::vector<int> vi;
|
||||
std::vector<A> va;
|
||||
};
|
||||
14
Examples/c/std_vector/example.i
Normal file
14
Examples/c/std_vector/example.i
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
/* File : example.i */
|
||||
%module example
|
||||
%include <std_string.i>
|
||||
%include <std_vector.i>
|
||||
|
||||
%{
|
||||
#include "example.h"
|
||||
%}
|
||||
|
||||
/* Let's just grab the original header file here */
|
||||
%include "example.h"
|
||||
|
||||
%template(Vint) std::vector<int>;
|
||||
%template(VA) std::vector<A>;
|
||||
37
Examples/c/std_vector/runme.c
Normal file
37
Examples/c/std_vector/runme.c
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
#include "example_proxy.h"
|
||||
|
||||
int main() {
|
||||
Klass *klass = new_Klass();
|
||||
Vint *vint = Klass_vi_get(klass);
|
||||
VA *va = Klass_va_get(klass);
|
||||
|
||||
printf("Vector of ints:\n");
|
||||
printf("size=%d\ncapacity=%d\n\n", Vint_size(vint), Vint_capacity(vint));
|
||||
|
||||
int i;
|
||||
for (i = 0; i < 10; i++)
|
||||
Vint_push_back(vint, i*i);
|
||||
|
||||
printf("size=%d\ncapacity=%d\n\n", Vint_size(vint), Vint_capacity(vint));
|
||||
|
||||
for (i = 0; i < Vint_size(vint); i++)
|
||||
printf("%d%c", Vint_at(vint, i), i+1 == Vint_size(vint) ? '\n' : ',');
|
||||
|
||||
Vint_clear(vint);
|
||||
Vint_reserve(vint, 100);
|
||||
printf("\nsize=%d\ncapacity=%d\n", Vint_size(vint), Vint_capacity(vint));
|
||||
|
||||
printf("\nVector of objects:\n");
|
||||
|
||||
for (i = 0; i < 10; i++) {
|
||||
A *a = new_A_std_string_i("hello", i);
|
||||
VA_push_back(va, a);
|
||||
}
|
||||
|
||||
for (i = 0; i < VA_size(va); i++) {
|
||||
A *a = VA_at(va, i);
|
||||
printf("%s %d\n", A_name_get(a), A_value_get(a));
|
||||
}
|
||||
|
||||
SWIG_exit(0);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue