📄 operator.hpp
字号:
// -*- Mode : c++ -*-//// SUMMARY : // USAGE : // ORG : // AUTHOR : Frederic Hecht// E-MAIL : hecht@ann.jussieu.fr///* This file is part of Freefem++ Freefem++ is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. Freefem++ is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with Freefem++; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */#if defined(__GNUC__) && __GNUC__+0 >= 3inline double pow(double x,long l) { return pow(x,(double)l);}#endiftemplate<class R,class A=R> struct Op1_neg: public unary_function<A,R> { static R f(const A & a) { return - (R)a;} }; template<class R,class A=R> struct Op1_plus: public unary_function<A,R> { static R f(const A & a) { return + (R)a;} }; template<class A> struct Op1_not: public unary_function<A,bool> { static bool f(const A & a) { return ! (bool)a;} }; template<class R,class A=R,class B=A> struct Op2_add: public binary_function<A,B,R> { static R f(const A & a,const B & b) { return ((R)a + (R)b);} }; template<class R,class A=R,class B=A> struct Op2_sub: public binary_function<A,B,R> { static R f(const A & a,const B & b) { return ((R)a - (R)b);} }; template<class R,class A=R,class B=A> struct Op2_mul: public binary_function<A,B,R> { static R f(const A & a,const B & b) { // cout << a << " * " << b <<" => " << ((R)a * (R)b) << endl; return ((R)a * (R)b);} }; template<class R,class A=R,class B=A> struct Op2_div: public binary_function<A,B,R> { static R f(const A & a,const B & b) { if (b == B()) {cerr << a << "/" << b << " : " << typeid(A).name() << " " << typeid(B).name() << " " << typeid(R).name() << endl;ExecError(" Div by 0");} return ((R)a / (R)b);} }; template<class R,class A=R,class B=A> struct Op2_mod: public binary_function<A,B,R> { static R f(const A & a,const B & b) { return ((R)a % (R)b);} }; template<class A,class B=A> struct Op2_lt: public binary_function<A,B,bool> { static bool f(const A & a,const B & b) { // cout << a << " < " << b << " = " << ( a<b) << endl; return a < b;} }; template<class A,class B=A> struct Op2_le: public binary_function<A,B,bool> { static bool f(const A & a,const B & b) { return a <= b;} }; template<class A,class B=A> struct Op2_gt: public binary_function<A,B,bool> { static bool f(const A & a,const B & b) { return a > b;} }; template<class A,class B=A> struct Op2_ge: public binary_function<A,B,bool> { static bool f(const A & a,const B & b) { return a >= b;} }; template<class A,class B=A> struct Op2_eq: public binary_function<A,B,bool> { static bool f(const A & a,const B & b) { //cout << a << " == " << b << " => " <<( a == b) << endl; return a == b;} }; template<class A,class B=A> struct Op2_ne: public binary_function<A,B,bool> { static bool f(const A & a,const B & b) { return a != b;} }; struct Op2_and: public binary_function<bool,bool,bool> { static bool f(const bool & a,const bool & b) { return a && b;} }; struct Op2_or: public binary_function<bool,bool,bool> { static bool f(const bool & a,const bool & b) { return a || b;} }; template<class R,class A,class B> struct Op2_padd: public binary_function<A,B,R*> { static R * f(Stack s,const A & a,const B & b) { R* r= Add2StackOfPtr2Free(s,new R (*a + *b)); // delete a,delete b; return r;} }; template<class A,class B=A> struct Op2_plt: public binary_function<A,B,bool> { static bool f(const A & a,const B & b) { bool r= *a < *b; //delete a,delete b; return r;} }; template<class A,class B=A> struct Op2_ple: public binary_function<A,B,bool> { static bool f(const A & a,const B & b) { bool r= *a <= *b; // delete a,delete b; return r;} }; template<class A,class B=A> struct Op2_pgt: public binary_function<A,B,bool> { static bool f(const A & a,const B & b) { bool r= *a > *b; // delete a,delete b; return r;} }; template<class A,class B=A> struct Op2_pge: public binary_function<A,B,bool> { static bool f(const A & a,const B & b) { bool r= *a >= *b; // delete a,delete b; return r;} }; template<class A,class B=A> struct Op2_peq: public binary_function<A,B,bool> { static bool f(const A & a,const B & b) { bool r= *a == *b; // delete a,delete b; return r;} }; template<class A,class B=A> struct Op2_pne: public binary_function<A,B,bool> { static bool f(const A & a,const B & b) { bool r=*a != *b; // delete a,delete b; return r;} }; template<class R,class A=R,class B=A>struct Op2_pow: public binary_function<A,B,R> { static R f(const A & a,const B & b) { return R(pow(a,b));}}; template<class A>struct Op_Read : public binary_function<istream*,A*,istream*> { static istream * f(istream * const & f,A * const & a) { *f >> *a; return f; }};template<class A>struct Op_ReadP : public binary_function<istream*,A**,istream*> { static istream * f(istream * const & f,A ** const & a) { assert(a); if( ! *a) *a= new A ; *f >> **a; return f; }};template<class A>struct Op_ReadKN : public binary_function<istream*,KN<A>*,istream*> { static istream * f(istream * const & f,KN<A>* const & a) { if( !f || !*f) ExecError("Fatal Error: file not open in read array (Op_ReadKN)"); int n;char c; *f >> n; if(!f->good()) ExecError("Fatal Error: file not good in read array (Op_ReadKN)"); if(n !=a->N()) { cerr << " length on the array " << a->N() << " != " << n << " length in file " << endl; ExecError("Fatal Error: incompatible length in read array (Op_ReadKN)"); assert(n==a->N()); } while (f->get(c) && (c!='\n' && c!='\r' ) ) ((void) 0); // eat until control (new line for (int i=0;i<n;i++) *f >> (*a)[i] ; return f; }};template<class A>struct Print: public binary_function<ostream*,A,ostream*> { static ostream* f(ostream* const & a,const A & b) { *a << b; return a;}};// ---------------------------------------------template<class A>struct set_eq: public binary_function<A*,A,A*> { static A* f(A* const & a,const A & b) { *a = b; return a;}};template<class A,class B>struct set_eqq: public binary_function<A,B,A> { static A f(const A & a,const B & b) {A aa(a); aa = b; return aa;}};template<class A,class B>struct set_eqq_add: public binary_function<A,B,A> { static A f(const A & a,const B & b) {A aa(a); aa += b; return aa;}};template<class A>struct set_eq_add: public binary_function<A*,A,A*> { static A* f(A* const & a,const A & b) { *a += b; return a;}};template<class A>struct set_eq_sub: public binary_function<A*,A,A*> { static A* f(A* const & a,const A & b) { *a -= b; return a;}};template<class A>struct set_eq_mul: public binary_function<A*,A,A*> { static A* f(A* const & a,const A & b) { *a *= b; return a;}};template<class A>struct set_eq_div: public binary_function<A*,A,A*> { static A* f(A* const & a,const A & b) { *a /= b; return a;}};template<class A>struct set_peq: public binary_function<A**,A*,A**> { static A** f(A** const & a, A * const & b) { if(*a != b ) { //cerr << " set_peq " << *a << endl; delete *a; //cerr << " set_peq " << *a << " " << " = " << b << " " << endl; *a = new A(*b); //(stack ptr) FH mars 2006 //cerr << " set_peq " << *a << " " << **a << " = " << *b << " " << b << endl; } return a;}};// ---------------------------------------------template<class A,class B>struct set_eqarrayp: public binary_function<A*,B,A*> { static A* f(A* const & a, B const & b) { *a = *b; return a;}};template<class A,class B>struct set_eqarrayp_add: public binary_function<A*,B,A*> { static A* f(A* const & a, B const & b) { assert(SameShape(*a,*b)); *a += *b; return a;}};template<class A,class B>struct set_eqarrayp_sub: public binary_function<A*,B,A*> { static A* f(A* const & a, B const & b) { assert(SameShape(*a,*b)); *a -= *b; return a;}};template<class A,class B>struct set_eqarrayp_mul: public binary_function<A*,B,A*> { static A* f(A* const & a, B const & b) { assert(SameShape(*a,*b)); *a *= *b; return a;}};template<class A,class B>struct set_eqarrayp_div: public binary_function<A*,B,A*> { static A* f(A* const & a, B const & b) { assert(SameShape(*a,*b)); *a /= *b; return a;}};// ---------------------------------------------template<class A,class B>struct set_eqarraypd: public binary_function<A*,B,A*> { static A* f(A* const & a, B const & b) {assert(SameShape(*a,*b)); *a = *b; delete b; return a;}};template<class A,class B>struct set_eqarraypd_add: public binary_function<A*,B,A*> { static A* f(A* const & a, B const & b) {assert(SameShape(*a,*b)); *a += *b; delete b; return a;}};template<class A,class B>struct set_eqarraypd_sub: public binary_function<A*,B,A*> { static A* f(A* const & a, B const & b) {assert(SameShape(*a,*b)); *a -= *b; delete b; return a;}};template<class A,class B>struct set_eqarraypd_mul: public binary_function<A*,B,A*> { static A* f(A* const & a, B const & b) {assert(SameShape(*a,*b)); *a *= *b; delete b; return a;}};template<class A,class B>struct set_eqarraypd_div: public binary_function<A*,B,A*> { static A* f(A* const & a, B const & b) {assert(SameShape(*a,*b)); *a /= *b; delete b; return a;}};// ---------------------------------------------template<class A,class B>struct set_eqarray: public binary_function<A*,B,A*> { static A* f(A* const & a, B const & b) { *a = b; return a;}};// --------------------------------------------- august 2007 FH template<class A,class B>struct init_eqarray: public binary_function<A*,B,A*> { static A* f(A* const & a, B const & b) { a->init(); *a = b; return a;}};// ---------------------------------------------template<class A,class B>struct init_eqarraypd: public binary_function<A*,B,A*> { static A* f(A* const & a, B const & b) {a->init(); *a = *b; delete b; return a;}};// ---------------------------------------------template<class A,class B>struct init_eqarrayp: public binary_function<A*,B,A*> { static A* f(A* const & a, B const & b) { a->init(); *a = *b; return a;}};// ---------------------------------------- fin modif august 2007template<class A,class B>struct set_eqarray_add: public binary_function<A*,B,A*> { static A* f(A* const & a, B const & b) {assert(SameShape(*a,b)); *a += b; return a;}};template<class A,class B>struct set_eqarray_sub: public binary_function<A*,B,A*> { static A* f(A* const & a, B const & b) {assert(SameShape(*a,b)); *a -= b; return a;}};template<class A,class B>struct set_eqarray_mul: public binary_function<A*,B,A*> { static A* f(A* const & a, B const & b) {assert(SameShape(*a,b)); *a *= b; return a;}};template<class A,class B>struct set_eqarray_div: public binary_function<A*,B,A*> { static A* f(A* const & a, B const & b) {assert(SameShape(*a,b)); *a /= b; return a;}};template<class A,class B>struct set_eq_array: public binary_function<A,B,A> { static A f(const A & a, B const & b) { A aa=a;aa = b; return a;}};template<class A,class B>struct set_eq_array_add: public binary_function<A,B,A> { static A f(A const & a, B const & b) {assert(SameShape(a,b)); A aa(a); aa += b; return a;}};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -