Skip to content

Inheritance

This section covers single and multiple inheritances.

Single Inheritance

Assume we have two types: Bicycle inherited from Vehicle:

/**
 * __API__
 * action: gen_class
 * shared_ref: True
 * package: inheritance
 */
class Vehicle {
public:

    Vehicle(int numberOfSeats) : _numberOfSeats(numberOfSeats) {};

    /**
     * __API__
     * action: gen_getter
     * throws: no_throw
     */
    int numberOfSeats() const {
        return _numberOfSeats;
    };

    /**
     * __API__
     * action: gen_method
     * throws: no_throw
     */
     virtual std::string type() const = 0;

     virtual ~Vehicle() = default;
private:
    int _numberOfSeats;
};
/**
 * __API__
 * action: gen_class
 * shared_ref: True
 * package: inheritance
 */
class Bicycle : public Vehicle {
public:
    /**
     * __API__
     * action: gen_constructor
     * throws: no_throw
     */
    Bicycle(int numberOfSeats) : Vehicle(numberOfSeats) {
        name = "bicycle";
    };

    /**
     * __API__
     * action: gen_method
     * throws: no_throw
     */
    std::string type() const override {
        return name;
    }

    std::string name;
};

/**
 * __API__
 * action: gen_class
 * shared_ref: True
 * package: inheritance
 */
class ElectricBicycle : public Bicycle {
public:
    /**
     * __API__
     * action: gen_constructor
     * throws: no_throw
     */
    ElectricBicycle(int numberOfSeats) : Bicycle(numberOfSeats) {
        name = "ElectricBicycle";
    };

    /**
     * __API__
     * action: gen_method
     * throws: no_throw
     * name: type
     * is_overridden: True
     */
    std::string bicycleType(){
        return name;
    }

    std::string name;
};


/**
 * __API__
 * action: gen_class
 * shared_ref: True
 * package: inheritance
 */
class MountainBicycle : public Bicycle {
public:
    /**
     * __API__
     * action: gen_constructor
     * throws: no_throw
     */
    MountainBicycle(int numberOfSeats) : Bicycle(numberOfSeats) {};

    /**
     * __API__
     * action: gen_method
     * throws: no_throw
     */
    std::string type() const override {
        return "MountainBicycle";
    }

};

/**
 * __API__
 * action: gen_class
 * shared_ref: True
 * package: inheritance
 */
class ElectricCityBicycle : public ElectricBicycle {
public:
    /**
     * __API__
     * action: gen_constructor
     * throws: no_throw
     */
    ElectricCityBicycle(int numberOfSeats) : ElectricBicycle(numberOfSeats) {};

    /**
     * __API__
     * action: gen_method
     * throws: no_throw
     */
    std::string type() const override {
        return "ElectricCityBicycle";
    }

};

As this is a single inheritance, we don't have to add something special. CppBind generates two classes, one inherited from the other.

Note

We have used the same value for the shared_ref attribute for both classes. It is mandatory. This attribute should be the same in the type hierarchy.

Note

If the type parsed is inherited from another one that does not have an __API__, i.e., is not parsed by CppBind, then in the binding code, it won't appear as a base type for the target type.

Usage examples:

val bicycle = Bicycle(1)
assert(bicycle.numberOfSeats == 1)
bicycle = Bicycle(1)
assert bicycle.number_of_seats == 1
let bicycle = Bicycle(numberOfSeats: 1)
assert(bicycle.numberOfSeats == 1)
Generated bindings

/**
 *   ______ .______   .______   .______    __  .__   __.  _______  
 *  /      ||   _  \  |   _  \  |   _  \  |  | |  \ |  | |       \ 
 * |  ,----'|  |_)  | |  |_)  | |  |_)  | |  | |   \|  | |  .--.  |
 * |  |     |   ___/  |   ___/  |   _  <  |  | |  . `  | |  |  |  |
 * |  `----.|  |      |  |      |  |_)  | |  | |  |\   | |  '--'  |
 *  \______|| _|      | _|      |______/  |__| |__| \__| |_______/ 
 * 
 * This file is generated by cppbind on 11/21/2022-15:52.
 * Please do not change it manually.
 */

package com.examples.inheritance

import com.examples.cppbind.*
import com.examples.cppbind.exceptions.*

open class Vehicle
internal constructor(obj: CppBindObject) : AutoCloseable {
    companion object {
        init {
            System.loadLibrary("wrapper_jni")
        }

        /**
         * An internal property to keep an information about the underlying C++ object type.
         * It is intended to be used by the generated code.
         */
        const val cppbindCxxTypeName: String = "cppbind::example::Vehicle"

        /**
         * An internal method to create a Kotlin object from a C++ object.
         * It is intended to be used by the generated code.
         */
        public fun cppbindConstructObject(id: Long, owner: Boolean = false): Vehicle {
            val idType = jGettypebyid(id)
            val obj : Vehicle
            when (idType) {
                ElectricCityBicycle.cppbindCxxTypeName -> obj = ElectricCityBicycle(CppBindObject(id, owner))
                ElectricBicycle.cppbindCxxTypeName -> obj = ElectricBicycle(CppBindObject(id, owner))
                MountainBicycle.cppbindCxxTypeName -> obj = MountainBicycle(CppBindObject(id, owner))
                Bicycle.cppbindCxxTypeName -> obj = Bicycle(CppBindObject(id, owner))
                else -> obj = Vehicle(CppBindObject(id, owner))
            }
            return obj
        }
    }

    protected var cppbindObj = obj
    private var refs: MutableList<Any> = mutableListOf()

    /**
     * An internal method to bind the lifetimes of the current and another object.
     * It is intended to be used by the generated code.
     */
    fun keepCppBindReference(ref: Any) {
        refs.add(ref)
    }
    /**
     * An internal getter to get the id of an object.
     * It is intended to be used by the generated code.
     */
    open val cppbindObjId: Long
        get() {
            if (cppbindObj.id == 0L) {
                throw RuntimeException("Object is not allocated")
            }
            return cppbindObj.id
        }

    /**
     * An internal property returning underlying C++ object id.
     * It is intended to be used by the generated code.
     */
    internal val cxxId: Long by lazy {
        jGetcxxid(cppbindObj.id)
    }

    /**
     * An internal property returning underlying C++ type name.
     * It is intended to be used by the generated code.
     */
    internal val cxxTypeName: String by lazy {
        jGettypebyid(cppbindObj.id)
    }

    val numberOfSeats: Int
        get() {
            val result = jNumberofseats(cppbindObjId)

            return result
        }

    open fun type(): String {
        val result = jType(cppbindObjId)

        return result
    }

    /**
     * CppBind generated hashCode method returning the hash of underlying C++ object id.
     */
    override fun hashCode(): Int {
        return cxxId.hashCode()
    }

    /**
     * CppBind generated equals method comparing the underlying C++ object ids.
     */
    override fun equals(other: Any?): Boolean {
        other as Vehicle
        return cxxId == other.cxxId
    }

    /**
     * CppBind generated toString method returning underlying C++ object type and id.
     */
    override fun toString(): String {
        return "<0x$cxxId: $cxxTypeName>"
    }

    override fun close() {
        if (cppbindObj.owner && cppbindObj.id != 0L) {
            jFinalize(cppbindObj.id)
            cppbindObj.id = 0L
        }
    }

    /**
     * Finalize and deletes the object
     */
    protected fun finalize() {
        close()
    }

    ///// External wrapper functions ////////////
    private external fun jNumberofseats(id: Long): Int
    private external fun jType(id: Long): String
    private external fun jFinalize(id: Long): Unit
    private external fun jGetcxxid(id: Long): Long
}

private external fun jGettypebyid(id: Long): String
/**
 *   ______ .______   .______   .______    __  .__   __.  _______  
 *  /      ||   _  \  |   _  \  |   _  \  |  | |  \ |  | |       \ 
 * |  ,----'|  |_)  | |  |_)  | |  |_)  | |  | |   \|  | |  .--.  |
 * |  |     |   ___/  |   ___/  |   _  <  |  | |  . `  | |  |  |  |
 * |  `----.|  |      |  |      |  |_)  | |  | |  |\   | |  '--'  |
 *  \______|| _|      | _|      |______/  |__| |__| \__| |_______/ 
 * 
 * This file is generated by cppbind on 11/22/2022-06:40.
 * Please do not change it manually.
 */

package com.examples.inheritance

import com.examples.cppbind.*
import com.examples.cppbind.exceptions.*

open class Bicycle
internal constructor(obj: CppBindObject) : Vehicle(obj) {
    companion object {

        protected fun constructHelper(numberOfSeats: Int): Long {
            val id = jConstructor(numberOfSeats)
            return id
        }

        @JvmStatic
        private external fun jConstructor(numberOfSeats: Int, vararg extraObjs: Any?): Long
        /**
         * An internal property to keep an information about the underlying C++ object type.
         * It is intended to be used by the generated code.
         */
        const val cppbindCxxTypeName: String = "cppbind::example::Bicycle"

        /**
         * An internal method to create a Kotlin object from a C++ object.
         * It is intended to be used by the generated code.
         */
        public fun cppbindConstructObject(id: Long, owner: Boolean = false): Bicycle {
            val idType = jGettypebyid(id)
            val obj : Bicycle
            when (idType) {
                ElectricCityBicycle.cppbindCxxTypeName -> obj = ElectricCityBicycle(CppBindObject(id, owner))
                ElectricBicycle.cppbindCxxTypeName -> obj = ElectricBicycle(CppBindObject(id, owner))
                MountainBicycle.cppbindCxxTypeName -> obj = MountainBicycle(CppBindObject(id, owner))
                else -> obj = Bicycle(CppBindObject(id, owner))
            }
            return obj
        }
    }


    constructor(numberOfSeats: Int): this(CppBindObject(constructHelper(numberOfSeats), true)) {
    }

    open override fun type(): String {
        val result = jType(cppbindObjId)

        return result
    }

    ///// External wrapper functions ////////////
    private external fun jType(id: Long): String
}

open class ElectricBicycle
internal constructor(obj: CppBindObject) : Bicycle(obj) {
    companion object {

        protected fun constructHelper(numberOfSeats: Int): Long {
            val id = jConstructor(numberOfSeats)
            return id
        }

        @JvmStatic
        private external fun jConstructor(numberOfSeats: Int, vararg extraObjs: Any?): Long
        /**
         * An internal property to keep an information about the underlying C++ object type.
         * It is intended to be used by the generated code.
         */
        const val cppbindCxxTypeName: String = "cppbind::example::ElectricBicycle"

        /**
         * An internal method to create a Kotlin object from a C++ object.
         * It is intended to be used by the generated code.
         */
        public fun cppbindConstructObject(id: Long, owner: Boolean = false): ElectricBicycle {
            val idType = jGettypebyid(id)
            val obj : ElectricBicycle
            when (idType) {
                ElectricCityBicycle.cppbindCxxTypeName -> obj = ElectricCityBicycle(CppBindObject(id, owner))
                else -> obj = ElectricBicycle(CppBindObject(id, owner))
            }
            return obj
        }
    }


    constructor(numberOfSeats: Int): this(CppBindObject(constructHelper(numberOfSeats), true)) {
    }

    override fun type(): String {
        val result = jType(cppbindObjId)

        return result
    }

    ///// External wrapper functions ////////////
    private external fun jType(id: Long): String
}

open class MountainBicycle
internal constructor(obj: CppBindObject) : Bicycle(obj) {
    companion object {

        protected fun constructHelper(numberOfSeats: Int): Long {
            val id = jConstructor(numberOfSeats)
            return id
        }

        @JvmStatic
        private external fun jConstructor(numberOfSeats: Int, vararg extraObjs: Any?): Long
        /**
         * An internal property to keep an information about the underlying C++ object type.
         * It is intended to be used by the generated code.
         */
        const val cppbindCxxTypeName: String = "cppbind::example::MountainBicycle"
    }


    constructor(numberOfSeats: Int): this(CppBindObject(constructHelper(numberOfSeats), true)) {
    }

    open override fun type(): String {
        val result = jType(cppbindObjId)

        return result
    }

    ///// External wrapper functions ////////////
    private external fun jType(id: Long): String
}

open class ElectricCityBicycle
internal constructor(obj: CppBindObject) : ElectricBicycle(obj) {
    companion object {

        protected fun constructHelper(numberOfSeats: Int): Long {
            val id = jConstructor(numberOfSeats)
            return id
        }

        @JvmStatic
        private external fun jConstructor(numberOfSeats: Int, vararg extraObjs: Any?): Long
        /**
         * An internal property to keep an information about the underlying C++ object type.
         * It is intended to be used by the generated code.
         */
        const val cppbindCxxTypeName: String = "cppbind::example::ElectricCityBicycle"
    }


    constructor(numberOfSeats: Int): this(CppBindObject(constructHelper(numberOfSeats), true)) {
    }

    open override fun type(): String {
        val result = jType(cppbindObjId)

        return result
    }

    ///// External wrapper functions ////////////
    private external fun jType(id: Long): String
}

private external fun jGettypebyid(id: Long): String

"""
  ______ .______   .______   .______    __  .__   __.  _______  
 /      ||   _  \  |   _  \  |   _  \  |  | |  \ |  | |       \ 
|  ,----'|  |_)  | |  |_)  | |  |_)  | |  | |   \|  | |  .--.  |
|  |     |   ___/  |   ___/  |   _  <  |  | |  . `  | |  |  |  |
|  `----.|  |      |  |      |  |_)  | |  | |  |\   | |  '--'  |
 \______|| _|      | _|      |______/  |__| |__| \__| |_______/ 

This file is generated by cppbind on 11/24/2022-07:17.
Please do not change it manually.
"""
from __future__ import annotations

from abc import abstractmethod
from typing import *

import examples.inheritance.vehicle as pybind_vehicle_pygen
from examples_lib.cppbind.cppbind_metaclass_pygen import *
from examples_lib.cppbind.cppbind_utils_pygen import *


class Vehicle(metaclass=CppBindMetaclass):
    @abstractmethod
    def __init__(self, *args, **kwargs):
        pass

    @property
    @bind
    def number_of_seats(self) -> int:

        pass

    @bind
    def type(self) -> str:

        pass

    @bind
    def __repr__(self) -> str:
        """
        CppBind generated __repr__ method returning underlying C++ object type and id.
        """
        pass
"""
  ______ .______   .______   .______    __  .__   __.  _______  
 /      ||   _  \  |   _  \  |   _  \  |  | |  \ |  | |       \ 
|  ,----'|  |_)  | |  |_)  | |  |_)  | |  | |   \|  | |  .--.  |
|  |     |   ___/  |   ___/  |   _  <  |  | |  . `  | |  |  |  |
|  `----.|  |      |  |      |  |_)  | |  | |  |\   | |  '--'  |
 \______|| _|      | _|      |______/  |__| |__| \__| |_______/ 

This file is generated by cppbind on 11/24/2022-07:17.
Please do not change it manually.
"""
from __future__ import annotations

from typing import *

import examples.inheritance.bicycle as pybind_bicycle_pygen
import examples_lib.inheritance.vehicle_pygen as vehicle_pygen
from examples_lib.cppbind.cppbind_metaclass_pygen import *
from examples_lib.cppbind.cppbind_utils_pygen import *


class Bicycle(vehicle_pygen.Vehicle, metaclass=CppBindMetaclass):

    @bind
    def __init__(self, number_of_seats: int):

        pass

    @bind
    def type(self) -> str:

        pass


class ElectricBicycle(Bicycle, metaclass=CppBindMetaclass):

    @bind
    def __init__(self, number_of_seats: int):

        pass

    @bind
    def type(self) -> str:

        pass


class MountainBicycle(Bicycle, metaclass=CppBindMetaclass):

    @bind
    def __init__(self, number_of_seats: int):

        pass

    @bind
    def type(self) -> str:

        pass


class ElectricCityBicycle(ElectricBicycle, metaclass=CppBindMetaclass):

    @bind
    def __init__(self, number_of_seats: int):

        pass

    @bind
    def type(self) -> str:

        pass

/**
 *   ______ .______   .______   .______    __  .__   __.  _______  
 *  /      ||   _  \  |   _  \  |   _  \  |  | |  \ |  | |       \ 
 * |  ,----'|  |_)  | |  |_)  | |  |_)  | |  | |   \|  | |  .--.  |
 * |  |     |   ___/  |   ___/  |   _  <  |  | |  . `  | |  |  |  |
 * |  `----.|  |      |  |      |  |_)  | |  | |  |\   | |  '--'  |
 *  \______|| _|      | _|      |______/  |__| |__| \__| |_______/ 
 * 
 * This file is generated by cppbind on 11/22/2022-06:42.
 * Please do not change it manually.
 */

import CWrapper
import Foundation

public class Vehicle {

  /// An internal property to keep a reference to the original C++ object.
  /// It is intended to be used by the generated code.
  public let cself: CppBindCObject

  /// An internal property to keep track whether Swift is responsible for deallocating the underlying C++ object or not.
  /// It is intended to be used by the generated code.
  public let owner: Bool
  private var refs: [Any]

  /// internal main initializer
  internal required init(_ _cself: CppBindCObject, _ _owner: Bool = false) {
    self.cself = _cself
    self.owner = _owner
    self.refs = []
  }

  deinit {
    release_CppbindExample_Vehicle(cself, owner)
  }

  /// An internal method to bind the lifetimes of the current and another object.
  /// It is intended to be used by the generated code.
  public func keepCppBindReference(_ object: Any) {
    self.refs.append(object)
  }

  /// internal dummy initializer to prevent automatic initializer inheritance
  internal init(_cself: CppBindCObject, _self: Vehicle) {
    fatalError("A dummy internal initializer should not be called.")
  }

  public var numberOfSeats: Int {
    var cppbindErr = CppBindCObject()
    let result = _prop_get_CppbindExample_Vehicle_numberOfSeats(cself, &cppbindErr)
    if cppbindErr.type != nil {
      let errorType = String(cString: cppbindErr.type!)
      switch errorType {
      case ("std::exception"):
        let excObj = StdException(cppbindErr, true)
        ExceptionHandler.handleUncaughtException(excObj.what())
      default:
        cppbindErr.type.deallocate()
        ExceptionHandler.handleUncaughtException("Uncaught Exception")
      }
    }
    let sctoswiftresult = Int(result)
    return sctoswiftresult
  }

  public func type() -> String {

    var cppbindErr = CppBindCObject()
    let result = _func_CppbindExample_Vehicle_type(cself, &cppbindErr)
    if cppbindErr.type != nil {
      let errorType = String(cString: cppbindErr.type!)
      switch errorType {
      case ("std::exception"):
        let excObj = StdException(cppbindErr, true)
        ExceptionHandler.handleUncaughtException(excObj.what())
      default:
        cppbindErr.type.deallocate()
        ExceptionHandler.handleUncaughtException("Uncaught Exception")
      }
    }
    let sctoswiftresult = String(cString: result)
    defer {
      result.deallocate()
    }
    return sctoswiftresult
  }

  /// An internal property to keep an information about the underlying C++ object type.
  /// It is intended to be used by the generated code.
  class var cppbindCxxTypeName : String { return "cppbind::example::Vehicle" }

  /// An internal method to create a Swift object from a C++ object.
  /// It is intended to be used by the generated code.
  class func cppbindConstructObject(_ cppbindObj: CppBindCObject, _ owner: Bool = false) -> Vehicle {
    let typeName = String(cString: cppbindObj.type)
    var obj : Vehicle
    switch(typeName) {
    case(ElectricCityBicycle.cppbindCxxTypeName):
      obj = ElectricCityBicycle(cppbindObj, owner)
    case(ElectricBicycle.cppbindCxxTypeName):
      obj = ElectricBicycle(cppbindObj, owner)
    case(MountainBicycle.cppbindCxxTypeName):
      obj = MountainBicycle(cppbindObj, owner)
    case(Bicycle.cppbindCxxTypeName):
      obj = Bicycle(cppbindObj, owner)
    default:
      obj = Vehicle(cppbindObj, owner)
    }
    return obj
  }
}
/**
 *   ______ .______   .______   .______    __  .__   __.  _______  
 *  /      ||   _  \  |   _  \  |   _  \  |  | |  \ |  | |       \ 
 * |  ,----'|  |_)  | |  |_)  | |  |_)  | |  | |   \|  | |  .--.  |
 * |  |     |   ___/  |   ___/  |   _  <  |  | |  . `  | |  |  |  |
 * |  `----.|  |      |  |      |  |_)  | |  | |  |\   | |  '--'  |
 *  \______|| _|      | _|      |______/  |__| |__| \__| |_______/ 
 * 
 * This file is generated by cppbind on 11/22/2022-06:42.
 * Please do not change it manually.
 */

import CWrapper
import Foundation

public class Bicycle: Vehicle {
  /// internal main initializer
  internal required init(_ _cself: CppBindCObject, _ _owner: Bool = false) {
    super.init(_cself, _owner)
  }

  /// internal dummy initializer to prevent automatic initializer inheritance
  internal init(_cself: CppBindCObject, _self: Bicycle) {
    fatalError("A dummy internal initializer should not be called.")
  }

  public convenience init(numberOfSeats: Int) {
    let swifttoscnumberOfSeats = CInt(numberOfSeats)
    var cppbindErr = CppBindCObject()
    self.init(create_CppbindExample_Bicycle(swifttoscnumberOfSeats, &cppbindErr), true)
    if cppbindErr.type != nil {
      let errorType = String(cString: cppbindErr.type!)
      switch errorType {
      case ("std::exception"):
        let excObj = StdException(cppbindErr, true)
        ExceptionHandler.handleUncaughtException(excObj.what())
      default:
        cppbindErr.type.deallocate()
        ExceptionHandler.handleUncaughtException("Uncaught Exception")
      }
    }
  }

  public override func type() -> String {

    var cppbindErr = CppBindCObject()
    let result = _func_CppbindExample_Bicycle_type(cself, &cppbindErr)
    if cppbindErr.type != nil {
      let errorType = String(cString: cppbindErr.type!)
      switch errorType {
      case ("std::exception"):
        let excObj = StdException(cppbindErr, true)
        ExceptionHandler.handleUncaughtException(excObj.what())
      default:
        cppbindErr.type.deallocate()
        ExceptionHandler.handleUncaughtException("Uncaught Exception")
      }
    }
    let sctoswiftresult = String(cString: result)
    defer {
      result.deallocate()
    }
    return sctoswiftresult
  }

  /// An internal property to keep an information about the underlying C++ object type.
  /// It is intended to be used by the generated code.
  override class var cppbindCxxTypeName : String { return "cppbind::example::Bicycle" }

  /// An internal method to create a Swift object from a C++ object.
  /// It is intended to be used by the generated code.
  override class func cppbindConstructObject(_ cppbindObj: CppBindCObject, _ owner: Bool = false) -> Bicycle {
    let typeName = String(cString: cppbindObj.type)
    var obj : Bicycle
    switch(typeName) {
    case(ElectricCityBicycle.cppbindCxxTypeName):
      obj = ElectricCityBicycle(cppbindObj, owner)
    case(ElectricBicycle.cppbindCxxTypeName):
      obj = ElectricBicycle(cppbindObj, owner)
    case(MountainBicycle.cppbindCxxTypeName):
      obj = MountainBicycle(cppbindObj, owner)
    default:
      obj = Bicycle(cppbindObj, owner)
    }
    return obj
  }
}

public class ElectricBicycle: Bicycle {
  /// internal main initializer
  internal required init(_ _cself: CppBindCObject, _ _owner: Bool = false) {
    super.init(_cself, _owner)
  }

  /// internal dummy initializer to prevent automatic initializer inheritance
  internal init(_cself: CppBindCObject, _self: ElectricBicycle) {
    fatalError("A dummy internal initializer should not be called.")
  }

  public convenience init(numberOfSeats: Int) {
    let swifttoscnumberOfSeats = CInt(numberOfSeats)
    var cppbindErr = CppBindCObject()
    self.init(create_CppbindExample_ElectricBicycle(swifttoscnumberOfSeats, &cppbindErr), true)
    if cppbindErr.type != nil {
      let errorType = String(cString: cppbindErr.type!)
      switch errorType {
      case ("std::exception"):
        let excObj = StdException(cppbindErr, true)
        ExceptionHandler.handleUncaughtException(excObj.what())
      default:
        cppbindErr.type.deallocate()
        ExceptionHandler.handleUncaughtException("Uncaught Exception")
      }
    }
  }

  public override func type() -> String {

    var cppbindErr = CppBindCObject()
    let result = _func_CppbindExample_ElectricBicycle_type(cself, &cppbindErr)
    if cppbindErr.type != nil {
      let errorType = String(cString: cppbindErr.type!)
      switch errorType {
      case ("std::exception"):
        let excObj = StdException(cppbindErr, true)
        ExceptionHandler.handleUncaughtException(excObj.what())
      default:
        cppbindErr.type.deallocate()
        ExceptionHandler.handleUncaughtException("Uncaught Exception")
      }
    }
    let sctoswiftresult = String(cString: result)
    defer {
      result.deallocate()
    }
    return sctoswiftresult
  }

  /// An internal property to keep an information about the underlying C++ object type.
  /// It is intended to be used by the generated code.
  override class var cppbindCxxTypeName : String { return "cppbind::example::ElectricBicycle" }

  /// An internal method to create a Swift object from a C++ object.
  /// It is intended to be used by the generated code.
  override class func cppbindConstructObject(_ cppbindObj: CppBindCObject, _ owner: Bool = false) -> ElectricBicycle {
    let typeName = String(cString: cppbindObj.type)
    var obj : ElectricBicycle
    switch(typeName) {
    case(ElectricCityBicycle.cppbindCxxTypeName):
      obj = ElectricCityBicycle(cppbindObj, owner)
    default:
      obj = ElectricBicycle(cppbindObj, owner)
    }
    return obj
  }
}

public class MountainBicycle: Bicycle {
  /// internal main initializer
  internal required init(_ _cself: CppBindCObject, _ _owner: Bool = false) {
    super.init(_cself, _owner)
  }

  public convenience init(numberOfSeats: Int) {
    let swifttoscnumberOfSeats = CInt(numberOfSeats)
    var cppbindErr = CppBindCObject()
    self.init(create_CppbindExample_MountainBicycle(swifttoscnumberOfSeats, &cppbindErr), true)
    if cppbindErr.type != nil {
      let errorType = String(cString: cppbindErr.type!)
      switch errorType {
      case ("std::exception"):
        let excObj = StdException(cppbindErr, true)
        ExceptionHandler.handleUncaughtException(excObj.what())
      default:
        cppbindErr.type.deallocate()
        ExceptionHandler.handleUncaughtException("Uncaught Exception")
      }
    }
  }

  public override func type() -> String {

    var cppbindErr = CppBindCObject()
    let result = _func_CppbindExample_MountainBicycle_type(cself, &cppbindErr)
    if cppbindErr.type != nil {
      let errorType = String(cString: cppbindErr.type!)
      switch errorType {
      case ("std::exception"):
        let excObj = StdException(cppbindErr, true)
        ExceptionHandler.handleUncaughtException(excObj.what())
      default:
        cppbindErr.type.deallocate()
        ExceptionHandler.handleUncaughtException("Uncaught Exception")
      }
    }
    let sctoswiftresult = String(cString: result)
    defer {
      result.deallocate()
    }
    return sctoswiftresult
  }

  /// An internal property to keep an information about the underlying C++ object type.
  /// It is intended to be used by the generated code.
  override class var cppbindCxxTypeName : String { return "cppbind::example::MountainBicycle" }
}

public class ElectricCityBicycle: ElectricBicycle {
  /// internal main initializer
  internal required init(_ _cself: CppBindCObject, _ _owner: Bool = false) {
    super.init(_cself, _owner)
  }

  public convenience init(numberOfSeats: Int) {
    let swifttoscnumberOfSeats = CInt(numberOfSeats)
    var cppbindErr = CppBindCObject()
    self.init(create_CppbindExample_ElectricCityBicycle(swifttoscnumberOfSeats, &cppbindErr), true)
    if cppbindErr.type != nil {
      let errorType = String(cString: cppbindErr.type!)
      switch errorType {
      case ("std::exception"):
        let excObj = StdException(cppbindErr, true)
        ExceptionHandler.handleUncaughtException(excObj.what())
      default:
        cppbindErr.type.deallocate()
        ExceptionHandler.handleUncaughtException("Uncaught Exception")
      }
    }
  }

  public override func type() -> String {

    var cppbindErr = CppBindCObject()
    let result = _func_CppbindExample_ElectricCityBicycle_type(cself, &cppbindErr)
    if cppbindErr.type != nil {
      let errorType = String(cString: cppbindErr.type!)
      switch errorType {
      case ("std::exception"):
        let excObj = StdException(cppbindErr, true)
        ExceptionHandler.handleUncaughtException(excObj.what())
      default:
        cppbindErr.type.deallocate()
        ExceptionHandler.handleUncaughtException("Uncaught Exception")
      }
    }
    let sctoswiftresult = String(cString: result)
    defer {
      result.deallocate()
    }
    return sctoswiftresult
  }

  /// An internal property to keep an information about the underlying C++ object type.
  /// It is intended to be used by the generated code.
  override class var cppbindCxxTypeName : String { return "cppbind::example::ElectricCityBicycle" }
}

Multiple Inheritance

Now let's assume we have a type inherited from two others: ` Square inherited from RectangleandRhombus. The last two, in their turn, are derived fromParallelogram:

/**
 * __API__
 * action: gen_interface
 * shared_ref: False
 * package: inheritance
 * descendants:
 *  - cppbind::example::Rectangle
 *  - cppbind::example::Rhombus
 *  - cppbind::example::Square
 */
class Parallelogram {
public:

    Parallelogram() {};

    /**
     * __API__
     * action: gen_getter
     * throws: no_throw
     */
    virtual double area() const = 0;

    /**
     * __API__
     * action: gen_method
     * throws: no_throw
     */
    virtual double perimeter() const = 0;

    virtual ~Parallelogram() = default;

    /**
     * This method is used in swift tests. As currently we do not allow hash and equals on interfaces
     * and the default hash/equals/toString which are based on C++ object id are not generated for swift.
     * __API__
     * swift.action: gen_method
     * throws: no_throw
     */
    bool isEqualTo(Parallelogram* p) const {
        return this == p;
    }
};
/**
 * __API__
 * action: gen_interface
 * shared_ref: False
 * package: inheritance
 */
class Rectangle : public virtual Parallelogram {
public:
    /**
     * __API__
     * action: gen_constructor
     * throws: no_throw
     */
    Rectangle(double length, double width) : Parallelogram() {
        _length = length;
        _width = width;
    };

    /**
     * __API__
     * action: gen_getter
     * throws: no_throw
     */
    double area() const override {
        return _length * _width;
    }

    double perimeter() const override {
        return 2 * (_length + _width);
    }

    /**
     * __API__
     * action: gen_getter
     * throws: no_throw
     */
    double length() const {
        return _length;
    }

    /**
     * __API__
     * action: gen_getter
     * throws: no_throw
     */
    double width() const {
        return _width;
    }

protected:
    double _length;
    double _width;

};
/**
 * __API__
 * action: gen_interface
 * shared_ref: False
 * package: inheritance
 * name: RhombusFigure
 */
class Rhombus : public virtual Parallelogram {
public:
    /**
     * __API__
     * action: gen_constructor
     * throws: no_throw
     */
    Rhombus(double diagonal1, double diagonal2) : Parallelogram() {
           _diagonal1 = diagonal1;
           _diagonal2 = diagonal2;
    };


    double area() const override {
        return (_diagonal1 * _diagonal2) / 2;
    }

    double perimeter() const override {
        return 2 * sqrt(_diagonal1 * _diagonal1 + _diagonal2 * _diagonal2) ;
    }


private:
    double _diagonal1;
    double _diagonal2;
};
/**
 * __API__
 * action: gen_class
 * shared_ref: False
 * package: inheritance
 */
class Square final : public Rhombus, public Rectangle {
public:
    /**
     * __API__
     * action: gen_constructor
     * throws: no_throw
     *
     */
    Square(double side) : Rhombus(side * sqrt(2), side * sqrt(2)), Rectangle(side, side) {};

    /**
     * __API__
     * action: gen_getter
     * throws: no_throw
     */
    double area() const override {
        return Rectangle::area();
    };

    /**
     * __API__
     * action: gen_method
     * throws: no_throw
     */
    double perimeter() const override {
        return Rectangle::perimeter();
    };

};

Again, we have used the same value for shared_ref for all four types.

We used action: gen_interface instead of action: gen_class for the parent types. Most modern languages do not support multiple inheritance, so we have to tell CppBind to generate interfaces instead.

Note

It's important to note that CppBind supports multiple inheritance for only polymorphic types (when the type has a virtual method/destructor or a polymorphic base).

Note

As Rectangle and Rhombus are interfaces, Parallelogram should also be an interface.

Usage examples:

val rectangle = RectangleImpl(4.0, 2.0)
assert(rectangle.area == 8.0)
assert(rectangle.length == 4.0)
assert(rectangle.perimeter() == 12.0)

val rhombus = RhombusFigureImpl(5.0, 6.0)
assert(rhombus.area == 15.0)

val square = Square(5.0)
assert(square.area == 25.0)
assert(square.length == 5.0)
assert(square.perimeter() == 20.0)
rectangle = Rectangle(length=4.0, width=2.0)
assert rectangle.area == 8.0
assert rectangle.length == 4.0
assert rectangle.perimeter() == 12.0

rhombus = RhombusFigure(diagonal1=5.0, diagonal2=6.0)
assert rhombus.area == 15.0

square = Square(side=5.0)
assert square.area == 25.0
assert square.length == 5.0
assert square.perimeter() == 20
let rectangle = RectangleImpl(length: 4.0, width: 2.0)
assert(rectangle.area == 8.0)
assert(rectangle.length == 4.0)
assert(rectangle.perimeter() == 12.0)

let rhombus = RhombusFigureImpl(diagonal1: 5.0, diagonal2: 6.0)
assert(rhombus.area == 15.0)

let square = Square(side: 5.0)
assert(square.area == 25.0)
assert(square.length == 5.0)
assert(square.perimeter() == 20.0)
Here are the generated bindings

/**
 *   ______ .______   .______   .______    __  .__   __.  _______  
 *  /      ||   _  \  |   _  \  |   _  \  |  | |  \ |  | |       \ 
 * |  ,----'|  |_)  | |  |_)  | |  |_)  | |  | |   \|  | |  .--.  |
 * |  |     |   ___/  |   ___/  |   _  <  |  | |  . `  | |  |  |  |
 * |  `----.|  |      |  |      |  |_)  | |  | |  |\   | |  '--'  |
 *  \______|| _|      | _|      |______/  |__| |__| \__| |_______/ 
 * 
 * This file is generated by cppbind on 10/18/2022-09:00.
 * Please do not change it manually.
 */

package com.examples.inheritance

import com.examples.cppbind.*
import com.examples.cppbind.exceptions.*


interface IParallelogram : AutoCloseable {
    /**
     * An internal getter to get the id of an object.
     * It is intended to be used by the generated code.
     */
    val cppbindObjId: Long
    /**
     * An internal method to bind the lifetimes of the current and another object.
     * It is intended to be used by the generated code.
     */
    fun keepCppBindReference(ref: Any)

    open val area: Double
        get() {
            val result = IParallelogramHelper.jArea(cppbindObjId)

            return result
        }

    open fun perimeter(): Double {
        val result = IParallelogramHelper.jPerimeter(cppbindObjId)

        return result
    }

    companion object {
        /**
         * An internal method to create a Kotlin object from a C++ object.
         * It is intended to be used by the generated code.
         */
        public fun cppbindConstructObject(id: Long, owner: Boolean = false): IParallelogram {
            val idType = jGettypebyid(id)
            val obj : IParallelogram
            when (idType) {
                RectangleImpl.cppbindCxxTypeName -> obj = RectangleImpl(CppBindObject(id, owner))
                RhombusFigureImpl.cppbindCxxTypeName -> obj = RhombusFigureImpl(CppBindObject(id, owner))
                Square.cppbindCxxTypeName -> obj = Square(CppBindObject(id, owner))
                else -> obj = ParallelogramImpl(CppBindObject(id, owner))
            }
            return obj
        }
    }
}


class IParallelogramHelper {
    companion object {
        @JvmStatic
        external fun jArea(id: Long): Double
        @JvmStatic
        external fun jPerimeter(id: Long): Double
    }
}


open class ParallelogramImpl
internal constructor(obj : CppBindObject) : IParallelogram {
    companion object {
        init {
            System.loadLibrary("wrapper_jni")
        }

        /**
         * An internal property to keep an information about the underlying C++ object type.
         * It is intended to be used by the generated code.
         */
        const val cppbindCxxTypeName: String = "cppbind::example::Parallelogram"
    }

    protected var cppbindObj = obj
    private var refs: MutableList<Any> = mutableListOf()

    override fun keepCppBindReference(ref: Any) {
        refs.add(ref)
    }

    override val cppbindObjId: Long
        get() {
            if (cppbindObj.id == 0L) {
                throw RuntimeException("Object is not allocated")
            }
            return cppbindObj.id
        }

    /**
     * An internal property returning underlying C++ object id.
     * It is intended to be used by the generated code.
     */
    internal val cxxId: Long by lazy {
        jGetcxxid(cppbindObj.id)
    }

    /**
     * An internal property returning underlying C++ type name.
     * It is intended to be used by the generated code.
     */
    internal val cxxTypeName: String by lazy {
        jGettypebyid(cppbindObj.id)
    }

    override fun close() {
        if (cppbindObj.owner && cppbindObj.id != 0L) {
            jFinalize(cppbindObj.id)
            cppbindObj.id = 0L
        }
    }

    /**
    * Finalize and deletes the object
    */
    protected fun finalize() {
        close()
    }

    /**
     * CppBind generated hashCode method returning the hash of underlying C++ object id.
     */
    override fun hashCode(): Int {
        return cxxId.hashCode()
    }

    /**
     * CppBind generated equals method comparing the underlying C++ object ids.
     */
    override fun equals(other: Any?): Boolean {
        other as ParallelogramImpl
        return cxxId == other.cxxId
    }

    /**
     * CppBind generated toString method returning underlying C++ object type and id.
     */
    override fun toString(): String {
        return "<0x$cxxId: $cxxTypeName>"
    }

    ///// External wrapper functions ////////////
    private external fun jFinalize(id: Long): Unit
    private external fun jGetcxxid(id: Long): Long
}

private external fun jGettypebyid(id: Long): String
/**
 *   ______ .______   .______   .______    __  .__   __.  _______  
 *  /      ||   _  \  |   _  \  |   _  \  |  | |  \ |  | |       \ 
 * |  ,----'|  |_)  | |  |_)  | |  |_)  | |  | |   \|  | |  .--.  |
 * |  |     |   ___/  |   ___/  |   _  <  |  | |  . `  | |  |  |  |
 * |  `----.|  |      |  |      |  |_)  | |  | |  |\   | |  '--'  |
 *  \______|| _|      | _|      |______/  |__| |__| \__| |_______/ 
 * 
 * This file is generated by cppbind on 10/18/2022-09:00.
 * Please do not change it manually.
 */

package com.examples.inheritance

import com.examples.cppbind.*
import com.examples.cppbind.exceptions.*


interface IRectangle : IParallelogram {

    open override val area: Double
        get() {
            val result = IRectangleHelper.jArea(cppbindObjId)

            return result
        }

    val length: Double
        get() {
            val result = IRectangleHelper.jLength(cppbindObjId)

            return result
        }

    val width: Double
        get() {
            val result = IRectangleHelper.jWidth(cppbindObjId)

            return result
        }


    companion object {
        /**
         * An internal method to create a Kotlin object from a C++ object.
         * It is intended to be used by the generated code.
         */
        public fun cppbindConstructObject(id: Long, owner: Boolean = false): IRectangle {
            val idType = jGettypebyid(id)
            val obj : IRectangle
            when (idType) {
                Square.cppbindCxxTypeName -> obj = Square(CppBindObject(id, owner))
                else -> obj = RectangleImpl(CppBindObject(id, owner))
            }
            return obj
        }
    }
}


class IRectangleHelper {
    companion object {
        @JvmStatic
        external fun jArea(id: Long): Double
        @JvmStatic
        external fun jLength(id: Long): Double
        @JvmStatic
        external fun jWidth(id: Long): Double
    }
}


open class RectangleImpl
internal constructor(obj : CppBindObject) : IRectangle {
    companion object {
        init {
            System.loadLibrary("wrapper_jni")
        }

        protected fun constructHelper(length: Double, width: Double): Long {
            val id = jConstructor(length, width)
            return id
        }

        @JvmStatic
        private external fun jConstructor(length: Double, width: Double, vararg extraObjs: Any?): Long
        /**
         * An internal property to keep an information about the underlying C++ object type.
         * It is intended to be used by the generated code.
         */
        const val cppbindCxxTypeName: String = "cppbind::example::Rectangle"
    }

    protected var cppbindObj = obj
    private var refs: MutableList<Any> = mutableListOf()

    override fun keepCppBindReference(ref: Any) {
        refs.add(ref)
    }

    override val cppbindObjId: Long
        get() {
            if (cppbindObj.id == 0L) {
                throw RuntimeException("Object is not allocated")
            }
            return cppbindObj.id
        }

    /**
     * An internal property returning underlying C++ object id.
     * It is intended to be used by the generated code.
     */
    internal val cxxId: Long by lazy {
        jGetcxxid(cppbindObj.id)
    }

    /**
     * An internal property returning underlying C++ type name.
     * It is intended to be used by the generated code.
     */
    internal val cxxTypeName: String by lazy {
        jGettypebyid(cppbindObj.id)
    }

    constructor(length: Double, width: Double): this(CppBindObject(constructHelper(length, width), true)) {
    }

    override fun close() {
        if (cppbindObj.owner && cppbindObj.id != 0L) {
            jFinalize(cppbindObj.id)
            cppbindObj.id = 0L
        }
    }

    /**
    * Finalize and deletes the object
    */
    protected fun finalize() {
        close()
    }

    /**
     * CppBind generated hashCode method returning the hash of underlying C++ object id.
     */
    override fun hashCode(): Int {
        return cxxId.hashCode()
    }

    /**
     * CppBind generated equals method comparing the underlying C++ object ids.
     */
    override fun equals(other: Any?): Boolean {
        other as RectangleImpl
        return cxxId == other.cxxId
    }

    /**
     * CppBind generated toString method returning underlying C++ object type and id.
     */
    override fun toString(): String {
        return "<0x$cxxId: $cxxTypeName>"
    }

    ///// External wrapper functions ////////////
    private external fun jFinalize(id: Long): Unit
    private external fun jGetcxxid(id: Long): Long
}

private external fun jGettypebyid(id: Long): String
/**
 *   ______ .______   .______   .______    __  .__   __.  _______  
 *  /      ||   _  \  |   _  \  |   _  \  |  | |  \ |  | |       \ 
 * |  ,----'|  |_)  | |  |_)  | |  |_)  | |  | |   \|  | |  .--.  |
 * |  |     |   ___/  |   ___/  |   _  <  |  | |  . `  | |  |  |  |
 * |  `----.|  |      |  |      |  |_)  | |  | |  |\   | |  '--'  |
 *  \______|| _|      | _|      |______/  |__| |__| \__| |_______/ 
 * 
 * This file is generated by cppbind on 10/18/2022-09:00.
 * Please do not change it manually.
 */

package com.examples.inheritance

import com.examples.cppbind.*
import com.examples.cppbind.exceptions.*


interface IRhombusFigure : IParallelogram {



    companion object {
        /**
         * An internal method to create a Kotlin object from a C++ object.
         * It is intended to be used by the generated code.
         */
        public fun cppbindConstructObject(id: Long, owner: Boolean = false): IRhombusFigure {
            val idType = jGettypebyid(id)
            val obj : IRhombusFigure
            when (idType) {
                Square.cppbindCxxTypeName -> obj = Square(CppBindObject(id, owner))
                else -> obj = RhombusFigureImpl(CppBindObject(id, owner))
            }
            return obj
        }
    }
}



open class RhombusFigureImpl
internal constructor(obj : CppBindObject) : IRhombusFigure {
    companion object {
        init {
            System.loadLibrary("wrapper_jni")
        }

        protected fun constructHelper(diagonal1: Double, diagonal2: Double): Long {
            val id = jConstructor(diagonal1, diagonal2)
            return id
        }

        @JvmStatic
        private external fun jConstructor(diagonal1: Double, diagonal2: Double, vararg extraObjs: Any?): Long
        /**
         * An internal property to keep an information about the underlying C++ object type.
         * It is intended to be used by the generated code.
         */
        const val cppbindCxxTypeName: String = "cppbind::example::Rhombus"
    }

    protected var cppbindObj = obj
    private var refs: MutableList<Any> = mutableListOf()

    override fun keepCppBindReference(ref: Any) {
        refs.add(ref)
    }

    override val cppbindObjId: Long
        get() {
            if (cppbindObj.id == 0L) {
                throw RuntimeException("Object is not allocated")
            }
            return cppbindObj.id
        }

    /**
     * An internal property returning underlying C++ object id.
     * It is intended to be used by the generated code.
     */
    internal val cxxId: Long by lazy {
        jGetcxxid(cppbindObj.id)
    }

    /**
     * An internal property returning underlying C++ type name.
     * It is intended to be used by the generated code.
     */
    internal val cxxTypeName: String by lazy {
        jGettypebyid(cppbindObj.id)
    }

    constructor(diagonal1: Double, diagonal2: Double): this(CppBindObject(constructHelper(diagonal1, diagonal2), true)) {
    }

    override fun close() {
        if (cppbindObj.owner && cppbindObj.id != 0L) {
            jFinalize(cppbindObj.id)
            cppbindObj.id = 0L
        }
    }

    /**
    * Finalize and deletes the object
    */
    protected fun finalize() {
        close()
    }

    /**
     * CppBind generated hashCode method returning the hash of underlying C++ object id.
     */
    override fun hashCode(): Int {
        return cxxId.hashCode()
    }

    /**
     * CppBind generated equals method comparing the underlying C++ object ids.
     */
    override fun equals(other: Any?): Boolean {
        other as RhombusFigureImpl
        return cxxId == other.cxxId
    }

    /**
     * CppBind generated toString method returning underlying C++ object type and id.
     */
    override fun toString(): String {
        return "<0x$cxxId: $cxxTypeName>"
    }

    ///// External wrapper functions ////////////
    private external fun jFinalize(id: Long): Unit
    private external fun jGetcxxid(id: Long): Long
}

private external fun jGettypebyid(id: Long): String
/**
 *   ______ .______   .______   .______    __  .__   __.  _______  
 *  /      ||   _  \  |   _  \  |   _  \  |  | |  \ |  | |       \ 
 * |  ,----'|  |_)  | |  |_)  | |  |_)  | |  | |   \|  | |  .--.  |
 * |  |     |   ___/  |   ___/  |   _  <  |  | |  . `  | |  |  |  |
 * |  `----.|  |      |  |      |  |_)  | |  | |  |\   | |  '--'  |
 *  \______|| _|      | _|      |______/  |__| |__| \__| |_______/ 
 * 
 * This file is generated by cppbind on 08/12/2022-06:48.
 * Please do not change it manually.
 */

package com.examples.inheritance

import com.examples.cppbind.*
import com.examples.cppbind.exceptions.*

class Square
internal constructor(obj: CppBindObject) : IRhombusFigure, IRectangle, AutoCloseable {
    companion object {
        init {
            System.loadLibrary("wrapper_jni")
        }

        protected fun constructHelper(side: Double): Long {
            val id = jConstructor(side)
            return id
        }

        @JvmStatic
        private external fun jConstructor(side: Double, vararg extraObjs: Any?): Long
        /**
         * An internal property to keep an information about the underlying C++ object type.
         * It is intended to be used by the generated code.
         */
        const val cppbindCxxTypeName: String = "cppbind::example::Square"
    }

    protected var cppbindObj = obj
    private var refs: MutableList<Any> = mutableListOf()

    /**
     * An internal method to bind the lifetimes of the current and another object.
     * It is intended to be used by the generated code.
     */
    override fun keepCppBindReference(ref: Any) {
        refs.add(ref)
    }
    /**
     * An internal getter to get the id of an object.
     * It is intended to be used by the generated code.
     */
    override val cppbindObjId: Long
        get() {
            if (cppbindObj.id == 0L) {
                throw RuntimeException("Object is not allocated")
            }
            return cppbindObj.id
        }

    /**
     * An internal property returning underlying C++ object id.
     * It is intended to be used by the generated code.
     */
    internal val cxxId: Long by lazy {
        jGetcxxid(cppbindObj.id)
    }

    /**
     * An internal property returning underlying C++ type name.
     * It is intended to be used by the generated code.
     */
    internal val cxxTypeName: String by lazy {
        jGettypebyid(cppbindObj.id)
    }

    constructor(side: Double): this(CppBindObject(constructHelper(side), true)) {
    }

    override val area: Double
        get() {
            val result = jArea(cppbindObjId)

            return result
        }

    override fun perimeter(): Double {
        val result = jPerimeter(cppbindObjId)

        return result
    }

    /**
     * CppBind generated hashCode method returning the hash of underlying C++ object id.
     */
    override fun hashCode(): Int {
        return cxxId.hashCode()
    }

    /**
     * CppBind generated equals method comparing the underlying C++ object ids.
     */
    override fun equals(other: Any?): Boolean {
        other as Square
        return cxxId == other.cxxId
    }

    /**
     * CppBind generated toString method returning underlying C++ object type and id.
     */
    override fun toString(): String {
        return "<0x$cxxId: $cxxTypeName>"
    }

    override fun close() {
        if (cppbindObj.owner && cppbindObj.id != 0L) {
            jFinalize(cppbindObj.id)
            cppbindObj.id = 0L
        }
    }

    /**
     * Finalize and deletes the object
     */
    protected fun finalize() {
        close()
    }

    ///// External wrapper functions ////////////
    private external fun jArea(id: Long): Double
    private external fun jPerimeter(id: Long): Double
    private external fun jFinalize(id: Long): Unit
    private external fun jGetcxxid(id: Long): Long
}

private external fun jGettypebyid(id: Long): String

"""
  ______ .______   .______   .______    __  .__   __.  _______  
 /      ||   _  \  |   _  \  |   _  \  |  | |  \ |  | |       \ 
|  ,----'|  |_)  | |  |_)  | |  |_)  | |  | |   \|  | |  .--.  |
|  |     |   ___/  |   ___/  |   _  <  |  | |  . `  | |  |  |  |
|  `----.|  |      |  |      |  |_)  | |  | |  |\   | |  '--'  |
 \______|| _|      | _|      |______/  |__| |__| \__| |_______/ 

This file is generated by cppbind on 11/24/2022-07:17.
Please do not change it manually.
"""
from __future__ import annotations

from abc import abstractmethod
from typing import *

import examples.inheritance.parallelogram as pybind_parallelogram_pygen
from examples_lib.cppbind.cppbind_metaclass_pygen import *
from examples_lib.cppbind.cppbind_utils_pygen import *


class Parallelogram(metaclass=CppBindMetaclass):
    @abstractmethod
    def __init__(self, *args, **kwargs):
        pass

    @property
    @bind
    def area(self) -> float:

        pass

    @bind
    def perimeter(self) -> float:

        pass

    @bind
    def __repr__(self) -> str:
        """
        CppBind generated __repr__ method returning underlying C++ object type and id.
        """
        pass
"""
  ______ .______   .______   .______    __  .__   __.  _______  
 /      ||   _  \  |   _  \  |   _  \  |  | |  \ |  | |       \ 
|  ,----'|  |_)  | |  |_)  | |  |_)  | |  | |   \|  | |  .--.  |
|  |     |   ___/  |   ___/  |   _  <  |  | |  . `  | |  |  |  |
|  `----.|  |      |  |      |  |_)  | |  | |  |\   | |  '--'  |
 \______|| _|      | _|      |______/  |__| |__| \__| |_______/ 

This file is generated by cppbind on 11/24/2022-07:17.
Please do not change it manually.
"""
from __future__ import annotations

from typing import *

import examples.inheritance.rectangle as pybind_rectangle_pygen
import examples_lib.inheritance.parallelogram_pygen as parallelogram_pygen
from examples_lib.cppbind.cppbind_metaclass_pygen import *
from examples_lib.cppbind.cppbind_utils_pygen import *


class Rectangle(parallelogram_pygen.Parallelogram, metaclass=CppBindMetaclass):

    @bind
    def __init__(self, length: float, width: float):

        pass

    @property
    @bind
    def area(self) -> float:

        pass

    @property
    @bind
    def length(self) -> float:

        pass

    @property
    @bind
    def width(self) -> float:

        pass
"""
  ______ .______   .______   .______    __  .__   __.  _______  
 /      ||   _  \  |   _  \  |   _  \  |  | |  \ |  | |       \ 
|  ,----'|  |_)  | |  |_)  | |  |_)  | |  | |   \|  | |  .--.  |
|  |     |   ___/  |   ___/  |   _  <  |  | |  . `  | |  |  |  |
|  `----.|  |      |  |      |  |_)  | |  | |  |\   | |  '--'  |
 \______|| _|      | _|      |______/  |__| |__| \__| |_______/ 

This file is generated by cppbind on 11/24/2022-07:17.
Please do not change it manually.
"""
from __future__ import annotations

from typing import *

import examples.inheritance.rhombus as pybind_rhombus_pygen
import examples_lib.inheritance.parallelogram_pygen as parallelogram_pygen
from examples_lib.cppbind.cppbind_metaclass_pygen import *
from examples_lib.cppbind.cppbind_utils_pygen import *


class RhombusFigure(parallelogram_pygen.Parallelogram, metaclass=CppBindMetaclass):

    @bind
    def __init__(self, diagonal1: float, diagonal2: float):

        pass
"""
  ______ .______   .______   .______    __  .__   __.  _______  
 /      ||   _  \  |   _  \  |   _  \  |  | |  \ |  | |       \ 
|  ,----'|  |_)  | |  |_)  | |  |_)  | |  | |   \|  | |  .--.  |
|  |     |   ___/  |   ___/  |   _  <  |  | |  . `  | |  |  |  |
|  `----.|  |      |  |      |  |_)  | |  | |  |\   | |  '--'  |
 \______|| _|      | _|      |______/  |__| |__| \__| |_______/ 

This file is generated by cppbind on 11/24/2022-07:17.
Please do not change it manually.
"""
from __future__ import annotations

from typing import *

import examples.inheritance.square as pybind_square_pygen
import examples_lib.inheritance.rectangle_pygen as rectangle_pygen
import examples_lib.inheritance.rhombus_pygen as rhombus_pygen
from examples_lib.cppbind.cppbind_metaclass_pygen import *
from examples_lib.cppbind.cppbind_utils_pygen import *


class Square(rhombus_pygen.RhombusFigure, rectangle_pygen.Rectangle, metaclass=CppBindMetaclass):

    @bind
    def __init__(self, side: float):

        pass

    @property
    @bind
    def area(self) -> float:

        pass

    @bind
    def perimeter(self) -> float:

        pass

/**
 *   ______ .______   .______   .______    __  .__   __.  _______  
 *  /      ||   _  \  |   _  \  |   _  \  |  | |  \ |  | |       \ 
 * |  ,----'|  |_)  | |  |_)  | |  |_)  | |  | |   \|  | |  .--.  |
 * |  |     |   ___/  |   ___/  |   _  <  |  | |  . `  | |  |  |  |
 * |  `----.|  |      |  |      |  |_)  | |  | |  |\   | |  '--'  |
 *  \______|| _|      | _|      |______/  |__| |__| \__| |_______/ 
 * 
 * This file is generated by cppbind on 10/18/2022-08:51.
 * Please do not change it manually.
 */

import CWrapper
import Foundation

public protocol Parallelogram {
  /// An internal property to keep a reference to the original C++ object.
  /// It is intended to be used by the generated code.
  var cself: CppBindCObject { get }

  /// An internal method to bind the lifetimes of the current and another object.
  /// It is intended to be used by the generated code.
  func keepCppBindReference(_ object: Any)
  var area: Double { get }
  func perimeter() -> Double
  /// This method is used in swift tests. As currently we do not allow hash and equals on interfaces
  /// and the default hash/equals/toString which are based on C++ object id are not generated for swift.
  func isEqualTo(p: Parallelogram) -> Bool
}

extension Parallelogram {
  public var area: Double {
    var cppbindErr = CppBindCObject()
    let result = _prop_get_CppbindExample_Parallelogram_area(cself, &cppbindErr)
    if cppbindErr.type != nil {
      let errorType = String(cString: cppbindErr.type!)
      switch errorType {
      case ("std::exception"):
        let excObj = StdException(cppbindErr, true)
        ExceptionHandler.handleUncaughtException(excObj.what())
      default:
        cppbindErr.type.deallocate()
        ExceptionHandler.handleUncaughtException("Uncaught Exception")
      }
    }
    return result
  }

  public func perimeter() -> Double {

    var cppbindErr = CppBindCObject()
    let result = _func_CppbindExample_Parallelogram_perimeter(cself, &cppbindErr)
    if cppbindErr.type != nil {
      let errorType = String(cString: cppbindErr.type!)
      switch errorType {
      case ("std::exception"):
        let excObj = StdException(cppbindErr, true)
        ExceptionHandler.handleUncaughtException(excObj.what())
      default:
        cppbindErr.type.deallocate()
        ExceptionHandler.handleUncaughtException("Uncaught Exception")
      }
    }
    return result
  }

  /// This method is used in swift tests. As currently we do not allow hash and equals on interfaces
  /// and the default hash/equals/toString which are based on C++ object id are not generated for swift.
  public func isEqualTo(p: Parallelogram) -> Bool {

    let swifttoscp = p.cself
    var cppbindErr = CppBindCObject()
    let result = _func_CppbindExample_Parallelogram_isEqualTo(cself, swifttoscp, &cppbindErr)
    if cppbindErr.type != nil {
      let errorType = String(cString: cppbindErr.type!)
      switch errorType {
      case ("std::exception"):
        let excObj = StdException(cppbindErr, true)
        ExceptionHandler.handleUncaughtException(excObj.what())
      default:
        cppbindErr.type.deallocate()
        ExceptionHandler.handleUncaughtException("Uncaught Exception")
      }
    }
    return result
  }

}

public class ParallelogramImpl: Parallelogram {
  public let cself: CppBindCObject
  public let owner: Bool
  private var refs: [Any]

  /// internal main initializer
  internal required init(_ _cself: CppBindCObject, _ _owner: Bool = false) {
    self.cself = _cself
    self.owner = _owner
    self.refs = []
  }

  deinit {
    release_CppbindExample_ParallelogramImpl(cself, owner)
  }

  public func keepCppBindReference(_ object: Any) {
    self.refs.append(object)
  }

  /// An internal property to keep an information about the underlying C++ object type.
  /// It is intended to be used by the generated code.
  class var cppbindCxxTypeName : String { return "cppbind::example::Parallelogram" }

  /// An internal method to create a Swift object from a C++ object.
  /// It is intended to be used by the generated code.
  class func cppbindConstructObject(_ cppbindObj: CppBindCObject, _ owner: Bool = false) -> Parallelogram {
    let typeName = String(cString: cppbindObj.type)
    var obj : Parallelogram
    switch(typeName) {
    case(RectangleImpl.cppbindCxxTypeName):
      obj = RectangleImpl(cppbindObj, owner)
    case(RhombusFigureImpl.cppbindCxxTypeName):
      obj = RhombusFigureImpl(cppbindObj, owner)
    case(Square.cppbindCxxTypeName):
      obj = Square(cppbindObj, owner)
    default:
      obj = ParallelogramImpl(cppbindObj, owner)
    }
    return obj
  }
}
/**
 *   ______ .______   .______   .______    __  .__   __.  _______  
 *  /      ||   _  \  |   _  \  |   _  \  |  | |  \ |  | |       \ 
 * |  ,----'|  |_)  | |  |_)  | |  |_)  | |  | |   \|  | |  .--.  |
 * |  |     |   ___/  |   ___/  |   _  <  |  | |  . `  | |  |  |  |
 * |  `----.|  |      |  |      |  |_)  | |  | |  |\   | |  '--'  |
 *  \______|| _|      | _|      |______/  |__| |__| \__| |_______/ 
 * 
 * This file is generated by cppbind on 10/18/2022-08:51.
 * Please do not change it manually.
 */

import CWrapper
import Foundation

public protocol Rectangle: Parallelogram {
  var area: Double { get }
  var length: Double { get }
  var width: Double { get }
}

extension Rectangle {
  public var area: Double {
    var cppbindErr = CppBindCObject()
    let result = _prop_get_CppbindExample_Rectangle_area(cself, &cppbindErr)
    if cppbindErr.type != nil {
      let errorType = String(cString: cppbindErr.type!)
      switch errorType {
      case ("std::exception"):
        let excObj = StdException(cppbindErr, true)
        ExceptionHandler.handleUncaughtException(excObj.what())
      default:
        cppbindErr.type.deallocate()
        ExceptionHandler.handleUncaughtException("Uncaught Exception")
      }
    }
    return result
  }

  public var length: Double {
    var cppbindErr = CppBindCObject()
    let result = _prop_get_CppbindExample_Rectangle_length(cself, &cppbindErr)
    if cppbindErr.type != nil {
      let errorType = String(cString: cppbindErr.type!)
      switch errorType {
      case ("std::exception"):
        let excObj = StdException(cppbindErr, true)
        ExceptionHandler.handleUncaughtException(excObj.what())
      default:
        cppbindErr.type.deallocate()
        ExceptionHandler.handleUncaughtException("Uncaught Exception")
      }
    }
    return result
  }

  public var width: Double {
    var cppbindErr = CppBindCObject()
    let result = _prop_get_CppbindExample_Rectangle_width(cself, &cppbindErr)
    if cppbindErr.type != nil {
      let errorType = String(cString: cppbindErr.type!)
      switch errorType {
      case ("std::exception"):
        let excObj = StdException(cppbindErr, true)
        ExceptionHandler.handleUncaughtException(excObj.what())
      default:
        cppbindErr.type.deallocate()
        ExceptionHandler.handleUncaughtException("Uncaught Exception")
      }
    }
    return result
  }

}

public class RectangleImpl: Rectangle {
  public let cself: CppBindCObject
  public let owner: Bool
  private var refs: [Any]

  /// internal main initializer
  internal required init(_ _cself: CppBindCObject, _ _owner: Bool = false) {
    self.cself = _cself
    self.owner = _owner
    self.refs = []
  }

  deinit {
    release_CppbindExample_RectangleImpl(cself, owner)
  }

  public func keepCppBindReference(_ object: Any) {
    self.refs.append(object)
  }

  public convenience init(length: Double, width: Double) {
    var cppbindErr = CppBindCObject()
    self.init(create_CppbindExample_Rectangle(length, width, &cppbindErr), true)
    if cppbindErr.type != nil {
      let errorType = String(cString: cppbindErr.type!)
      switch errorType {
      case ("std::exception"):
        let excObj = StdException(cppbindErr, true)
        ExceptionHandler.handleUncaughtException(excObj.what())
      default:
        cppbindErr.type.deallocate()
        ExceptionHandler.handleUncaughtException("Uncaught Exception")
      }
    }
  }

  /// An internal property to keep an information about the underlying C++ object type.
  /// It is intended to be used by the generated code.
  class var cppbindCxxTypeName : String { return "cppbind::example::Rectangle" }

  /// An internal method to create a Swift object from a C++ object.
  /// It is intended to be used by the generated code.
  class func cppbindConstructObject(_ cppbindObj: CppBindCObject, _ owner: Bool = false) -> Rectangle {
    let typeName = String(cString: cppbindObj.type)
    var obj : Rectangle
    switch(typeName) {
    case(Square.cppbindCxxTypeName):
      obj = Square(cppbindObj, owner)
    default:
      obj = RectangleImpl(cppbindObj, owner)
    }
    return obj
  }
}
/**
 *   ______ .______   .______   .______    __  .__   __.  _______  
 *  /      ||   _  \  |   _  \  |   _  \  |  | |  \ |  | |       \ 
 * |  ,----'|  |_)  | |  |_)  | |  |_)  | |  | |   \|  | |  .--.  |
 * |  |     |   ___/  |   ___/  |   _  <  |  | |  . `  | |  |  |  |
 * |  `----.|  |      |  |      |  |_)  | |  | |  |\   | |  '--'  |
 *  \______|| _|      | _|      |______/  |__| |__| \__| |_______/ 
 * 
 * This file is generated by cppbind on 10/18/2022-08:51.
 * Please do not change it manually.
 */

import CWrapper
import Foundation

public protocol RhombusFigure: Parallelogram {
}

extension RhombusFigure {
}

public class RhombusFigureImpl: RhombusFigure {
  public let cself: CppBindCObject
  public let owner: Bool
  private var refs: [Any]

  /// internal main initializer
  internal required init(_ _cself: CppBindCObject, _ _owner: Bool = false) {
    self.cself = _cself
    self.owner = _owner
    self.refs = []
  }

  deinit {
    release_CppbindExample_RhombusFigureImpl(cself, owner)
  }

  public func keepCppBindReference(_ object: Any) {
    self.refs.append(object)
  }

  public convenience init(diagonal1: Double, diagonal2: Double) {
    var cppbindErr = CppBindCObject()
    self.init(create_CppbindExample_RhombusFigure(diagonal1, diagonal2, &cppbindErr), true)
    if cppbindErr.type != nil {
      let errorType = String(cString: cppbindErr.type!)
      switch errorType {
      case ("std::exception"):
        let excObj = StdException(cppbindErr, true)
        ExceptionHandler.handleUncaughtException(excObj.what())
      default:
        cppbindErr.type.deallocate()
        ExceptionHandler.handleUncaughtException("Uncaught Exception")
      }
    }
  }

  /// An internal property to keep an information about the underlying C++ object type.
  /// It is intended to be used by the generated code.
  class var cppbindCxxTypeName : String { return "cppbind::example::Rhombus" }

  /// An internal method to create a Swift object from a C++ object.
  /// It is intended to be used by the generated code.
  class func cppbindConstructObject(_ cppbindObj: CppBindCObject, _ owner: Bool = false) -> RhombusFigure {
    let typeName = String(cString: cppbindObj.type)
    var obj : RhombusFigure
    switch(typeName) {
    case(Square.cppbindCxxTypeName):
      obj = Square(cppbindObj, owner)
    default:
      obj = RhombusFigureImpl(cppbindObj, owner)
    }
    return obj
  }
}
/**
 *   ______ .______   .______   .______    __  .__   __.  _______  
 *  /      ||   _  \  |   _  \  |   _  \  |  | |  \ |  | |       \ 
 * |  ,----'|  |_)  | |  |_)  | |  |_)  | |  | |   \|  | |  .--.  |
 * |  |     |   ___/  |   ___/  |   _  <  |  | |  . `  | |  |  |  |
 * |  `----.|  |      |  |      |  |_)  | |  | |  |\   | |  '--'  |
 *  \______|| _|      | _|      |______/  |__| |__| \__| |_______/ 
 * 
 * This file is generated by cppbind on 08/14/2022-10:58.
 * Please do not change it manually.
 */

import CWrapper
import Foundation

public class Square: RhombusFigure, Rectangle {

  /// An internal property to keep a reference to the original C++ object.
  /// It is intended to be used by the generated code.
  public let cself: CppBindCObject

  /// An internal property to keep track whether Swift is responsible for deallocating the underlying C++ object or not.
  /// It is intended to be used by the generated code.
  public let owner: Bool
  private var refs: [Any]

  /// internal main initializer
  internal required init(_ _cself: CppBindCObject, _ _owner: Bool = false) {
    self.cself = _cself
    self.owner = _owner
    self.refs = []
  }

  deinit {
    release_CppbindExample_Square(cself, owner)
  }

  /// An internal method to bind the lifetimes of the current and another object.
  /// It is intended to be used by the generated code.
  public func keepCppBindReference(_ object: Any) {
    self.refs.append(object)
  }

  public convenience init(side: Double) {
    var cppbindErr = CppBindCObject()
    self.init(create_CppbindExample_Square(side, &cppbindErr), true)
    if cppbindErr.type != nil {
      let errorType = String(cString: cppbindErr.type!)
      switch errorType {
      case ("std::exception"):
        let excObj = StdException(cppbindErr, true)
        ExceptionHandler.handleUncaughtException(excObj.what())
      default:
        cppbindErr.type.deallocate()
        ExceptionHandler.handleUncaughtException("Uncaught Exception")
      }
    }
  }

  public var area: Double {
    var cppbindErr = CppBindCObject()
    let result = _prop_get_CppbindExample_Square_area(cself, &cppbindErr)
    if cppbindErr.type != nil {
      let errorType = String(cString: cppbindErr.type!)
      switch errorType {
      case ("std::exception"):
        let excObj = StdException(cppbindErr, true)
        ExceptionHandler.handleUncaughtException(excObj.what())
      default:
        cppbindErr.type.deallocate()
        ExceptionHandler.handleUncaughtException("Uncaught Exception")
      }
    }
    return result
  }

  public func perimeter() -> Double {

    var cppbindErr = CppBindCObject()
    let result = _func_CppbindExample_Square_perimeter(cself, &cppbindErr)
    if cppbindErr.type != nil {
      let errorType = String(cString: cppbindErr.type!)
      switch errorType {
      case ("std::exception"):
        let excObj = StdException(cppbindErr, true)
        ExceptionHandler.handleUncaughtException(excObj.what())
      default:
        cppbindErr.type.deallocate()
        ExceptionHandler.handleUncaughtException("Uncaught Exception")
      }
    }
    return result
  }

  /// An internal property to keep an information about the underlying C++ object type.
  /// It is intended to be used by the generated code.
  class var cppbindCxxTypeName : String { return "cppbind::example::Square" }
}


Last update: December 1, 2022