From cbf4a9e583d69b8bfcc78669d341c830f58863de Mon Sep 17 00:00:00 2001 From: Simon Marchetto Date: Thu, 3 Apr 2014 17:24:08 +0200 Subject: [PATCH] scilab: document C++ operators --- Doc/Manual/Scilab.html | 54 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/Doc/Manual/Scilab.html b/Doc/Manual/Scilab.html index 24cfbfd31..977f8c3b5 100644 --- a/Doc/Manual/Scilab.html +++ b/Doc/Manual/Scilab.html @@ -33,6 +33,7 @@
  • C++ classes
  • C++ inheritance
  • C++ templates +
  • C++ operators
  • C++ STL
  • Type mappings @@ -1026,7 +1027,58 @@ Templates are supported. See the SWIG general documentation on how templates are An example of templates can be found in Examples/scilab/templates.

    -

    37.3.11 C++ STL

    +

    37.3.11 C++ operators

    + +

    +C++ operators are partially supported. +Operator overloading exists in Scilab, but a C++ operator is not (in this version) wrapped by SWIG with a Scilab operator, but with a function. +It is not automatic, you have to rename each operator to wrap (with the instruction %rename) to give the name of wrapping function. +

    + +

    +Let's see it on an example of class with two operators + and double(): +

    + +
    +%module example
    +
    +%rename(plus) operator +;
    +%rename(toDouble) operator double();
    +
    +%inline %{
    +
    +class Complex {
    +public:
    +  Complex(double re, double im) : real(re), imag(im) {};
    +
    +  Complex operator+(const Complex& other) {
    +    double result_real = real + other.real;
    +    double result_imaginary = imag + other.imag;
    +    return Complex(result_real, result_imaginary);
    +  }
    +  operator double() { return real; }
    +private:
    +  double real;
    +  double imag;
    +};
    +
    +%}
    +
    + +

    +

    +-->c1 = new_Complex(3, 7);
    +
    +-->c2 = Complex_plus(c, new_Complex(1,1));
    +
    +-->Complex_toDouble(c2)
    + ans  =
    +
    +    4.
    +
    +

    + +

    37.3.12 C++ STL

    The Standard Template Library (STL) is partially supported. See STL for more details.