From 44b9d7a0101f2445b17e8295e8d8b36b6cfd308f Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 11 Jul 2004 21:16:24 +0000 Subject: [PATCH] Duplicate to class example. Removed git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@6032 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- SWIG/Examples/perl5/shadow/.cvsignore | 10 -- SWIG/Examples/perl5/shadow/Makefile | 20 --- SWIG/Examples/perl5/shadow/example.cxx | 28 --- SWIG/Examples/perl5/shadow/example.h | 41 ----- SWIG/Examples/perl5/shadow/example.i | 11 -- SWIG/Examples/perl5/shadow/index.html | 233 ------------------------- SWIG/Examples/perl5/shadow/runme.pl | 56 ------ 7 files changed, 399 deletions(-) delete mode 100644 SWIG/Examples/perl5/shadow/.cvsignore delete mode 100644 SWIG/Examples/perl5/shadow/Makefile delete mode 100644 SWIG/Examples/perl5/shadow/example.cxx delete mode 100644 SWIG/Examples/perl5/shadow/example.h delete mode 100644 SWIG/Examples/perl5/shadow/example.i delete mode 100644 SWIG/Examples/perl5/shadow/index.html delete mode 100644 SWIG/Examples/perl5/shadow/runme.pl diff --git a/SWIG/Examples/perl5/shadow/.cvsignore b/SWIG/Examples/perl5/shadow/.cvsignore deleted file mode 100644 index 618145e24..000000000 --- a/SWIG/Examples/perl5/shadow/.cvsignore +++ /dev/null @@ -1,10 +0,0 @@ -example.pm -*_wrap.c -*_wrap.cxx -example.dll -example.dsw -example.ncb -example.opt -example.plg -Release -Debug diff --git a/SWIG/Examples/perl5/shadow/Makefile b/SWIG/Examples/perl5/shadow/Makefile deleted file mode 100644 index 2f01aed66..000000000 --- a/SWIG/Examples/perl5/shadow/Makefile +++ /dev/null @@ -1,20 +0,0 @@ -TOP = ../.. -SWIG = $(TOP)/../swig -CXXSRCS = example.cxx -TARGET = example -INTERFACE = example.i -LIBS = -lm -SWIGOPT = - -all:: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ - SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' perl5_cpp - -static:: - $(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \ - SWIGOPT='$(SWIGOPT)' TARGET='myperl' INTERFACE='$(INTERFACE)' perl5_cpp_static - -clean:: - $(MAKE) -f $(TOP)/Makefile perl5_clean - -check: all diff --git a/SWIG/Examples/perl5/shadow/example.cxx b/SWIG/Examples/perl5/shadow/example.cxx deleted file mode 100644 index 1e8e203dd..000000000 --- a/SWIG/Examples/perl5/shadow/example.cxx +++ /dev/null @@ -1,28 +0,0 @@ -/* File : example.c */ - -#include "example.h" -#define M_PI 3.14159265358979323846 - -/* Move the shape to a new location */ -void Shape::move(double dx, double dy) { - x += dx; - y += dy; -} - -int Shape::nshapes = 0; - -double Circle::area(void) { - return M_PI*radius*radius; -} - -double Circle::perimeter(void) { - return 2*M_PI*radius; -} - -double Square::area(void) { - return width*width; -} - -double Square::perimeter(void) { - return 4*width; -} diff --git a/SWIG/Examples/perl5/shadow/example.h b/SWIG/Examples/perl5/shadow/example.h deleted file mode 100644 index 1f6f8b304..000000000 --- a/SWIG/Examples/perl5/shadow/example.h +++ /dev/null @@ -1,41 +0,0 @@ -/* File : example.h */ - -class Shape { -public: - Shape() { - nshapes++; - } - virtual ~Shape() { - nshapes--; - }; - double x, y; - void move(double dx, double dy); - virtual double area(void) = 0; - virtual double perimeter(void) = 0; - static int nshapes; -}; - -class Circle : public Shape { -private: - double radius; -public: - Circle(double r) : radius(r) { }; - ~Circle() { }; - virtual double area(void); - virtual double perimeter(void); -}; - -class Square : public Shape { -private: - double width; -public: - Square(double w) : width(w) { }; - ~Square() { } - virtual double area(void); - virtual double perimeter(void); -}; - - - - - diff --git a/SWIG/Examples/perl5/shadow/example.i b/SWIG/Examples/perl5/shadow/example.i deleted file mode 100644 index 23ee8a822..000000000 --- a/SWIG/Examples/perl5/shadow/example.i +++ /dev/null @@ -1,11 +0,0 @@ -/* File : example.i */ -%module example - -%{ -#include "example.h" -%} - -/* Let's just grab the original header file here */ - -%include "example.h" - diff --git a/SWIG/Examples/perl5/shadow/index.html b/SWIG/Examples/perl5/shadow/index.html deleted file mode 100644 index ecfdb6d0f..000000000 --- a/SWIG/Examples/perl5/shadow/index.html +++ /dev/null @@ -1,233 +0,0 @@ - - -SWIG:Examples:perl5:class - - - - - -SWIG/Examples/perl5/class/ -
- -

Wrapping a simple C++ class

- -$Header$
- -

-This example illustrates the most primitive form of C++ class wrapping performed -by SWIG. In this case, C++ classes are simply transformed into a collection of -C-style functions that provide access to class members. - -

The C++ Code

- -Suppose you have some C++ classes described by the following (and admittedly lame) -header file: - -
-
-/* File : example.h */
-
-class Shape {
-public:
-  Shape() {
-    nshapes++;
-  }
-  virtual ~Shape() {
-    nshapes--;
-  };
-  double  x, y;   
-  void    move(double dx, double dy);
-  virtual double area() = 0;
-  virtual double perimeter() = 0;
-  static  int nshapes;
-};
-
-class Circle : public Shape {
-private:
-  double radius;
-public:
-  Circle(double r) : radius(r) { };
-  virtual double area();
-  virtual double perimeter();
-};
-
-class Square : public Shape {
-private:
-  double width;
-public:
-  Square(double w) : width(w) { };
-  virtual double area();
-  virtual double perimeter();
-};
-
-
- -

The SWIG interface

- -A simple SWIG interface for this can be built by simply grabbing the header file -like this: - -
-
-/* File : example.i */
-%module example
-
-%{
-#include "example.h"
-%}
-
-/* Let's just grab the original header file here */
-%include "example.h"
-
-
- -Note: when creating a C++ extension, you must run SWIG with the -c++ option like this: -
-
-% swig -c++ -python example.i
-
-
- -

A sample Perl script

- -Click here to see a script that calls the C++ functions from Perl. - -

Key points

- - - -

General Comments

- - - -
- - diff --git a/SWIG/Examples/perl5/shadow/runme.pl b/SWIG/Examples/perl5/shadow/runme.pl deleted file mode 100644 index b69d83ec0..000000000 --- a/SWIG/Examples/perl5/shadow/runme.pl +++ /dev/null @@ -1,56 +0,0 @@ -# file: runme.pl - -# This file illustrates the low-level C++ interface -# created by SWIG. In this case, all of our C++ classes -# get converted into function calls. - -use example; - -# ----- Object creation ----- - -print "Creating some objects:\n"; -$c = new example::Circle(10); -print " Created circle $c\n"; -$s = new example::Square(10); -print " Created square $s\n"; - -# ----- Access a static member ----- - -print "\nA total of $example::Shape::nshapes shapes were created\n"; - -# ----- Member data access ----- - -# Set the location of the object. -# Note: methods in the base class Shape are used since -# x and y are defined there. - -$c->{x} = 20; -$c->{y} = 30; -$s->{x} = -10; -$s->{y} = 5; - -print "\nHere is their current position:\n"; -print " Circle = (",$c->{x},",", $c->{y},")\n"; -print " Square = (",$s->{x},",", $s->{y},")\n"; - -# ----- Call some methods ----- - -print "\nHere are some properties of the shapes:\n"; -foreach $o ($c,$s) { - print " $o\n"; - print " area = ", $o->area(), "\n"; - print " perimeter = ", $o->perimeter(), "\n"; - } - -# ----- Delete everything ----- - -print "\nGuess I'll clean up now\n"; - -# Note: this invokes the virtual destructor - -$c->DESTROY(); -$s->DESTROY(); - -print $example::Shape::nshapes," shapes remain\n"; -print "Goodbye\n"; -