Modelib: Fichier source de py_Expr.cxx

Page principale | Liste des namespaces | Hiérarchie des classes | Liste alphabétique | Liste des classes | Liste des fichiers | Membres de namespace | Membres de classe | Membres de fichier

# py_Expr.cxx

Aller à la documentation de ce fichier.

    00001 /*
    00002     Copyright (c) 2005, Quentin Lequy and Romain Gaucher
    00003     All rights reserved.
    00004
    00005     Redistribution and use in source and binary forms, with or
    00006     without modification, are permitted provided that the following
    00007     conditions are met:
    00008
    00009         * Redistributions of source code must retain the above copyright
    00010           notice, this list of conditions and the following disclaimer.
    00011
    00012         * Redistributions in binary form must reproduce the above copyright
    00013           notice, this list of conditions and the following disclaimer in the
    00014           documentation and/or other materials provided with the distribution.
    00015
    00016         * Neither the name of Quentin Lequy or Romain Gaucher nor the names
    00017           of its contributors may be used to endorse or promote products
    00018           derived from this software without specific prior written permission.
    00019
    00020     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    00021     AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    00022     IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    00023     ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
    00024     LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
    00025     DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
    00026     SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
    00027     AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    00028     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
    00029     SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    00030 */
    00031
    00032 #include <boost/python.hpp>
    00033 #include <boost/python/class.hpp>
    00034 #include <boost/python/module.hpp>
    00035 #include <boost/python/def.hpp>
    00036 #include <boost/python/implicit.hpp>
    00037
    00038 namespace Modelib {
    00039
    00040 void export_Expr()
    00041 {
    00042     using namespace boost::python;
    00043     class_<Expr>("Expr",init<>())      // constructeurs
    00044       .def(init<Expr>())
    00045       .def(init<const NumVar&>())
    00046       .def(init<float>())
    00047       .def(init<int>())
    00048       .def(init<double>())
    00049       .def(init<unsigned>())
    00050       .def(init<const Num&>())
    00051       .def(init<const Num&, const NumVar&>())
    00052       .def(init<const Num&, const NumVar&, const LagrangianParam&>())
    00053       .def("ASS", &Expr::ASS_prim,return_internal_reference<>())          // méthodes
    00054       .def("ASS", &Expr::ASS_lag,return_internal_reference<>())
    00055       .def("Size", &Expr::Size)
    00056       .def("IsNum", &Expr::IsNum)
    00057       .def("IsVar", &Expr::IsVar)
    00058       .def("GetConstant", &Expr::GetConstant)
    00059       //.def("__eq__", &Expr::operator=,return_internal_reference<>())                // opérateurs surchargés
    00060       //.def(self = self)
    00061       .def("__iadd__", &Expr::__iadd__,return_internal_reference<>())
    00062       .def("__isub__", &Expr::__isub__,return_internal_reference<>())
    00063       .def("__imul__", &Expr::__imul__,return_internal_reference<>())
    00064       .def("__str__", &Expr::ostr_1,return_internal_reference<>())
    00065       .def("__str__", &Expr::ostr_2,return_internal_reference<>())
    00066      ;
    00067
    00068   // définitions des fonctions construisant une expression
    00069   // depuis des combinaisons d'entités
    00070   def("Sum", &Sum);
    00071   def("__mul__", &omul_1);
    00072   def("__mul__", &omul_2);
    00073   def("__mul__", &omul_3);
    00074   def("__mul__", &omul_4);
    00075   def("__mul__", &omul_5);
    00076   def("__mul__", &omul_6);
    00077   def("__add__", &oplus);
    00078   def("__sub__", &ominus);
    00079   def("Out", &Oute);
    00080
    00081   // Conversion implicites pour permettre des Expr += unsigned etc.
    00082   // Python les verra comme des Expr += Expr
    00083   implicitly_convertible<int,Expr>();
    00084   implicitly_convertible<NumVar,Expr>();
    00085   implicitly_convertible<IntVar,Expr>();
    00086   implicitly_convertible<FloatVar,Expr>();
    00087   implicitly_convertible<float,Expr>();
    00088   implicitly_convertible<unsigned,Expr>();
    00089   implicitly_convertible<double,Expr>();
    00090   implicitly_convertible<Num,Expr>();
    00091   implicitly_convertible<Int,Expr>();
    00092   implicitly_convertible<Float,Expr>();
    00093
    00094 }
    00095
    00096 }