Merge branch 'nested' - nested structs/classes support
* nested: Deprecation of the 'nestedworkaround' feature Ensure -c++out is not used with -c++ Add missing header to new source file Nested C class setters restored in c++out mode for Octave Classprefix fixed after private nested classes some comments and spaces added Fix template partial specialization detection Minor tweaks in Swig_feature_set Swig_offset_string moved to misc.c nested private classes are discarded while parsing nested relate functions are moved to nested.cxx and renamed accordingly out-of-scope template definitions fixed nested_private test disabled again fixed out-of-scope nested class definitions, added a test enabled nested C structs assignment (still disabled for Octave), added Java runtime test fixed nested_private test case for Java & C# Testcase of private nested class usage causing segfault C nested struct passed by value example Add in Travis testing for nested branch Add C++ nested class example Minor code improvements Cosmetics/code beautification of nested class support Nested classes support
This commit is contained in:
commit
314fae460b
61 changed files with 2438 additions and 1127 deletions
|
|
@ -5,6 +5,7 @@ class
|
|||
enum
|
||||
extend
|
||||
funcptr
|
||||
nested
|
||||
reference
|
||||
simple
|
||||
template
|
||||
|
|
|
|||
19
Examples/csharp/nested/Makefile
Normal file
19
Examples/csharp/nested/Makefile
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
TOP = ../..
|
||||
SWIG = $(TOP)/../preinst-swig
|
||||
CXXSRCS = example.cxx
|
||||
TARGET = example
|
||||
INTERFACE = example.i
|
||||
SWIGOPT =
|
||||
CSHARPSRCS = *.cs
|
||||
CSHARPFLAGS= -nologo -out:runme.exe
|
||||
|
||||
check: build
|
||||
$(MAKE) -f $(TOP)/Makefile csharp_run
|
||||
|
||||
build:
|
||||
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
|
||||
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' csharp_cpp
|
||||
$(MAKE) -f $(TOP)/Makefile CSHARPSRCS='$(CSHARPSRCS)' CSHARPFLAGS='$(CSHARPFLAGS)' csharp_compile
|
||||
|
||||
clean:
|
||||
$(MAKE) -f $(TOP)/Makefile csharp_clean
|
||||
94
Examples/csharp/nested/example-cs.csproj
Normal file
94
Examples/csharp/nested/example-cs.csproj
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
<VisualStudioProject>
|
||||
<CSHARP
|
||||
ProjectType = "Local"
|
||||
ProductVersion = "7.10.3077"
|
||||
SchemaVersion = "2.0"
|
||||
ProjectGuid = "{C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}"
|
||||
>
|
||||
<Build>
|
||||
<Settings
|
||||
ApplicationIcon = ""
|
||||
AssemblyKeyContainerName = ""
|
||||
AssemblyName = "runme"
|
||||
AssemblyOriginatorKeyFile = ""
|
||||
DefaultClientScript = "JScript"
|
||||
DefaultHTMLPageLayout = "Grid"
|
||||
DefaultTargetSchema = "IE50"
|
||||
DelaySign = "false"
|
||||
OutputType = "Exe"
|
||||
PreBuildEvent = ""
|
||||
PostBuildEvent = ""
|
||||
RootNamespace = "runme"
|
||||
RunPostBuildEvent = "OnBuildSuccess"
|
||||
StartupObject = ""
|
||||
>
|
||||
<Config
|
||||
Name = "Debug"
|
||||
AllowUnsafeBlocks = "false"
|
||||
BaseAddress = "285212672"
|
||||
CheckForOverflowUnderflow = "false"
|
||||
ConfigurationOverrideFile = ""
|
||||
DefineConstants = "DEBUG;TRACE"
|
||||
DocumentationFile = ""
|
||||
DebugSymbols = "true"
|
||||
FileAlignment = "4096"
|
||||
IncrementalBuild = "false"
|
||||
NoStdLib = "false"
|
||||
NoWarn = ""
|
||||
Optimize = "false"
|
||||
OutputPath = ".\"
|
||||
RegisterForComInterop = "false"
|
||||
RemoveIntegerChecks = "false"
|
||||
TreatWarningsAsErrors = "false"
|
||||
WarningLevel = "4"
|
||||
/>
|
||||
<Config
|
||||
Name = "Release"
|
||||
AllowUnsafeBlocks = "false"
|
||||
BaseAddress = "285212672"
|
||||
CheckForOverflowUnderflow = "false"
|
||||
ConfigurationOverrideFile = ""
|
||||
DefineConstants = "TRACE"
|
||||
DocumentationFile = ""
|
||||
DebugSymbols = "false"
|
||||
FileAlignment = "4096"
|
||||
IncrementalBuild = "false"
|
||||
NoStdLib = "false"
|
||||
NoWarn = ""
|
||||
Optimize = "true"
|
||||
OutputPath = ".\"
|
||||
RegisterForComInterop = "false"
|
||||
RemoveIntegerChecks = "false"
|
||||
TreatWarningsAsErrors = "false"
|
||||
WarningLevel = "4"
|
||||
/>
|
||||
</Settings>
|
||||
<References/>
|
||||
</Build>
|
||||
<Files>
|
||||
<Include>
|
||||
<File
|
||||
RelPath = "example.cs"
|
||||
SubType = "Code"
|
||||
BuildAction = "Compile"
|
||||
/>
|
||||
<File
|
||||
RelPath = "examplePINVOKE.cs"
|
||||
SubType = "Code"
|
||||
BuildAction = "Compile"
|
||||
/>
|
||||
<File
|
||||
RelPath = "MotorCar.cs"
|
||||
SubType = "Code"
|
||||
BuildAction = "Compile"
|
||||
/>
|
||||
<File
|
||||
RelPath = "runme.cs"
|
||||
SubType = "Code"
|
||||
BuildAction = "Compile"
|
||||
/>
|
||||
</Include>
|
||||
</Files>
|
||||
</CSHARP>
|
||||
</VisualStudioProject>
|
||||
|
||||
158
Examples/csharp/nested/example-vc.vcproj
Normal file
158
Examples/csharp/nested/example-vc.vcproj
Normal file
|
|
@ -0,0 +1,158 @@
|
|||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="7.10"
|
||||
Name="example"
|
||||
ProjectGUID="{C2302635-D489-4678-96B4-70F5309DCBE6}"
|
||||
Keyword="Win32Proj">
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"/>
|
||||
</Platforms>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
OutputDirectory="Debug"
|
||||
IntermediateDirectory="Debug"
|
||||
ConfigurationType="2"
|
||||
CharacterSet="2">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;EXAMPLEVC_EXPORTS"
|
||||
MinimalRebuild="TRUE"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="1"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="TRUE"
|
||||
DebugInformationFormat="4"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
OutputFile="example.dll"
|
||||
LinkIncremental="2"
|
||||
GenerateDebugInformation="TRUE"
|
||||
ProgramDatabaseFile="$(OutDir)/example.pdb"
|
||||
SubSystem="2"
|
||||
ImportLibrary="$(OutDir)/example.lib"
|
||||
TargetMachine="1"/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"/>
|
||||
<Tool
|
||||
Name="VCManagedWrapperGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory="Release"
|
||||
IntermediateDirectory="Release"
|
||||
ConfigurationType="2"
|
||||
CharacterSet="2">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;EXAMPLEVC_EXPORTS"
|
||||
RuntimeLibrary="0"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="TRUE"
|
||||
DebugInformationFormat="3"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
OutputFile="example.dll"
|
||||
LinkIncremental="1"
|
||||
GenerateDebugInformation="TRUE"
|
||||
SubSystem="2"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
ImportLibrary="$(OutDir)/example.lib"
|
||||
TargetMachine="1"/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"/>
|
||||
<Tool
|
||||
Name="VCManagedWrapperGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
|
||||
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}">
|
||||
<File
|
||||
RelativePath="example.cxx">
|
||||
</File>
|
||||
<File
|
||||
RelativePath="example_wrap.cxx">
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
Filter="h;hpp;hxx;hm;inl;inc;xsd"
|
||||
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}">
|
||||
<File
|
||||
RelativePath="example.h">
|
||||
</File>
|
||||
</Filter>
|
||||
<File
|
||||
RelativePath=".\example.i">
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32">
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
CommandLine="echo Invoking SWIG...
|
||||
echo on
|
||||
..\..\..\swig.exe -c++ -csharp "$(InputPath)"
|
||||
@echo off"
|
||||
Outputs="$(InputName)_wrap.cxx"/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32">
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
CommandLine="echo Invoking SWIG...
|
||||
echo on
|
||||
..\..\..\swig.exe -c++ -csharp "$(InputPath)"
|
||||
@echo off"
|
||||
Outputs="$(InputName)_wrap.cxx"/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
||||
62
Examples/csharp/nested/example.cxx
Normal file
62
Examples/csharp/nested/example.cxx
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
#include "example.h"
|
||||
|
||||
int MotorCar::DesignOpinion::AceDesignCount = 0;
|
||||
int MotorCar::DesignOpinion::TotalDesignCount = 0;
|
||||
|
||||
int MotorCar::DesignOpinion::PercentScore() {
|
||||
return AceDesignCount*100/TotalDesignCount;
|
||||
}
|
||||
|
||||
MotorCar::Wheels::Wheels(Shape shape, size_t count) : shape(shape), count(count) {}
|
||||
|
||||
MotorCar::WindScreen::WindScreen(bool opaque) : opaque(opaque) {}
|
||||
|
||||
MotorCar::MotorCar(const std::string &name, const Wheels &wheels, const WindScreen &windscreen) : name(name), wheels(wheels), windscreen(windscreen) {}
|
||||
|
||||
MotorCar MotorCar::DesignFromComponents(const std::string &name, const Wheels &wheels, const WindScreen &windscreen) {
|
||||
MotorCar car = MotorCar(name, wheels, windscreen);
|
||||
DesignOpinion::TotalDesignCount++;
|
||||
if (car.wheels.Opinion().itrocks && car.windscreen.Opinion().itrocks)
|
||||
DesignOpinion::AceDesignCount++;
|
||||
return car;
|
||||
}
|
||||
|
||||
MotorCar::DesignOpinion MotorCar::Wheels::Opinion() {
|
||||
DesignOpinion opinion;
|
||||
opinion.itrocks = true;
|
||||
if (shape == Square) {
|
||||
opinion.itrocks = false;
|
||||
opinion.reason = "you'll have a few issues with wheel rotation";
|
||||
}
|
||||
if (count <= 2) {
|
||||
opinion.reason += opinion.itrocks ? "" : " and ";
|
||||
opinion.itrocks = false;
|
||||
opinion.reason += "a few more wheels are needed for stability";
|
||||
}
|
||||
if (opinion.itrocks)
|
||||
opinion.reason = "your choice of wheels was top notch";
|
||||
|
||||
return opinion;
|
||||
}
|
||||
|
||||
MotorCar::DesignOpinion MotorCar::WindScreen::Opinion() {
|
||||
DesignOpinion opinion;
|
||||
opinion.itrocks = !opaque;
|
||||
opinion.reason = opinion.itrocks ? "the driver will have a commanding view out the window" : "you can't see out the windscreen";
|
||||
return opinion;
|
||||
}
|
||||
|
||||
std::string MotorCar::WillItWork() {
|
||||
DesignOpinion wh = wheels.Opinion();
|
||||
DesignOpinion ws = windscreen.Opinion();
|
||||
std::string willit;
|
||||
if (wh.itrocks && ws.itrocks) {
|
||||
willit = "Great car design because " + wh.reason + " and " + ws.reason;
|
||||
} else {
|
||||
willit = "You need a rethink because ";
|
||||
willit += wh.itrocks ? "" : wh.reason;
|
||||
willit += (!wh.itrocks && !ws.itrocks) ? " and " : "";
|
||||
willit += ws.itrocks ? "" : ws.reason;
|
||||
}
|
||||
return willit;
|
||||
}
|
||||
48
Examples/csharp/nested/example.h
Normal file
48
Examples/csharp/nested/example.h
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
#include <string>
|
||||
|
||||
/** Design a motor car from various components */
|
||||
struct MotorCar {
|
||||
|
||||
/** Information about an opinion of the design of a car component */
|
||||
struct DesignOpinion {
|
||||
bool itrocks;
|
||||
std::string reason;
|
||||
static int AceDesignCount;
|
||||
static int TotalDesignCount;
|
||||
static int PercentScore();
|
||||
};
|
||||
|
||||
/** Wheels component */
|
||||
struct Wheels {
|
||||
enum Shape { Round, Square };
|
||||
Wheels(Shape shape, size_t count);
|
||||
DesignOpinion Opinion();
|
||||
private:
|
||||
Shape shape;
|
||||
size_t count;
|
||||
};
|
||||
|
||||
/** Windscreen component */
|
||||
struct WindScreen {
|
||||
WindScreen(bool opaque);
|
||||
DesignOpinion Opinion();
|
||||
private:
|
||||
bool opaque;
|
||||
};
|
||||
|
||||
/** Factory method for creating a car */
|
||||
static MotorCar DesignFromComponents(const std::string &name, const Wheels &wheels, const WindScreen &windscreen);
|
||||
|
||||
std::string Name() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/** Get an overall opinion on the car design */
|
||||
std::string WillItWork();
|
||||
|
||||
private:
|
||||
MotorCar(const std::string &name, const Wheels &wheels, const WindScreen &windscreen);
|
||||
std::string name;
|
||||
Wheels wheels;
|
||||
WindScreen windscreen;
|
||||
};
|
||||
13
Examples/csharp/nested/example.i
Normal file
13
Examples/csharp/nested/example.i
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
%module example
|
||||
|
||||
// This example shows how wrappers for numerous aspects of C++ nested classes work:
|
||||
// Nested static and instance variables and methods and nested enums
|
||||
|
||||
%include <std_string.i>
|
||||
|
||||
%{
|
||||
#include "example.h"
|
||||
%}
|
||||
|
||||
%include "example.h"
|
||||
|
||||
30
Examples/csharp/nested/example.sln
Normal file
30
Examples/csharp/nested/example.sln
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
Microsoft Visual Studio Solution File, Format Version 8.00
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "example-cs", "example-cs.csproj", "{C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{C2302635-D489-4678-96B4-70F5309DCBE6} = {C2302635-D489-4678-96B4-70F5309DCBE6}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "example-vc", "example-vc.vcproj", "{C2302635-D489-4678-96B4-70F5309DCBE6}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfiguration) = preSolution
|
||||
Debug = Debug
|
||||
Release = Release
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfiguration) = postSolution
|
||||
{C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug.ActiveCfg = Debug|.NET
|
||||
{C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Debug.Build.0 = Debug|.NET
|
||||
{C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release.ActiveCfg = Release|.NET
|
||||
{C17D27DF-4C57-4625-AEE0-A40C4F48FF1A}.Release.Build.0 = Release|.NET
|
||||
{C2302635-D489-4678-96B4-70F5309DCBE6}.Debug.ActiveCfg = Debug|Win32
|
||||
{C2302635-D489-4678-96B4-70F5309DCBE6}.Debug.Build.0 = Debug|Win32
|
||||
{C2302635-D489-4678-96B4-70F5309DCBE6}.Release.ActiveCfg = Release|Win32
|
||||
{C2302635-D489-4678-96B4-70F5309DCBE6}.Release.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityAddIns) = postSolution
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
27
Examples/csharp/nested/runme.cs
Normal file
27
Examples/csharp/nested/runme.cs
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
// This example illustrates how C++ classes can be used from C# using SWIG.
|
||||
// The C# class gets mapped onto the C++ class and behaves as if it is a C# class.
|
||||
|
||||
using System;
|
||||
|
||||
public class runme
|
||||
{
|
||||
static void Main()
|
||||
{
|
||||
MotorCar car1 = MotorCar.DesignFromComponents("Bumpy", new MotorCar.Wheels(MotorCar.Wheels.Shape.Square, 4), new MotorCar.WindScreen(false));
|
||||
MotorCar car2 = MotorCar.DesignFromComponents("Wobbly", new MotorCar.Wheels(MotorCar.Wheels.Shape.Round, 2), new MotorCar.WindScreen(false));
|
||||
MotorCar car3 = MotorCar.DesignFromComponents("Batty", new MotorCar.Wheels(MotorCar.Wheels.Shape.Round, 4), new MotorCar.WindScreen(true));
|
||||
MotorCar car4 = MotorCar.DesignFromComponents("Spiffing", new MotorCar.Wheels(MotorCar.Wheels.Shape.Round, 4), new MotorCar.WindScreen(false));
|
||||
|
||||
Console.WriteLine("Expert opinion on " + car1.Name() + " : \n " + car1.WillItWork());
|
||||
Console.WriteLine("Expert opinion on " + car2.Name() + " : \n " + car2.WillItWork());
|
||||
Console.WriteLine("Expert opinion on " + car3.Name() + " : \n " + car3.WillItWork());
|
||||
Console.WriteLine("Expert opinion on " + car4.Name() + " : \n " + car4.WillItWork());
|
||||
|
||||
int count = MotorCar.DesignOpinion.AceDesignCount;
|
||||
int total = MotorCar.DesignOpinion.TotalDesignCount;
|
||||
int percent = MotorCar.DesignOpinion.PercentScore();
|
||||
Console.WriteLine("Overall opinion rating on car design is " + count + "/" + total + " = " + percent + "%");
|
||||
|
||||
Console.WriteLine("Single square wheel thoughts: " + new MotorCar.Wheels(MotorCar.Wheels.Shape.Square, 1).Opinion().reason);
|
||||
}
|
||||
}
|
||||
|
|
@ -7,6 +7,7 @@ extend
|
|||
funcptr
|
||||
multimap
|
||||
native
|
||||
nested
|
||||
pointer
|
||||
reference
|
||||
simple
|
||||
|
|
|
|||
18
Examples/java/nested/Makefile
Normal file
18
Examples/java/nested/Makefile
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
TOP = ../..
|
||||
SWIG = $(TOP)/../preinst-swig
|
||||
CXXSRCS = example.cxx
|
||||
TARGET = example
|
||||
INTERFACE = example.i
|
||||
SWIGOPT =
|
||||
JAVASRCS = *.java
|
||||
|
||||
check: build
|
||||
$(MAKE) -f $(TOP)/Makefile java_run
|
||||
|
||||
build:
|
||||
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
|
||||
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java_cpp
|
||||
$(MAKE) -f $(TOP)/Makefile JAVASRCS='$(JAVASRCS)' JAVAFLAGS='$(JAVAFLAGS)' java_compile
|
||||
|
||||
clean:
|
||||
$(MAKE) -f $(TOP)/Makefile java_clean
|
||||
62
Examples/java/nested/example.cxx
Normal file
62
Examples/java/nested/example.cxx
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
#include "example.h"
|
||||
|
||||
int MotorCar::DesignOpinion::AceDesignCount = 0;
|
||||
int MotorCar::DesignOpinion::TotalDesignCount = 0;
|
||||
|
||||
int MotorCar::DesignOpinion::PercentScore() {
|
||||
return AceDesignCount*100/TotalDesignCount;
|
||||
}
|
||||
|
||||
MotorCar::Wheels::Wheels(Shape shape, size_t count) : shape(shape), count(count) {}
|
||||
|
||||
MotorCar::WindScreen::WindScreen(bool opaque) : opaque(opaque) {}
|
||||
|
||||
MotorCar::MotorCar(const std::string &name, const Wheels &wheels, const WindScreen &windscreen) : name(name), wheels(wheels), windscreen(windscreen) {}
|
||||
|
||||
MotorCar MotorCar::DesignFromComponents(const std::string &name, const Wheels &wheels, const WindScreen &windscreen) {
|
||||
MotorCar car = MotorCar(name, wheels, windscreen);
|
||||
DesignOpinion::TotalDesignCount++;
|
||||
if (car.wheels.Opinion().itrocks && car.windscreen.Opinion().itrocks)
|
||||
DesignOpinion::AceDesignCount++;
|
||||
return car;
|
||||
}
|
||||
|
||||
MotorCar::DesignOpinion MotorCar::Wheels::Opinion() {
|
||||
DesignOpinion opinion;
|
||||
opinion.itrocks = true;
|
||||
if (shape == Square) {
|
||||
opinion.itrocks = false;
|
||||
opinion.reason = "you'll have a few issues with wheel rotation";
|
||||
}
|
||||
if (count <= 2) {
|
||||
opinion.reason += opinion.itrocks ? "" : " and ";
|
||||
opinion.itrocks = false;
|
||||
opinion.reason += "a few more wheels are needed for stability";
|
||||
}
|
||||
if (opinion.itrocks)
|
||||
opinion.reason = "your choice of wheels was top notch";
|
||||
|
||||
return opinion;
|
||||
}
|
||||
|
||||
MotorCar::DesignOpinion MotorCar::WindScreen::Opinion() {
|
||||
DesignOpinion opinion;
|
||||
opinion.itrocks = !opaque;
|
||||
opinion.reason = opinion.itrocks ? "the driver will have a commanding view out the window" : "you can't see out the windscreen";
|
||||
return opinion;
|
||||
}
|
||||
|
||||
std::string MotorCar::WillItWork() {
|
||||
DesignOpinion wh = wheels.Opinion();
|
||||
DesignOpinion ws = windscreen.Opinion();
|
||||
std::string willit;
|
||||
if (wh.itrocks && ws.itrocks) {
|
||||
willit = "Great car design because " + wh.reason + " and " + ws.reason;
|
||||
} else {
|
||||
willit = "You need a rethink because ";
|
||||
willit += wh.itrocks ? "" : wh.reason;
|
||||
willit += (!wh.itrocks && !ws.itrocks) ? " and " : "";
|
||||
willit += ws.itrocks ? "" : ws.reason;
|
||||
}
|
||||
return willit;
|
||||
}
|
||||
162
Examples/java/nested/example.dsp
Normal file
162
Examples/java/nested/example.dsp
Normal file
|
|
@ -0,0 +1,162 @@
|
|||
# Microsoft Developer Studio Project File - Name="example" - Package Owner=<4>
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||
# ** DO NOT EDIT **
|
||||
|
||||
# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
|
||||
|
||||
CFG=example - Win32 Release
|
||||
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||
!MESSAGE use the Export Makefile command and run
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "example.mak".
|
||||
!MESSAGE
|
||||
!MESSAGE You can specify a configuration when running NMAKE
|
||||
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "example.mak" CFG="example - Win32 Release"
|
||||
!MESSAGE
|
||||
!MESSAGE Possible choices for configuration are:
|
||||
!MESSAGE
|
||||
!MESSAGE "example - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
|
||||
!MESSAGE "example - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
|
||||
!MESSAGE
|
||||
|
||||
# Begin Project
|
||||
# PROP AllowPerConfigDependencies 0
|
||||
# PROP Scc_ProjName ""
|
||||
# PROP Scc_LocalPath ""
|
||||
CPP=cl.exe
|
||||
MTL=midl.exe
|
||||
RSC=rc.exe
|
||||
|
||||
!IF "$(CFG)" == "example - Win32 Debug"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 1
|
||||
# PROP BASE Output_Dir "Debug"
|
||||
# PROP BASE Intermediate_Dir "Debug"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 1
|
||||
# PROP Output_Dir "Debug"
|
||||
# PROP Intermediate_Dir "Debug"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "EXAMPLE_EXPORTS" /YX /FD /GZ /c
|
||||
# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "$(JAVA_INCLUDE)" /I "$(JAVA_INCLUDE)\win32" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "EXAMPLE_EXPORTS" /YX /FD /GZ /c
|
||||
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
|
||||
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
|
||||
# ADD BASE RSC /l 0x809 /d "_DEBUG"
|
||||
# ADD RSC /l 0x809 /d "_DEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
|
||||
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /dll /debug /machine:I386 /out:"example.dll" /pdbtype:sept
|
||||
# Begin Special Build Tool
|
||||
SOURCE="$(InputPath)"
|
||||
PostBuild_Desc=Java compile post-build step
|
||||
PostBuild_Cmds=echo on "%JAVA_BIN%\javac" *.java
|
||||
# End Special Build Tool
|
||||
|
||||
!ELSEIF "$(CFG)" == "example - Win32 Release"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "Release"
|
||||
# PROP BASE Intermediate_Dir "Release"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "Release"
|
||||
# PROP Intermediate_Dir "Release"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "EXAMPLE_EXPORTS" /YX /FD /c
|
||||
# ADD CPP /nologo /MT /W3 /GX /O2 /I "$(JAVA_INCLUDE)" /I "$(JAVA_INCLUDE)\win32" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "EXAMPLE_EXPORTS" /YX /FD /c
|
||||
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD BASE RSC /l 0x809 /d "NDEBUG"
|
||||
# ADD RSC /l 0x809 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /dll /machine:I386
|
||||
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /dll /machine:I386 /out:"example.dll"
|
||||
# Begin Special Build Tool
|
||||
SOURCE="$(InputPath)"
|
||||
PostBuild_Desc=Java compile post-build step
|
||||
PostBuild_Cmds=echo on "%JAVA_BIN%\javac" *.java
|
||||
# End Special Build Tool
|
||||
|
||||
!ENDIF
|
||||
|
||||
# Begin Target
|
||||
|
||||
# Name "example - Win32 Debug"
|
||||
# Name "example - Win32 Release"
|
||||
# Begin Group "Source Files"
|
||||
|
||||
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\example.cxx
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\example_wrap.cxx
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Header Files"
|
||||
|
||||
# PROP Default_Filter "h;hpp;hxx;hm;inl"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\example.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Resource Files"
|
||||
|
||||
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
|
||||
# End Group
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\example.i
|
||||
|
||||
!IF "$(CFG)" == "example - Win32 Debug"
|
||||
|
||||
# Begin Custom Build
|
||||
InputPath=.\example.i
|
||||
InputName=example
|
||||
|
||||
"$(InputName)_wrap.cxx" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
|
||||
echo In order to function correctly, please ensure the following environment variables are correctly set:
|
||||
echo JAVA_INCLUDE: %JAVA_INCLUDE%
|
||||
echo JAVA_BIN: %JAVA_BIN%
|
||||
echo on
|
||||
..\..\..\swig.exe -c++ -java "$(InputPath)"
|
||||
|
||||
# End Custom Build
|
||||
|
||||
!ELSEIF "$(CFG)" == "example - Win32 Release"
|
||||
|
||||
# Begin Custom Build
|
||||
InputPath=.\example.i
|
||||
InputName=example
|
||||
|
||||
"$(InputName)_wrap.cxx" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
|
||||
echo In order to function correctly, please ensure the following environment variables are correctly set:
|
||||
echo JAVA_INCLUDE: %JAVA_INCLUDE%
|
||||
echo JAVA_BIN: %JAVA_BIN%
|
||||
echo on
|
||||
..\..\..\swig.exe -c++ -java "$(InputPath)"
|
||||
|
||||
# End Custom Build
|
||||
|
||||
!ENDIF
|
||||
|
||||
# End Source File
|
||||
# End Target
|
||||
# End Project
|
||||
48
Examples/java/nested/example.h
Normal file
48
Examples/java/nested/example.h
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
#include <string>
|
||||
|
||||
/** Design a motor car from various components */
|
||||
struct MotorCar {
|
||||
|
||||
/** Information about an opinion of the design of a car component */
|
||||
struct DesignOpinion {
|
||||
bool itrocks;
|
||||
std::string reason;
|
||||
static int AceDesignCount;
|
||||
static int TotalDesignCount;
|
||||
static int PercentScore();
|
||||
};
|
||||
|
||||
/** Wheels component */
|
||||
struct Wheels {
|
||||
enum Shape { Round, Square };
|
||||
Wheels(Shape shape, size_t count);
|
||||
DesignOpinion Opinion();
|
||||
private:
|
||||
Shape shape;
|
||||
size_t count;
|
||||
};
|
||||
|
||||
/** Windscreen component */
|
||||
struct WindScreen {
|
||||
WindScreen(bool opaque);
|
||||
DesignOpinion Opinion();
|
||||
private:
|
||||
bool opaque;
|
||||
};
|
||||
|
||||
/** Factory method for creating a car */
|
||||
static MotorCar DesignFromComponents(const std::string &name, const Wheels &wheels, const WindScreen &windscreen);
|
||||
|
||||
std::string Name() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/** Get an overall opinion on the car design */
|
||||
std::string WillItWork();
|
||||
|
||||
private:
|
||||
MotorCar(const std::string &name, const Wheels &wheels, const WindScreen &windscreen);
|
||||
std::string name;
|
||||
Wheels wheels;
|
||||
WindScreen windscreen;
|
||||
};
|
||||
13
Examples/java/nested/example.i
Normal file
13
Examples/java/nested/example.i
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
%module example
|
||||
|
||||
// This example shows how wrappers for numerous aspects of C++ nested classes work:
|
||||
// Nested static and instance variables and methods and nested enums
|
||||
|
||||
%include <std_string.i>
|
||||
|
||||
%{
|
||||
#include "example.h"
|
||||
%}
|
||||
|
||||
%include "example.h"
|
||||
|
||||
32
Examples/java/nested/runme.java
Normal file
32
Examples/java/nested/runme.java
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
// This example illustrates wrapping of nested C++ classes
|
||||
|
||||
public class runme {
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("example");
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e);
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String argv[])
|
||||
{
|
||||
MotorCar car1 = MotorCar.DesignFromComponents("Bumpy", new MotorCar.Wheels(MotorCar.Wheels.Shape.Square, 4), new MotorCar.WindScreen(false));
|
||||
MotorCar car2 = MotorCar.DesignFromComponents("Wobbly", new MotorCar.Wheels(MotorCar.Wheels.Shape.Round, 2), new MotorCar.WindScreen(false));
|
||||
MotorCar car3 = MotorCar.DesignFromComponents("Batty", new MotorCar.Wheels(MotorCar.Wheels.Shape.Round, 4), new MotorCar.WindScreen(true));
|
||||
MotorCar car4 = MotorCar.DesignFromComponents("Spiffing", new MotorCar.Wheels(MotorCar.Wheels.Shape.Round, 4), new MotorCar.WindScreen(false));
|
||||
|
||||
System.out.println("Expert opinion on " + car1.Name() + " : \n " + car1.WillItWork());
|
||||
System.out.println("Expert opinion on " + car2.Name() + " : \n " + car2.WillItWork());
|
||||
System.out.println("Expert opinion on " + car3.Name() + " : \n " + car3.WillItWork());
|
||||
System.out.println("Expert opinion on " + car4.Name() + " : \n " + car4.WillItWork());
|
||||
|
||||
int count = MotorCar.DesignOpinion.getAceDesignCount();
|
||||
int total = MotorCar.DesignOpinion.getTotalDesignCount();
|
||||
int percent = MotorCar.DesignOpinion.PercentScore();
|
||||
System.out.println("Overall opinion rating on car design is " + count + "/" + total + " = " + percent + "%");
|
||||
|
||||
System.out.println("Single square wheel thoughts: " + new MotorCar.Wheels(MotorCar.Wheels.Shape.Square, 1).Opinion().getReason());
|
||||
}
|
||||
}
|
||||
|
|
@ -84,6 +84,7 @@ CPP_TEST_BROKEN += \
|
|||
extend_variable \
|
||||
li_std_vector_ptr \
|
||||
li_boost_shared_ptr_template \
|
||||
nested_private \
|
||||
overload_complicated \
|
||||
template_default_pointer \
|
||||
template_expr \
|
||||
|
|
@ -279,6 +280,7 @@ CPP_TEST_CASES += \
|
|||
naturalvar_more \
|
||||
nested_class \
|
||||
nested_comment \
|
||||
nested_scope \
|
||||
nested_workaround \
|
||||
newobject1 \
|
||||
null_pointer \
|
||||
|
|
|
|||
|
|
@ -3,14 +3,12 @@ This was reported in bug #909389 */
|
|||
|
||||
%module derived_nested
|
||||
|
||||
%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) BB::CC;
|
||||
%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) BB::DD;
|
||||
%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) BB::EE;
|
||||
%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) BB::FF;
|
||||
|
||||
%inline %{
|
||||
|
||||
class A { int x; };
|
||||
class A {
|
||||
public:
|
||||
int x;
|
||||
};
|
||||
class B {
|
||||
class C { int y; }; //generates a warning
|
||||
class D : public A { int z; }; //ok
|
||||
|
|
|
|||
|
|
@ -14,59 +14,59 @@ public class nested_class_runme {
|
|||
|
||||
public static void main(String argv[]) {
|
||||
Outer outer = new Outer();
|
||||
SWIGTYPE_p_Outer__InnerStruct1 is1 = outer.makeInnerStruct1();
|
||||
SWIGTYPE_p_Outer__InnerClass1 ic1 = outer.makeInnerClass1();
|
||||
SWIGTYPE_p_Outer__InnerUnion1 iu1 = outer.makeInnerUnion1();
|
||||
Outer.InnerStruct1 is1 = outer.makeInnerStruct1();
|
||||
Outer.InnerClass1 ic1 = outer.makeInnerClass1();
|
||||
Outer.InnerUnion1 iu1 = outer.makeInnerUnion1();
|
||||
|
||||
SWIGTYPE_p_Outer__InnerStruct2 is2 = outer.makeInnerStruct2();
|
||||
SWIGTYPE_p_Outer__InnerClass2 ic2 = outer.makeInnerClass2();
|
||||
SWIGTYPE_p_Outer__InnerUnion2 iu2 = outer.makeInnerUnion2();
|
||||
Outer.InnerStruct2 is2 = outer.makeInnerStruct2();
|
||||
Outer.InnerClass2 ic2 = outer.makeInnerClass2();
|
||||
Outer.InnerUnion2 iu2 = outer.makeInnerUnion2();
|
||||
|
||||
SWIGTYPE_p_Outer__InnerClass4Typedef ic4 = outer.makeInnerClass4Typedef();
|
||||
SWIGTYPE_p_Outer__InnerStruct4Typedef is4 = outer.makeInnerStruct4Typedef();
|
||||
SWIGTYPE_p_Outer__InnerUnion4Typedef iu4 = outer.makeInnerUnion4Typedef();
|
||||
Outer.InnerClass4Typedef ic4 = outer.makeInnerClass4Typedef();
|
||||
Outer.InnerStruct4Typedef is4 = outer.makeInnerStruct4Typedef();
|
||||
Outer.InnerUnion4Typedef iu4 = outer.makeInnerUnion4Typedef();
|
||||
|
||||
SWIGTYPE_p_Outer__InnerClass5 ic5 = outer.makeInnerClass5();
|
||||
SWIGTYPE_p_Outer__InnerStruct5 is5 = outer.makeInnerStruct5();
|
||||
SWIGTYPE_p_Outer__InnerUnion5 iu5 = outer.makeInnerUnion5();
|
||||
Outer.InnerClass5Typedef ic5 = outer.makeInnerClass5();
|
||||
Outer.InnerStruct5Typedef is5 = outer.makeInnerStruct5();
|
||||
Outer.InnerUnion5Typedef iu5 = outer.makeInnerUnion5();
|
||||
|
||||
ic5 = outer.makeInnerClass5Typedef();
|
||||
is5 = outer.makeInnerStruct5Typedef();
|
||||
iu5 = outer.makeInnerUnion5Typedef();
|
||||
|
||||
{
|
||||
SWIGTYPE_p_Outer__InnerMultiple im1 = outer.getMultipleInstance1();
|
||||
SWIGTYPE_p_Outer__InnerMultiple im2 = outer.getMultipleInstance2();
|
||||
SWIGTYPE_p_Outer__InnerMultiple im3 = outer.getMultipleInstance3();
|
||||
SWIGTYPE_p_Outer__InnerMultiple im4 = outer.getMultipleInstance4();
|
||||
Outer.InnerMultiple im1 = outer.getMultipleInstance1();
|
||||
Outer.InnerMultiple im2 = outer.getMultipleInstance2();
|
||||
Outer.InnerMultiple im3 = outer.getMultipleInstance3();
|
||||
Outer.InnerMultiple im4 = outer.getMultipleInstance4();
|
||||
}
|
||||
|
||||
{
|
||||
SWIGTYPE_p_Outer__InnerMultipleDerived im1 = outer.getMultipleDerivedInstance1();
|
||||
SWIGTYPE_p_Outer__InnerMultipleDerived im2 = outer.getMultipleDerivedInstance2();
|
||||
SWIGTYPE_p_Outer__InnerMultipleDerived im3 = outer.getMultipleDerivedInstance3();
|
||||
SWIGTYPE_p_Outer__InnerMultipleDerived im4 = outer.getMultipleDerivedInstance4();
|
||||
Outer.InnerMultipleDerived im1 = outer.getMultipleDerivedInstance1();
|
||||
Outer.InnerMultipleDerived im2 = outer.getMultipleDerivedInstance2();
|
||||
Outer.InnerMultipleDerived im3 = outer.getMultipleDerivedInstance3();
|
||||
Outer.InnerMultipleDerived im4 = outer.getMultipleDerivedInstance4();
|
||||
}
|
||||
|
||||
{
|
||||
SWIGTYPE_p_Outer__InnerMultipleDerived im1 = outer.getMultipleDerivedInstance1();
|
||||
SWIGTYPE_p_Outer__InnerMultipleDerived im2 = outer.getMultipleDerivedInstance2();
|
||||
SWIGTYPE_p_Outer__InnerMultipleDerived im3 = outer.getMultipleDerivedInstance3();
|
||||
SWIGTYPE_p_Outer__InnerMultipleDerived im4 = outer.getMultipleDerivedInstance4();
|
||||
Outer.InnerMultipleDerived im1 = outer.getMultipleDerivedInstance1();
|
||||
Outer.InnerMultipleDerived im2 = outer.getMultipleDerivedInstance2();
|
||||
Outer.InnerMultipleDerived im3 = outer.getMultipleDerivedInstance3();
|
||||
Outer.InnerMultipleDerived im4 = outer.getMultipleDerivedInstance4();
|
||||
}
|
||||
|
||||
{
|
||||
SWIGTYPE_p_Outer__InnerMultipleAnonTypedef1 mat1 = outer.makeInnerMultipleAnonTypedef1();
|
||||
SWIGTYPE_p_Outer__InnerMultipleAnonTypedef2 mat2 = outer.makeInnerMultipleAnonTypedef2();
|
||||
SWIGTYPE_p_Outer__InnerMultipleAnonTypedef3 mat3 = outer.makeInnerMultipleAnonTypedef3();
|
||||
Outer.InnerMultipleAnonTypedef1 mat1 = outer.makeInnerMultipleAnonTypedef1();
|
||||
Outer.InnerMultipleAnonTypedef1 mat2 = outer.makeInnerMultipleAnonTypedef2();
|
||||
SWIGTYPE_p_p_Outer__InnerMultipleAnonTypedef1 mat3 = outer.makeInnerMultipleAnonTypedef3();
|
||||
|
||||
SWIGTYPE_p_Outer__InnerMultipleNamedTypedef mnt = outer.makeInnerMultipleNamedTypedef();
|
||||
SWIGTYPE_p_Outer__InnerMultipleNamedTypedef mnt1 = outer.makeInnerMultipleNamedTypedef1();
|
||||
SWIGTYPE_p_Outer__InnerMultipleNamedTypedef mnt2 = outer.makeInnerMultipleNamedTypedef2();
|
||||
Outer.InnerMultipleNamedTypedef1 mnt = outer.makeInnerMultipleNamedTypedef();
|
||||
Outer.InnerMultipleNamedTypedef1 mnt1 = outer.makeInnerMultipleNamedTypedef1();
|
||||
Outer.InnerMultipleNamedTypedef1 mnt2 = outer.makeInnerMultipleNamedTypedef2();
|
||||
SWIGTYPE_p_p_Outer__InnerMultipleNamedTypedef mnt3 = outer.makeInnerMultipleNamedTypedef3();
|
||||
}
|
||||
{
|
||||
SWIGTYPE_p_Outer__InnerSameName isn = outer.makeInnerSameName();
|
||||
Outer.InnerSameName isn = outer.makeInnerSameName();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,21 +17,28 @@ public class nested_structs_runme {
|
|||
nested_structs.setValues(outer, 10);
|
||||
|
||||
Outer_inner1 inner1 = outer.getInner1();
|
||||
Outer_inner2 inner2 = outer.getInner2();
|
||||
Outer_inner3 inner3 = outer.getInner3();
|
||||
Outer_inner4 inner4 = outer.getInner4();
|
||||
Outer_inner1 inner2 = outer.getInner2();
|
||||
Outer_inner1 inner3 = outer.getInner3();
|
||||
Outer_inner1 inner4 = outer.getInner4();
|
||||
if (inner1.getVal() != 10) throw new RuntimeException("failed inner1");
|
||||
if (inner2.getVal() != 20) throw new RuntimeException("failed inner2");
|
||||
if (inner3.getVal() != 20) throw new RuntimeException("failed inner3");
|
||||
if (inner4.getVal() != 40) throw new RuntimeException("failed inner4");
|
||||
|
||||
Outer_inside1 inside1 = outer.getInside1();
|
||||
Outer_inside2 inside2 = outer.getInside2();
|
||||
Outer_inside3 inside3 = outer.getInside3();
|
||||
Outer_inside4 inside4 = outer.getInside4();
|
||||
Named inside1 = outer.getInside1();
|
||||
Named inside2 = outer.getInside2();
|
||||
Named inside3 = outer.getInside3();
|
||||
Named inside4 = outer.getInside4();
|
||||
if (inside1.getVal() != 100) throw new RuntimeException("failed inside1");
|
||||
if (inside2.getVal() != 200) throw new RuntimeException("failed inside2");
|
||||
if (inside3.getVal() != 200) throw new RuntimeException("failed inside3");
|
||||
if (inside4.getVal() != 400) throw new RuntimeException("failed inside4");
|
||||
|
||||
outer.getInner1().setVal(11);
|
||||
if (inner1.getVal() != 11) throw new RuntimeException("failed inner1 assignment");
|
||||
Named named = new Named();
|
||||
named.setVal(22);
|
||||
outer.setInside2(named);
|
||||
if (outer.getInside2().getVal() != 22) throw new RuntimeException("failed inside2 assignment");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,10 @@ public class template_nested_runme {
|
|||
T_NestedOuterTemplateDouble tn = new T_NestedOuterTemplateDouble();
|
||||
if (tn.hohum(-12.3) != -12.3)
|
||||
throw new RuntimeException("it failed");
|
||||
OuterClass.T_OuterClassInner1Int inner1 = new OuterClass().useInner1(new OuterClass.T_OuterClassInner1Int());
|
||||
OuterClass.T_OuterClassInner2NormalClass inner2 = new OuterClass.T_OuterClassInner2NormalClass();
|
||||
inner2.setEmbeddedVar(2);
|
||||
OuterClass.T_OuterClassInner2NormalClass inner22 = new OuterClass().useInner2Again(inner2);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
%module namespace_class
|
||||
|
||||
%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Ala::Ola;
|
||||
|
||||
#ifdef SWIGD
|
||||
%warnfilter(SWIGWARN_IGNORE_OPERATOR_LT);
|
||||
|
|
@ -216,9 +215,6 @@ namespace a
|
|||
|
||||
%}
|
||||
|
||||
// %copyctor doesn't work with nested class workaround
|
||||
%nocopyctor;
|
||||
|
||||
%inline %{
|
||||
class Ala {
|
||||
public :
|
||||
|
|
@ -236,12 +232,6 @@ namespace a
|
|||
};
|
||||
%}
|
||||
|
||||
%rename(Ala__Ola) Ala::Ola;
|
||||
class Ala::Ola {
|
||||
public:
|
||||
Ola() {}
|
||||
void eek() {}
|
||||
};
|
||||
|
||||
%template(hi) Ala::hi<int>;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
%module namespace_union
|
||||
|
||||
#pragma SWIG nowarn=SWIGWARN_PARSE_UNNAMED_NESTED_CLASS
|
||||
|
||||
%inline %{
|
||||
namespace SpatialIndex
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,25 +1,5 @@
|
|||
%module nested_class
|
||||
|
||||
#pragma SWIG nowarn=SWIGWARN_PARSE_UNNAMED_NESTED_CLASS
|
||||
%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerStruct1;
|
||||
%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerClass1;
|
||||
%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerUnion1;
|
||||
%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerClass2;
|
||||
%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerStruct2;
|
||||
%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerUnion2;
|
||||
%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerClass4Typedef;
|
||||
%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerStruct4Typedef;
|
||||
%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerUnion4Typedef;
|
||||
%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerClass5;
|
||||
%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerStruct5;
|
||||
%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerUnion5;
|
||||
%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerMultiple;
|
||||
%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerMultipleDerived;
|
||||
%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerMultipleAnonTypedef1;
|
||||
%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerMultipleNamedTypedef;
|
||||
%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer::InnerSameName;
|
||||
%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) Outer2::IgnoreMe;
|
||||
|
||||
%inline %{
|
||||
struct Outer {
|
||||
typedef int Integer;
|
||||
|
|
@ -39,7 +19,7 @@ struct Outer {
|
|||
};
|
||||
|
||||
///////////////////////////////////////////
|
||||
#ifdef SWIG
|
||||
#if defined(__GNUC__) || defined(_MSC_VER) || defined(SWIG)
|
||||
/* some compilers do not accept these */
|
||||
class {
|
||||
public:
|
||||
|
|
@ -154,7 +134,7 @@ struct Outer {
|
|||
Integer xx;
|
||||
} MultipleInstanceAnonDerived1, MultipleInstanceAnonDerived2, *MultipleInstanceAnonDerived3, MultipleInstanceAnonDerived4[2];
|
||||
|
||||
#ifdef SWIG
|
||||
#if defined(__GNUC__) || defined(_MSC_VER) || defined(SWIG)
|
||||
/* some compilers do not accept these */
|
||||
struct : public InnerMultiple {
|
||||
Integer xx;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
%module nested_comment
|
||||
|
||||
#pragma SWIG nowarn=SWIGWARN_PARSE_UNNAMED_NESTED_CLASS
|
||||
|
||||
// this example shows a problem with 'dump_nested' (parser.y).
|
||||
|
||||
// bug #949654
|
||||
|
|
|
|||
32
Examples/test-suite/nested_private.i
Normal file
32
Examples/test-suite/nested_private.i
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
%module nested_private
|
||||
|
||||
// segfault due to private nested class usage
|
||||
|
||||
%inline %{
|
||||
#include <string>
|
||||
class MotorCar {
|
||||
|
||||
struct DesignOpinion {
|
||||
std::string reason;
|
||||
};
|
||||
|
||||
public:
|
||||
struct WindScreen {
|
||||
WindScreen(bool opaque) : opaque(opaque) {}
|
||||
DesignOpinion Opinion();
|
||||
private:
|
||||
bool opaque;
|
||||
};
|
||||
|
||||
std::string WindScreenOpinion() {
|
||||
return MotorCar::WindScreen(true).Opinion().reason;
|
||||
}
|
||||
};
|
||||
|
||||
MotorCar::DesignOpinion MotorCar::WindScreen::Opinion() {
|
||||
DesignOpinion opinion;
|
||||
opinion.reason = !opaque ? "great design" : "you can't see out the windscreen";
|
||||
return opinion;
|
||||
}
|
||||
|
||||
%}
|
||||
14
Examples/test-suite/nested_scope.i
Normal file
14
Examples/test-suite/nested_scope.i
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
%module nested_scope
|
||||
|
||||
%inline %{
|
||||
namespace ns {
|
||||
struct Global {
|
||||
struct Outer {
|
||||
struct Nested;
|
||||
};
|
||||
struct Outer::Nested {
|
||||
int data;
|
||||
} instance;
|
||||
};
|
||||
}
|
||||
%}
|
||||
|
|
@ -25,5 +25,21 @@ void setValues(struct Outer *outer, int val) {
|
|||
outer->inside4[0].val = val * 4;
|
||||
outer->inside5 = &outer->inside3;
|
||||
}
|
||||
|
||||
int getInside1Val(struct Outer *n) { return n->inside1.val; }
|
||||
%}
|
||||
|
||||
/*
|
||||
Below was causing problems in Octave as wrappers were compiled as C++.
|
||||
Solution requires regenerating the inner struct into
|
||||
the global C++ namespace (which is where it is intended to be in C).
|
||||
*/
|
||||
%inline %{
|
||||
int nestedByVal(struct Named s);
|
||||
int nestedByPtr(struct Named *s);
|
||||
%}
|
||||
%{
|
||||
int nestedByVal(struct Named s) { return s.val; }
|
||||
int nestedByPtr(struct Named *s) { return s->val; }
|
||||
%}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,14 +1,6 @@
|
|||
%module nested_workaround
|
||||
// Similar to "Nested classes" documentation example.
|
||||
|
||||
class Inner {
|
||||
int val;
|
||||
public:
|
||||
Inner(int v = 0) : val(v) {}
|
||||
void setValue(int v) { val = v; }
|
||||
int getValue() const { return val; }
|
||||
};
|
||||
%nestedworkaround Outer::Inner;
|
||||
// "flatnested" emulates deprecated feature "nested_workaround" for the languages not supporting nested classes
|
||||
%feature ("flatnested");
|
||||
|
||||
%inline %{
|
||||
class Outer {
|
||||
|
|
@ -28,11 +20,3 @@ public:
|
|||
}
|
||||
};
|
||||
%}
|
||||
|
||||
// We've fooled SWIG into thinking that Inner is a global class, so now we need
|
||||
// to trick the C++ compiler into understanding this apparent global type.
|
||||
%{
|
||||
typedef Outer::Inner Inner;
|
||||
%}
|
||||
|
||||
|
||||
|
|
|
|||
14
Examples/test-suite/octave/nested_structs_runme.m
Normal file
14
Examples/test-suite/octave/nested_structs_runme.m
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
nested_structs
|
||||
|
||||
named = nested_structs.Named();
|
||||
named.val = 999;
|
||||
assert(nested_structs.nestedByVal(named), 999);
|
||||
assert(nested_structs.nestedByPtr(named), 999);
|
||||
|
||||
outer = nested_structs.Outer();
|
||||
outer.inside1.val = 456;
|
||||
assert(nested_structs.getInside1Val(outer), 456);
|
||||
|
||||
outer.inside1 = named;
|
||||
assert(nested_structs.getInside1Val(outer), 999);
|
||||
|
||||
|
|
@ -2,13 +2,6 @@
|
|||
|
||||
// Test nested templates - that is template classes and template methods within a class.
|
||||
|
||||
%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) ns::OuterClass::Inner1;
|
||||
%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) ns::OuterClass::Inner2;
|
||||
%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) ns::OuterTemplate::NestedInnerTemplate1;
|
||||
%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) ns::OuterTemplate::NestedInnerTemplate2;
|
||||
%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) ns::OuterTemplate::NestedInnerTemplate3;
|
||||
%warnfilter(SWIGWARN_PARSE_NAMED_NESTED_CLASS) ns::OuterTemplate::NestedStruct;
|
||||
|
||||
namespace ns {
|
||||
template <class T> struct ForwardTemplate;
|
||||
}
|
||||
|
|
@ -33,7 +26,13 @@ namespace ns {
|
|||
template <class T> struct NormalTemplate {
|
||||
void tmethod(T t) {}
|
||||
};
|
||||
}
|
||||
%}
|
||||
%template(T_NormalTemplateNormalClass) ns::NormalTemplate<ns::NormalClass>;
|
||||
%template(T_NormalTemplateInt) ns::NormalTemplate<int>;
|
||||
|
||||
%inline %{
|
||||
namespace ns {
|
||||
class OuterClass {
|
||||
public:
|
||||
template <class T> struct Inner1 {
|
||||
|
|
@ -70,6 +69,7 @@ namespace ns {
|
|||
};
|
||||
};
|
||||
Inner2<int> useInner2(const Inner2<int>& inner) { return inner; }
|
||||
Inner2<NormalClass> useInner2Again(const Inner2<NormalClass>& inner) { return inner; }
|
||||
int iii;
|
||||
};
|
||||
struct ABC {
|
||||
|
|
@ -108,9 +108,10 @@ namespace ns {
|
|||
|
||||
%}
|
||||
|
||||
%template(T_NormalTemplateNormalClass) ns::NormalTemplate<ns::NormalClass>;
|
||||
%template(T_OuterTMethodNormalClass) ns::OuterClass::InnerTMethod<ns::NormalClass>;
|
||||
%template(T_TemplateFuncs1Int) ns::TemplateFuncs::templateMethod1<int>;
|
||||
%template(T_TemplateFuncs2Double) ns::TemplateFuncs::templateMethod2<double>;
|
||||
%template(T_NestedOuterTemplateDouble) ns::OuterTemplate<double>;
|
||||
|
||||
%template(T_OuterClassInner1Int) ns::OuterClass::Inner1<int>;
|
||||
%template(T_OuterClassInner2NormalClass) ns::OuterClass::Inner2<ns::NormalClass>;
|
||||
%template(T_OuterClassInner2Int) ns::OuterClass::Inner2<int>;
|
||||
|
|
|
|||
|
|
@ -4,18 +4,22 @@
|
|||
|
||||
// Testing that the typemaps invoked within a class via %template are picked up by appropriate methods
|
||||
|
||||
%inline %{
|
||||
template <typename T> struct Typemap {
|
||||
#ifdef SWIG
|
||||
%typemap(in) T {
|
||||
$1 = -99;
|
||||
}
|
||||
#endif
|
||||
};
|
||||
template <> struct Typemap<short> { // Note explicit specialization
|
||||
#ifdef SWIG
|
||||
%typemap(in) short {
|
||||
$1 = -77;
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
%inline %{
|
||||
int globalInt1(int s) { return s; }
|
||||
short globalShort1(short s) { return s; }
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
%warnfilter(SWIGWARN_RUBY_WRONG_NAME) nRState; // Ruby, wrong class name
|
||||
%warnfilter(SWIGWARN_RUBY_WRONG_NAME) nRState_rstate; // Ruby, wrong class name
|
||||
#pragma SWIG nowarn=SWIGWARN_PARSE_UNNAMED_NESTED_CLASS
|
||||
|
||||
%inline %{
|
||||
class nRState {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue