source: XIOS/dev/XIOS_DEV_CMIP6/src/parse_expr/scalar_expr_node.hpp @ 1474

Last change on this file since 1474 was 1158, checked in by oabramkina, 7 years ago

Two server levels: merging with trunk r1137.
There are bugs.

File size: 4.1 KB
Line 
1#ifndef __XIOS_SCALAR_EXPR_NODE_HPP__
2#define __XIOS_SCALAR_EXPR_NODE_HPP__
3
4#include <string>
5#include <boost/smart_ptr/scoped_ptr.hpp>
6
7namespace xios
8{
9  /*!
10   * Interface implemented by all the nodes of a tree representing an expression
11   * which can be reduced to a scalar value.
12   */
13  struct IScalarExprNode
14  {
15    /*!
16     * Builds a filter graph corresponding to the expression tree.
17     *
18     * \return the output pin of the filter producing the result of the expression
19     */
20    virtual double reduce() const = 0;
21  };
22
23  /*!
24   * Expression node corresponding to a scalar value.
25   */
26  class CScalarValExprNode : public IScalarExprNode
27  {
28    public:
29      /*!
30       * Constructs an expression node corresponding to the specified scalar value.
31       *
32       * \param strVal the string representation of the scalar value
33       */
34      CScalarValExprNode(const std::string& strVal);
35
36      double reduce() const;
37
38    private:
39      std::string strVal; //!< The string representation of the scalar value
40  };
41
42  /*!
43   * Expression node corresponding to a scalar variable.
44   */
45  class CScalarVarExprNode : public IScalarExprNode
46  {
47    public:
48      /*!
49       * Constructs an expression node corresponding
50       * to the scalar variable whose id is provided.
51       *
52       * \param varId the identifier of the scalar variable
53       */
54      CScalarVarExprNode(const std::string& varId);
55
56      double reduce() const;
57
58    private:
59      std::string varId; //!< The identifier of the field
60  };
61
62  /*!
63   * Expression node corresponding to a unary operation on a scalar.
64   */
65  class CScalarUnaryOpExprNode : public IScalarExprNode
66  {
67    public:
68      /*!
69       * Constructs an expression node corresponding to the specified unary operation
70       * applied to the provided scalar node.
71       * Note that the child node will be destroyed automatically when the parent node
72       * is destroyed.
73       *
74       * \param opId the identifier of the operator
75       * \param child the scalar child node to which the operator is applied
76       */
77      CScalarUnaryOpExprNode(const std::string& opId, IScalarExprNode* child);
78
79      double reduce() const;
80
81    private:
82      std::string opId; //!< The identifier of the field
83      boost::scoped_ptr<IScalarExprNode> child; //!< The scalar child node to which the operator is applied
84  };
85
86  /*!
87   * Expression node corresponding to a binary operation on two scalars.
88   */
89  class CScalarBinaryOpExprNode : public IScalarExprNode
90  {
91    public:
92      /*!
93       * Constructs an expression node corresponding to the specified binary operation
94       * applied to the provided scalar child nodes.
95       * Note that the child nodes will be destroyed automatically when the parent node
96       * is destroyed.
97       *
98       * \param opId the identifier of the operator
99       * \param child1, child2 the scalar child nodes to which the operator is applied
100       */
101      CScalarBinaryOpExprNode(IScalarExprNode* child1, const std::string& opId, IScalarExprNode* child2);
102
103      double reduce() const;
104
105    private:
106      std::string opId; //!< The identifier of the field
107      boost::scoped_ptr<IScalarExprNode> child1, child2; //!< The scalar child nodes to which the operator is applied
108  };
109
110    class CScalarTernaryOpExprNode : public IScalarExprNode
111  {
112    public:
113      /*!
114       * Constructs an expression node corresponding to the specified ternary operation
115       * applied to the provided scalar child nodes.
116       * Note that the child nodes will be destroyed automatically when the parent node
117       * is destroyed.
118       *
119       * \param opId the identifier of the operator
120       * \param child1, child2 , child3 the scalar child nodes to which the operator is applied
121       */
122      CScalarTernaryOpExprNode(IScalarExprNode* child1, const std::string& opId, IScalarExprNode* child2, IScalarExprNode* child3);
123
124      double reduce() const;
125
126    private:
127      std::string opId; //!< The identifier of the field
128      boost::scoped_ptr<IScalarExprNode> child1, child2, child3; //!< The scalar child nodes to which the operator is applied
129  };
130}
131
132#endif // __XIOS_SCALAR_EXPR_NODE_HPP__
Note: See TracBrowser for help on using the repository browser.