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
 * descendants:
 *  - cppbind::example::Bicycle
 */
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;
};

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.

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

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 05/12/2022-10:29.
 * Please do not change it manually.
 */

package com.examples.inheritance

import com.examples.cppbind.alias.*
import com.examples.cppbind.exceptionUtils.*
import com.examples.cppbind.exception_helpers.*

open class Vehicle
internal constructor(obj: CppBindObject) : AutoCloseable {
    companion object {
        init {
            System.loadLibrary("wrapper_jni")
        }
        
        const val cppbindCxxTypeName: String = "cppbind::example::Vehicle"

        public fun cppbindConstructObject(id: Long, owner: Boolean = false): Vehicle {
            val idType = jGettypebyid(id)
            when (idType) {
                Bicycle.cppbindCxxTypeName -> return Bicycle(CppBindObject(id, owner))
                else -> return Vehicle(CppBindObject(id, owner))
            }
        }
    }
    
    protected var cppbindObj = obj
    private var refs: MutableList<Any> = mutableListOf()

    fun keepCppBindReference(ref: Any) {
        refs.add(ref)
    }
    
    open val id: Long
        get() {
            if (cppbindObj.id == 0L) {
                throw RuntimeException("Object is not allocated")
            }
            return cppbindObj.id
        }
    
    val numberOfSeats: Int
        get() {
            val result = jNumberofseats(id)
            
            return result
        }
    
    open fun type(): String {
        val result = jType(id)
        
        return result
    }

    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 jGettypebyid(id: Long): String
/**
 *   ______ .______   .______   .______    __  .__   __.  _______  
 *  /      ||   _  \  |   _  \  |   _  \  |  | |  \ |  | |       \ 
 * |  ,----'|  |_)  | |  |_)  | |  |_)  | |  | |   \|  | |  .--.  |
 * |  |     |   ___/  |   ___/  |   _  <  |  | |  . `  | |  |  |  |
 * |  `----.|  |      |  |      |  |_)  | |  | |  |\   | |  '--'  |
 *  \______|| _|      | _|      |______/  |__| |__| \__| |_______/ 
 * 
 * This file is generated by cppbind on 05/12/2022-10:29.
 * Please do not change it manually.
 */

package com.examples.inheritance

import com.examples.cppbind.alias.*
import com.examples.cppbind.exceptionUtils.*
import com.examples.cppbind.exception_helpers.*

open class Bicycle
internal constructor(obj: CppBindObject) : Vehicle(obj) {
    companion object {
        
        protected fun construct_helper(numberOfSeats: Int): Long {
            val id = jConstructor(numberOfSeats)
            return id
        }

        @JvmStatic
        private external fun jConstructor(numberOfSeats: Int): Long
        const val cppbindCxxTypeName: String = "cppbind::example::Bicycle"
    }
    
    
    constructor(numberOfSeats: Int): this(CppBindObject(construct_helper(numberOfSeats), true)) {
    }
    
    open override fun type(): String {
        val result = jType(id)
        
        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 05/12/2022-10:33.
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.bind_utils_pygen import *
from examples_lib.cppbind.metaclass_pygen import *


class Vehicle(metaclass=CppBindMetaclass):
    """
    Documentation generated from: `cxx/inheritance/vehicle.hpp#L16
    <https://github.com/PicsArt/cppbind/tree/master/examples/primitives/cxx/inheritance/vehicle.hpp#L16>`_
    """
    @abstractmethod
    def __init__(self, *args, **kwargs):
        pass
    
    @property
    @bind
    def number_of_seats(self) -> int:
        """
        Documentation generated from: `cxx/inheritance/vehicle.hpp#L26
        <https://github.com/PicsArt/cppbind/tree/master/examples/primitives/cxx/inheritance/vehicle.hpp#L26>`_
        """
        pass
    
    @bind
    def type(self) -> str:
        """
        Documentation generated from: `cxx/inheritance/vehicle.hpp#L35
        <https://github.com/PicsArt/cppbind/tree/master/examples/primitives/cxx/inheritance/vehicle.hpp#L35>`_
        """
        pass
"""
  ______ .______   .______   .______    __  .__   __.  _______  
 /      ||   _  \  |   _  \  |   _  \  |  | |  \ |  | |       \ 
|  ,----'|  |_)  | |  |_)  | |  |_)  | |  | |   \|  | |  .--.  |
|  |     |   ___/  |   ___/  |   _  <  |  | |  . `  | |  |  |  |
|  `----.|  |      |  |      |  |_)  | |  | |  |\   | |  '--'  |
 \______|| _|      | _|      |______/  |__| |__| \__| |_______/ 

This file is generated by cppbind on 05/12/2022-10:33.
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.bind_utils_pygen import *
from examples_lib.cppbind.metaclass_pygen import *


class Bicycle(vehicle_pygen.Vehicle, metaclass=CppBindMetaclass):
    """
    Documentation generated from: `cxx/inheritance/bicycle.hpp#L16
    <https://github.com/PicsArt/cppbind/tree/master/examples/primitives/cxx/inheritance/bicycle.hpp#L16>`_
    """
    
    @bind
    def __init__(self, number_of_seats: int):
        """
        Documentation generated from: `cxx/inheritance/bicycle.hpp#L23
        <https://github.com/PicsArt/cppbind/tree/master/examples/primitives/cxx/inheritance/bicycle.hpp#L23>`_
        """
        pass
    
    @bind
    def type(self) -> str:
        """
        Documentation generated from: `cxx/inheritance/bicycle.hpp#L32
        <https://github.com/PicsArt/cppbind/tree/master/examples/primitives/cxx/inheritance/bicycle.hpp#L32>`_
        """
        pass
/**
 *   ______ .______   .______   .______    __  .__   __.  _______  
 *  /      ||   _  \  |   _  \  |   _  \  |  | |  \ |  | |       \ 
 * |  ,----'|  |_)  | |  |_)  | |  |_)  | |  | |   \|  | |  .--.  |
 * |  |     |   ___/  |   ___/  |   _  <  |  | |  . `  | |  |  |  |
 * |  `----.|  |      |  |      |  |_)  | |  | |  |\   | |  '--'  |
 *  \______|| _|      | _|      |______/  |__| |__| \__| |_______/ 
 * 
 * This file is generated by cppbind on 05/12/2022-10:26.
 * Please do not change it manually.
 */

import CWrapper
import Foundation

public class Vehicle {

  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_Vehicle(cself, owner)
  }

  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
  }

  class var cppbindCxxTypeName : String { return "cppbind::example::Vehicle" }

  class func cppbindConstructObject(_ cppbindObj: CppBindCObject, _ owner: Bool = false) -> Vehicle {
    let typeName = String(cString: cppbindObj.type)
    switch(typeName) {
    case(Bicycle.cppbindCxxTypeName):
      return Bicycle(cppbindObj, owner)
    default:
      return Vehicle(cppbindObj, owner)
    }
  }
}
/**
 *   ______ .______   .______   .______    __  .__   __.  _______  
 *  /      ||   _  \  |   _  \  |   _  \  |  | |  \ |  | |       \ 
 * |  ,----'|  |_)  | |  |_)  | |  |_)  | |  | |   \|  | |  .--.  |
 * |  |     |   ___/  |   ___/  |   _  <  |  | |  . `  | |  |  |  |
 * |  `----.|  |      |  |      |  |_)  | |  | |  |\   | |  '--'  |
 *  \______|| _|      | _|      |______/  |__| |__| \__| |_______/ 
 * 
 * This file is generated by cppbind on 05/12/2022-10:26.
 * 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)
  }

  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
  }

  override class var cppbindCxxTypeName : String { return "cppbind::example::Bicycle" }
}

Multiple Inheritance

Now let’s assume we have a type inherited from two others: Square` inherited from ``Rectangle and Rhombus. The last two, in their turn, are derived from Parallelogram:

/**
 * __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;

    /**
     * __API__
     * action: gen_method
     * throws: no_throw
     */
    bool equals(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.

Note

Here we used action: gen_interface instead of action: gen_class. Most modern languages do not support multiple inheritance, so we have to tell CppBind to generate interfaces with implementations instead.

Note

It’s important to note that CppBind supports multiple inheritance for 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 05/12/2022-10:29.
 * Please do not change it manually.
 */

package com.examples.inheritance

import com.examples.cppbind.alias.*
import com.examples.cppbind.exceptionUtils.*
import com.examples.cppbind.exception_helpers.*


interface IParallelogram : AutoCloseable {
    val id: Long
    fun keepCppBindReference(ref: Any)
    
    open val area: Double
        get() {
            val result = IParallelogramHelper.jArea(id)
            
            return result
        }
    
    open fun perimeter(): Double {
        val result = IParallelogramHelper.jPerimeter(id)
        
        return result
    }

    fun equals(p: IParallelogram): Boolean {
        val kotlintojdkp = p.id
        val result = IParallelogramHelper.jEquals(id, kotlintojdkp)
        
        return result
    }

    companion object {
        public fun cppbindConstructObject(id: Long, owner: Boolean = false): IParallelogram {
            val idType = jGettypebyid(id)
            when (idType) {
                RectangleImpl.cppbindCxxTypeName -> return RectangleImpl(CppBindObject(id, owner))
                RhombusFigureImpl.cppbindCxxTypeName -> return RhombusFigureImpl(CppBindObject(id, owner))
                Square.cppbindCxxTypeName -> return Square(CppBindObject(id, owner))
                else -> return ParallelogramImpl(CppBindObject(id, owner))
            }
        }
    }
}


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


open class ParallelogramImpl
internal constructor(obj : CppBindObject) : IParallelogram {
    companion object {
        init {
            System.loadLibrary("wrapper_jni")
        }
        
        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 id: Long
        get() {
            if (cppbindObj.id == 0L) {
                throw RuntimeException("Object is not allocated")
            }
            return 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()
    }
    
    ///// External wrapper functions ////////////
    private external fun jFinalize(id: Long): Unit
}

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

package com.examples.inheritance

import com.examples.cppbind.alias.*
import com.examples.cppbind.exceptionUtils.*
import com.examples.cppbind.exception_helpers.*


interface IRectangle : IParallelogram {
    
    open override val area: Double
        get() {
            val result = IRectangleHelper.jArea(id)
            
            return result
        }

    val length: Double
        get() {
            val result = IRectangleHelper.jLength(id)
            
            return result
        }

    val width: Double
        get() {
            val result = IRectangleHelper.jWidth(id)
            
            return result
        }
    

    companion object {
        public fun cppbindConstructObject(id: Long, owner: Boolean = false): IRectangle {
            val idType = jGettypebyid(id)
            when (idType) {
                Square.cppbindCxxTypeName -> return Square(CppBindObject(id, owner))
                else -> return RectangleImpl(CppBindObject(id, owner))
            }
        }
    }
}


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 construct_helper(length: Double, width: Double): Long {
            val id = jConstructor(length, width)
            return id
        }

        @JvmStatic
        private external fun jConstructor(length: Double, width: Double): Long
        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 id: Long
        get() {
            if (cppbindObj.id == 0L) {
                throw RuntimeException("Object is not allocated")
            }
            return cppbindObj.id
        }
    
    constructor(length: Double, width: Double): this(CppBindObject(construct_helper(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()
    }
    
    ///// External wrapper functions ////////////
    private external fun jFinalize(id: Long): Unit
}

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

package com.examples.inheritance

import com.examples.cppbind.alias.*
import com.examples.cppbind.exceptionUtils.*
import com.examples.cppbind.exception_helpers.*


interface IRhombusFigure : IParallelogram {
    
    

    companion object {
        public fun cppbindConstructObject(id: Long, owner: Boolean = false): IRhombusFigure {
            val idType = jGettypebyid(id)
            when (idType) {
                Square.cppbindCxxTypeName -> return Square(CppBindObject(id, owner))
                else -> return RhombusFigureImpl(CppBindObject(id, owner))
            }
        }
    }
}



open class RhombusFigureImpl
internal constructor(obj : CppBindObject) : IRhombusFigure {
    companion object {
        init {
            System.loadLibrary("wrapper_jni")
        }
        
        protected fun construct_helper(diagonal1: Double, diagonal2: Double): Long {
            val id = jConstructor(diagonal1, diagonal2)
            return id
        }

        @JvmStatic
        private external fun jConstructor(diagonal1: Double, diagonal2: Double): Long
        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 id: Long
        get() {
            if (cppbindObj.id == 0L) {
                throw RuntimeException("Object is not allocated")
            }
            return cppbindObj.id
        }
    
    constructor(diagonal1: Double, diagonal2: Double): this(CppBindObject(construct_helper(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()
    }
    
    ///// External wrapper functions ////////////
    private external fun jFinalize(id: Long): Unit
}

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

package com.examples.inheritance

import com.examples.cppbind.alias.*
import com.examples.cppbind.exceptionUtils.*
import com.examples.cppbind.exception_helpers.*

class Square
internal constructor(obj: CppBindObject) : IRhombusFigure, IRectangle, AutoCloseable {
    companion object {
        init {
            System.loadLibrary("wrapper_jni")
        }
        
        protected fun construct_helper(side: Double): Long {
            val id = jConstructor(side)
            return id
        }

        @JvmStatic
        private external fun jConstructor(side: Double): Long
        const val cppbindCxxTypeName: String = "cppbind::example::Square"
    }
    
    protected var cppbindObj = obj
    private var refs: MutableList<Any> = mutableListOf()

    override fun keepCppBindReference(ref: Any) {
        refs.add(ref)
    }
    override val id: Long
        get() {
            if (cppbindObj.id == 0L) {
                throw RuntimeException("Object is not allocated")
            }
            return cppbindObj.id
        }
    
    constructor(side: Double): this(CppBindObject(construct_helper(side), true)) {
    }
    
    override val area: Double
        get() {
            val result = jArea(id)
            
            return result
        }
    
    override fun perimeter(): Double {
        val result = jPerimeter(id)
        
        return result
    }

    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 jGettypebyid(id: Long): String
"""
  ______ .______   .______   .______    __  .__   __.  _______  
 /      ||   _  \  |   _  \  |   _  \  |  | |  \ |  | |       \ 
|  ,----'|  |_)  | |  |_)  | |  |_)  | |  | |   \|  | |  .--.  |
|  |     |   ___/  |   ___/  |   _  <  |  | |  . `  | |  |  |  |
|  `----.|  |      |  |      |  |_)  | |  | |  |\   | |  '--'  |
 \______|| _|      | _|      |______/  |__| |__| \__| |_______/ 

This file is generated by cppbind on 05/12/2022-10:33.
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.bind_utils_pygen import *
from examples_lib.cppbind.metaclass_pygen import *


class Parallelogram(metaclass=CppBindMetaclass):
    """
    Documentation generated from: `cxx/inheritance/parallelogram.hpp#L16
    <https://github.com/PicsArt/cppbind/tree/master/examples/primitives/cxx/inheritance/parallelogram.hpp#L16>`_
    """
    @abstractmethod
    def __init__(self, *args, **kwargs):
        pass
    
    @property
    @bind
    def area(self) -> float:
        """
        Documentation generated from: `cxx/inheritance/parallelogram.hpp#L26
        <https://github.com/PicsArt/cppbind/tree/master/examples/primitives/cxx/inheritance/parallelogram.hpp#L26>`_
        """
        pass
    
    @bind
    def perimeter(self) -> float:
        """
        Documentation generated from: `cxx/inheritance/parallelogram.hpp#L33
        <https://github.com/PicsArt/cppbind/tree/master/examples/primitives/cxx/inheritance/parallelogram.hpp#L33>`_
        """
        pass

    @bind
    def equals(self, p: Parallelogram) -> bool:
        """
        Documentation generated from: `cxx/inheritance/parallelogram.hpp#L42
        <https://github.com/PicsArt/cppbind/tree/master/examples/primitives/cxx/inheritance/parallelogram.hpp#L42>`_
        """
        pass
"""
  ______ .______   .______   .______    __  .__   __.  _______  
 /      ||   _  \  |   _  \  |   _  \  |  | |  \ |  | |       \ 
|  ,----'|  |_)  | |  |_)  | |  |_)  | |  | |   \|  | |  .--.  |
|  |     |   ___/  |   ___/  |   _  <  |  | |  . `  | |  |  |  |
|  `----.|  |      |  |      |  |_)  | |  | |  |\   | |  '--'  |
 \______|| _|      | _|      |______/  |__| |__| \__| |_______/ 

This file is generated by cppbind on 05/12/2022-10:33.
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.bind_utils_pygen import *
from examples_lib.cppbind.metaclass_pygen import *


class Rectangle(parallelogram_pygen.Parallelogram, metaclass=CppBindMetaclass):
    """
    Documentation generated from: `cxx/inheritance/rectangle.hpp#L13
    <https://github.com/PicsArt/cppbind/tree/master/examples/primitives/cxx/inheritance/rectangle.hpp#L13>`_
    """
    
    @bind
    def __init__(self, length: float, width: float):
        """
        Documentation generated from: `cxx/inheritance/rectangle.hpp#L20
        <https://github.com/PicsArt/cppbind/tree/master/examples/primitives/cxx/inheritance/rectangle.hpp#L20>`_
        """
        pass
    
    @property
    @bind
    def area(self) -> float:
        """
        Documentation generated from: `cxx/inheritance/rectangle.hpp#L30
        <https://github.com/PicsArt/cppbind/tree/master/examples/primitives/cxx/inheritance/rectangle.hpp#L30>`_
        """
        pass

    @property
    @bind
    def length(self) -> float:
        """
        Documentation generated from: `cxx/inheritance/rectangle.hpp#L43
        <https://github.com/PicsArt/cppbind/tree/master/examples/primitives/cxx/inheritance/rectangle.hpp#L43>`_
        """
        pass

    @property
    @bind
    def width(self) -> float:
        """
        Documentation generated from: `cxx/inheritance/rectangle.hpp#L52
        <https://github.com/PicsArt/cppbind/tree/master/examples/primitives/cxx/inheritance/rectangle.hpp#L52>`_
        """
        pass
"""
  ______ .______   .______   .______    __  .__   __.  _______  
 /      ||   _  \  |   _  \  |   _  \  |  | |  \ |  | |       \ 
|  ,----'|  |_)  | |  |_)  | |  |_)  | |  | |   \|  | |  .--.  |
|  |     |   ___/  |   ___/  |   _  <  |  | |  . `  | |  |  |  |
|  `----.|  |      |  |      |  |_)  | |  | |  |\   | |  '--'  |
 \______|| _|      | _|      |______/  |__| |__| \__| |_______/ 

This file is generated by cppbind on 05/12/2022-10:33.
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.bind_utils_pygen import *
from examples_lib.cppbind.metaclass_pygen import *


class RhombusFigure(parallelogram_pygen.Parallelogram, metaclass=CppBindMetaclass):
    """
    Documentation generated from: `cxx/inheritance/rhombus.hpp#L16
    <https://github.com/PicsArt/cppbind/tree/master/examples/primitives/cxx/inheritance/rhombus.hpp#L16>`_
    """
    
    @bind
    def __init__(self, diagonal1: float, diagonal2: float):
        """
        Documentation generated from: `cxx/inheritance/rhombus.hpp#L23
        <https://github.com/PicsArt/cppbind/tree/master/examples/primitives/cxx/inheritance/rhombus.hpp#L23>`_
        """
        pass
"""
  ______ .______   .______   .______    __  .__   __.  _______  
 /      ||   _  \  |   _  \  |   _  \  |  | |  \ |  | |       \ 
|  ,----'|  |_)  | |  |_)  | |  |_)  | |  | |   \|  | |  .--.  |
|  |     |   ___/  |   ___/  |   _  <  |  | |  . `  | |  |  |  |
|  `----.|  |      |  |      |  |_)  | |  | |  |\   | |  '--'  |
 \______|| _|      | _|      |______/  |__| |__| \__| |_______/ 

This file is generated by cppbind on 05/12/2022-10:33.
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.bind_utils_pygen import *
from examples_lib.cppbind.metaclass_pygen import *


class Square(rhombus_pygen.RhombusFigure, rectangle_pygen.Rectangle, metaclass=CppBindMetaclass):
    """
    Documentation generated from: `cxx/inheritance/square.hpp#L16
    <https://github.com/PicsArt/cppbind/tree/master/examples/primitives/cxx/inheritance/square.hpp#L16>`_
    """
    
    @bind
    def __init__(self, side: float):
        """
        Documentation generated from: `cxx/inheritance/square.hpp#L24
        <https://github.com/PicsArt/cppbind/tree/master/examples/primitives/cxx/inheritance/square.hpp#L24>`_
        """
        pass
    
    @property
    @bind
    def area(self) -> float:
        """
        Documentation generated from: `cxx/inheritance/square.hpp#L31
        <https://github.com/PicsArt/cppbind/tree/master/examples/primitives/cxx/inheritance/square.hpp#L31>`_
        """
        pass
    
    @bind
    def perimeter(self) -> float:
        """
        Documentation generated from: `cxx/inheritance/square.hpp#L40
        <https://github.com/PicsArt/cppbind/tree/master/examples/primitives/cxx/inheritance/square.hpp#L40>`_
        """
        pass
/**
 *   ______ .______   .______   .______    __  .__   __.  _______  
 *  /      ||   _  \  |   _  \  |   _  \  |  | |  \ |  | |       \ 
 * |  ,----'|  |_)  | |  |_)  | |  |_)  | |  | |   \|  | |  .--.  |
 * |  |     |   ___/  |   ___/  |   _  <  |  | |  . `  | |  |  |  |
 * |  `----.|  |      |  |      |  |_)  | |  | |  |\   | |  '--'  |
 *  \______|| _|      | _|      |______/  |__| |__| \__| |_______/ 
 * 
 * This file is generated by cppbind on 05/12/2022-10:26.
 * Please do not change it manually.
 */

import CWrapper
import Foundation

public protocol Parallelogram {
  var cself: CppBindCObject { get }

  func keepCppBindReference(_ object: Any)
  var area: Double { get }
  func perimeter() -> Double
  func equals(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
  }

  public func equals(p: Parallelogram) -> Bool {

    let swifttoscp = p.cself
    var cppbindErr = CppBindCObject()
    let result = _func_CppbindExample_Parallelogram_equals(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)
  }

  class var cppbindCxxTypeName : String { return "cppbind::example::Parallelogram" }

  class func cppbindConstructObject(_ cppbindObj: CppBindCObject, _ owner: Bool = false) -> Parallelogram {
    let typeName = String(cString: cppbindObj.type)
    switch(typeName) {
    case(RectangleImpl.cppbindCxxTypeName):
      return RectangleImpl(cppbindObj, owner)
    case(RhombusFigureImpl.cppbindCxxTypeName):
      return RhombusFigureImpl(cppbindObj, owner)
    case(Square.cppbindCxxTypeName):
      return Square(cppbindObj, owner)
    default:
      return ParallelogramImpl(cppbindObj, owner)
    }
  }
}
/**
 *   ______ .______   .______   .______    __  .__   __.  _______  
 *  /      ||   _  \  |   _  \  |   _  \  |  | |  \ |  | |       \ 
 * |  ,----'|  |_)  | |  |_)  | |  |_)  | |  | |   \|  | |  .--.  |
 * |  |     |   ___/  |   ___/  |   _  <  |  | |  . `  | |  |  |  |
 * |  `----.|  |      |  |      |  |_)  | |  | |  |\   | |  '--'  |
 *  \______|| _|      | _|      |______/  |__| |__| \__| |_______/ 
 * 
 * This file is generated by cppbind on 05/12/2022-10:26.
 * 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")
      }
    }
  }

  class var cppbindCxxTypeName : String { return "cppbind::example::Rectangle" }

  class func cppbindConstructObject(_ cppbindObj: CppBindCObject, _ owner: Bool = false) -> Rectangle {
    let typeName = String(cString: cppbindObj.type)
    switch(typeName) {
    case(Square.cppbindCxxTypeName):
      return Square(cppbindObj, owner)
    default:
      return RectangleImpl(cppbindObj, owner)
    }
  }
}
/**
 *   ______ .______   .______   .______    __  .__   __.  _______  
 *  /      ||   _  \  |   _  \  |   _  \  |  | |  \ |  | |       \ 
 * |  ,----'|  |_)  | |  |_)  | |  |_)  | |  | |   \|  | |  .--.  |
 * |  |     |   ___/  |   ___/  |   _  <  |  | |  . `  | |  |  |  |
 * |  `----.|  |      |  |      |  |_)  | |  | |  |\   | |  '--'  |
 *  \______|| _|      | _|      |______/  |__| |__| \__| |_______/ 
 * 
 * This file is generated by cppbind on 05/12/2022-10:26.
 * 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")
      }
    }
  }

  class var cppbindCxxTypeName : String { return "cppbind::example::Rhombus" }

  class func cppbindConstructObject(_ cppbindObj: CppBindCObject, _ owner: Bool = false) -> RhombusFigure {
    let typeName = String(cString: cppbindObj.type)
    switch(typeName) {
    case(Square.cppbindCxxTypeName):
      return Square(cppbindObj, owner)
    default:
      return RhombusFigureImpl(cppbindObj, owner)
    }
  }
}
/**
 *   ______ .______   .______   .______    __  .__   __.  _______  
 *  /      ||   _  \  |   _  \  |   _  \  |  | |  \ |  | |       \ 
 * |  ,----'|  |_)  | |  |_)  | |  |_)  | |  | |   \|  | |  .--.  |
 * |  |     |   ___/  |   ___/  |   _  <  |  | |  . `  | |  |  |  |
 * |  `----.|  |      |  |      |  |_)  | |  | |  |\   | |  '--'  |
 *  \______|| _|      | _|      |______/  |__| |__| \__| |_______/ 
 * 
 * This file is generated by cppbind on 05/12/2022-10:26.
 * Please do not change it manually.
 */

import CWrapper
import Foundation

public class Square: RhombusFigure, 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_Square(cself, owner)
  }

  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
  }

  class var cppbindCxxTypeName : String { return "cppbind::example::Square" }
}