[Go] Renamed 'FooBarAbs' to 'FooBarAbstract' in the documentation and examples.
This commit is contained in:
parent
85037c3a33
commit
608ef60ecf
5 changed files with 144 additions and 140 deletions
|
|
@ -1,70 +1,72 @@
|
|||
package example
|
||||
|
||||
// FooBarGo is a superset of FooBarAbs and hence FooBarGo can be used as a drop
|
||||
// in replacement for FooBarAbs but the reverse causes a compile time error.
|
||||
// FooBarGo is a superset of FooBarAbstract and hence FooBarGo can be used as a
|
||||
// drop in replacement for FooBarAbstract but the reverse causes a compile time
|
||||
// error.
|
||||
type FooBarGo interface {
|
||||
FooBarAbs
|
||||
deleteFooBarAbs()
|
||||
FooBarAbstract
|
||||
deleteFooBarAbstract()
|
||||
IsFooBarGo()
|
||||
}
|
||||
|
||||
// Via embedding fooBarGo "inherits" all methods of FooBarAbs.
|
||||
// Via embedding fooBarGo "inherits" all methods of FooBarAbstract.
|
||||
type fooBarGo struct {
|
||||
FooBarAbs
|
||||
FooBarAbstract
|
||||
}
|
||||
|
||||
func (fbgs *fooBarGo) deleteFooBarAbs() {
|
||||
DeleteDirectorFooBarAbs(fbgs.FooBarAbs)
|
||||
func (fbgs *fooBarGo) deleteFooBarAbstract() {
|
||||
DeleteDirectorFooBarAbstract(fbgs.FooBarAbstract)
|
||||
}
|
||||
|
||||
// The IsFooBarGo method ensures that FooBarGo is a superset of FooBarAbs.
|
||||
// The IsFooBarGo method ensures that FooBarGo is a superset of FooBarAbstract.
|
||||
// This is also how the class hierarchy gets represented by the SWIG generated
|
||||
// wrapper code. For an instance FooBarCpp has the IsFooBarAbs and IsFooBarCpp
|
||||
// methods.
|
||||
// wrapper code. For an instance FooBarCpp has the IsFooBarAbstract and
|
||||
// IsFooBarCpp methods.
|
||||
func (fbgs *fooBarGo) IsFooBarGo() {}
|
||||
|
||||
// Go type that defines the DirectorInterface. It contains the Foo and Bar
|
||||
// methods that overwrite the respective virtual C++ methods on FooBarAbs.
|
||||
type overwrittenMethodsOnFooBarAbs struct {
|
||||
// Backlink to FooBarAbs so that the rest of the class can be used by the
|
||||
// overridden methods.
|
||||
fb FooBarAbs
|
||||
// methods that overwrite the respective virtual C++ methods on FooBarAbstract.
|
||||
type overwrittenMethodsOnFooBarAbstract struct {
|
||||
// Backlink to FooBarAbstract so that the rest of the class can be used by
|
||||
// the overridden methods.
|
||||
fb FooBarAbstract
|
||||
|
||||
// If additional constructor arguments have been given they are typically
|
||||
// stored here so that the overriden methods can use them.
|
||||
}
|
||||
|
||||
func (om *overwrittenMethodsOnFooBarAbs) Foo() string {
|
||||
// DirectorFooBarAbsFoo calls the base method FooBarAbs::Foo.
|
||||
return "Go " + DirectorFooBarAbsFoo(om.fb)
|
||||
func (om *overwrittenMethodsOnFooBarAbstract) Foo() string {
|
||||
// DirectorFooBarAbstractFoo calls the base method FooBarAbstract::Foo.
|
||||
return "Go " + DirectorFooBarAbstractFoo(om.fb)
|
||||
}
|
||||
|
||||
func (om *overwrittenMethodsOnFooBarAbs) Bar() string {
|
||||
func (om *overwrittenMethodsOnFooBarAbstract) Bar() string {
|
||||
return "Go Bar"
|
||||
}
|
||||
|
||||
func NewFooBarGo() FooBarGo {
|
||||
// Instantiate FooBarAbs with selected methods overridden. The methods that
|
||||
// will be overwritten are defined on overwrittenMethodsOnFooBarAbs and have
|
||||
// a compatible signature to the respective virtual C++ methods.
|
||||
// Furthermore additional constructor arguments will be typically stored in
|
||||
// the overwrittenMethodsOnFooBarAbs struct.
|
||||
om := &overwrittenMethodsOnFooBarAbs{}
|
||||
fb := NewDirectorFooBarAbs(om)
|
||||
// Instantiate FooBarAbstract with selected methods overridden. The methods
|
||||
// that will be overwritten are defined on
|
||||
// overwrittenMethodsOnFooBarAbstract and have a compatible signature to the
|
||||
// respective virtual C++ methods. Furthermore additional constructor
|
||||
// arguments will be typically stored in the
|
||||
// overwrittenMethodsOnFooBarAbstract struct.
|
||||
om := &overwrittenMethodsOnFooBarAbstract{}
|
||||
fb := NewDirectorFooBarAbstract(om)
|
||||
om.fb = fb // Backlink causes cycle as fb.v = om!
|
||||
|
||||
fbgs := &fooBarGo{FooBarAbs: fb}
|
||||
// The memory of the FooBarAbs director object instance can be automatically
|
||||
// freed once the FooBarGo instance is garbage collected by uncommenting the
|
||||
// following line. Please make sure to understand the runtime.SetFinalizer
|
||||
// specific gotchas before doing this. Furthemore DeleteFooBarGo should be
|
||||
// deleted if a finalizer is in use or the fooBarGo struct needs additional
|
||||
// data to prevent double deletion.
|
||||
// runtime.SetFinalizer(fbgs, FooBarGo.deleteFooBarAbs)
|
||||
fbgs := &fooBarGo{FooBarAbstract: fb}
|
||||
// The memory of the FooBarAbstract director object instance can be
|
||||
// automatically freed once the FooBarGo instance is garbage collected by
|
||||
// uncommenting the following line. Please make sure to understand the
|
||||
// runtime.SetFinalizer specific gotchas before doing this. Furthemore
|
||||
// DeleteFooBarGo should be deleted if a finalizer is in use or the fooBarGo
|
||||
// struct needs additional data to prevent double deletion.
|
||||
// runtime.SetFinalizer(fbgs, FooBarGo.deleteFooBarAbstract)
|
||||
return fbgs
|
||||
}
|
||||
|
||||
// Recommended to be removed if runtime.SetFinalizer is in use.
|
||||
func DeleteFooBarGo(fbg FooBarGo) {
|
||||
fbg.deleteFooBarAbs()
|
||||
fbg.deleteFooBarAbstract()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,11 +6,11 @@
|
|||
#include <string>
|
||||
|
||||
|
||||
class FooBarAbs
|
||||
class FooBarAbstract
|
||||
{
|
||||
public:
|
||||
FooBarAbs() {};
|
||||
virtual ~FooBarAbs() {};
|
||||
FooBarAbstract() {};
|
||||
virtual ~FooBarAbstract() {};
|
||||
|
||||
std::string FooBar() {
|
||||
return this->Foo() + ", " + this->Bar();
|
||||
|
|
@ -25,11 +25,11 @@ protected:
|
|||
};
|
||||
|
||||
|
||||
class FooBarCpp : public FooBarAbs
|
||||
class FooBarCpp : public FooBarAbstract
|
||||
{
|
||||
protected:
|
||||
virtual std::string Foo() {
|
||||
return "C++ " + FooBarAbs::Foo();
|
||||
return "C++ " + FooBarAbstract::Foo();
|
||||
}
|
||||
|
||||
virtual std::string Bar() {
|
||||
|
|
|
|||
|
|
@ -7,5 +7,5 @@
|
|||
#include "director.h"
|
||||
%}
|
||||
|
||||
%feature("director") FooBarAbs;
|
||||
%feature("director") FooBarAbstract;
|
||||
%include "director.h"
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ Classes</a> documentation subsection for an explanation of this example.
|
|||
<p>
|
||||
<ul>
|
||||
<li><a href="director.go">director.go</a>. Go source with the definition of the FooBarGo class.
|
||||
<li><a href="director.h">director.h</a>. Header with the definition of the FooBarAbs and FooBarCpp classes.
|
||||
<li><a href="director.h">director.h</a>. Header with the definition of the FooBarAbstract and FooBarCpp classes.
|
||||
<li><a href="example.i">example.i</a>. SWIG interface file.
|
||||
<li><a href="runme.go">runme.go</a>. Sample Go program.
|
||||
</ul>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue