refactor subtraction operation
[scilab.git] / scilab / modules / ast / includes / operations / types_opposite.hxx
1 /*
2 *  Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 *  Copyright (C) 2014 - Scilab Enterprises - Antoine ELIAS
4 *
5 *  This file must be used under the terms of the CeCILL.
6 *  This source file is licensed as described in the file COPYING, which
7 *  you should have received as part of this distribution.  The terms
8 *  are also available at
9 *  http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
10 *
11 */
12
13 #ifndef __TYPES_OPPOSITE_HXX__
14 #define __TYPES_OPPOSITE_HXX__
15
16 #include "internal.hxx"
17 #include "sparse.hxx"
18 #include "polynom.hxx"
19 #include "bool.hxx"
20 #include "double.hxx"
21
22 void fillOppositeFunction();
23
24 //define arrays on operation functions
25 typedef types::InternalType*(*opposite_function)(types::InternalType*);
26
27 #define DECLARE_OPPOSITE_PROTO(x) template<class T, class O> inline types::InternalType* x(T *_pL)
28 DECLARE_OPPOSITE_PROTO(opposite_E);
29 DECLARE_OPPOSITE_PROTO(opposite_I);
30 DECLARE_OPPOSITE_PROTO(opposite_IC);
31 DECLARE_OPPOSITE_PROTO(opposite_S);
32 DECLARE_OPPOSITE_PROTO(opposite_SC);
33 DECLARE_OPPOSITE_PROTO(opposite_M);
34 DECLARE_OPPOSITE_PROTO(opposite_MC);
35
36 #undef DECLARE_OPPOSITE_PROTO
37
38 //do not inline it
39 template<> types::InternalType* opposite_M<types::Bool, types::Double>(types::Bool* _pL);
40
41 template<> inline types::InternalType* opposite_M<types::Sparse, types::Sparse>(types::Sparse* _pL);
42 template<> inline types::InternalType* opposite_MC<types::Sparse, types::Sparse>(types::Sparse* _pL);
43
44 template<> inline types::InternalType* opposite_S<types::Polynom, types::Polynom>(types::Polynom* _pL);
45 template<> inline types::InternalType* opposite_SC<types::Polynom, types::Polynom>(types::Polynom* _pL);
46 template<> inline types::InternalType* opposite_M<types::Polynom, types::Polynom>(types::Polynom* _pL);
47 template<> inline types::InternalType* opposite_MC<types::Polynom, types::Polynom>(types::Polynom* _pL);
48
49
50 template<typename T, typename O> inline static void opposite(T l, O* o)
51 {
52     *o = (O)(-l);
53 }
54
55 template<typename T, typename O> inline static void opposite(T l, T lc, O* o, O* oc)
56 {
57     *o = (O)(-l);
58     *oc = (O)(-lc);
59 }
60
61 template<typename T, typename O> inline static void opposite(T* l, long long size, O* o)
62 {
63     for (int i = 0; i < size ; ++i)
64     {
65         o[i] = (O)(-l[i]);
66     }
67 }
68
69 template<typename T, typename O> inline static void opposite(T* l, T* lc, long long size, O* o, O* oc)
70 {
71     for (int i = 0; i < size ; ++i)
72     {
73         o[i] = (O)(-l[i]);
74         oc[i] = (O)(-lc[i]);
75     }
76 }
77
78
79 #endif /* __TYPES_OPPOSITE_HXX__ */