1 /* $Header: /var/cvs/mbdyn/mbdyn/mbdyn-1.0/libraries/libmbutil/evaluator.h,v 1.3 2017/01/12 14:44:04 masarati Exp $ */
2 /*
3 * MBDyn (C) is a multibody analysis code.
4 * http://www.mbdyn.org
5 *
6 * Copyright (C) 1996-2017
7 *
8 * Pierangelo Masarati <masarati@aero.polimi.it>
9 * Paolo Mantegazza <mantegazza@aero.polimi.it>
10 *
11 * Dipartimento di Ingegneria Aerospaziale - Politecnico di Milano
12 * via La Masa, 34 - 20156 Milano, Italy
13 * http://www.aero.polimi.it
14 *
15 * Changing this copyright notice is forbidden.
16 *
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation (version 2 of the License).
20 *
21 *
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 */
31
32 /*
33 * With the contribution of Ankit Aggarwal <ankit.ankit.aggarwal@gmail.com>
34 * during Google Summer of Code 2015
35 */
36
37 #ifndef EVALUATOR_H
38 #define EVALUATOR_H
39
40 #include "mathtyp.h"
41
42 class ExpressionElement {
43 public:
44 enum EEFlags {
45 EE_NONE = 0x0U,
46
47 EE_CONSTIFY = 0x1U,
48
49 EE_OPTIMIZE = EE_CONSTIFY
50 };
51
52 protected:
53 static unsigned m_uEEFlags;
54
55 public:
~ExpressionElement(void)56 virtual ~ExpressionElement(void) {};
57 #if 0 // TODO: check correctness whenever possible
58 virtual bool Check(void) const = { return true; };
59 #endif
60 virtual TypedValue Eval(void) const = 0;
61 virtual std::ostream& Output(std::ostream& out) const = 0;
62
GetFlags(void)63 static unsigned GetFlags(void) { return m_uEEFlags; };
SetFlag(EEFlags f)64 static void SetFlag(EEFlags f) { m_uEEFlags |= unsigned(f); };
ClearFlag(EEFlags f)65 static void ClearFlag(EEFlags f) { m_uEEFlags &= !unsigned(f); };
IsFlag(EEFlags f)66 static bool IsFlag(EEFlags f) { return m_uEEFlags & unsigned(f); };
67 };
68
69 extern std::string EEStrOut(const ExpressionElement *e);
70
71 extern bool EE_Eval(TypedValue& dst, const ExpressionElement *ee);
72 extern bool EE_Eval(bool& dst, const ExpressionElement *ee);
73 extern bool EE_Eval(Int& dst, const ExpressionElement *ee);
74 extern bool EE_Eval(Real& dst, const ExpressionElement *ee);
75 extern bool EE_Eval(std::string& dst, const ExpressionElement *ee);
76
EE_Eval(T & dst,const ExpressionElement * ee)77 template <class T> bool EE_Eval(T& dst, const ExpressionElement *ee) { ASSERT(ee == 0); return false; };
78
79 #endif // EVALUATOR_H
80