e2f45fd2c98f06abedb47d28277126af3bd2f843
[apps/core/preloaded/calculator.git] / include / calc-expression.h
1 /*
2 *
3 * Copyright 2012  Samsung Electronics Co., Ltd
4 *
5 * Licensed under the Flora License, Version 1.0 (the License);
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 *    http://floralicense.org/license
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an AS IS BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 */
18
19 #ifndef __DEF_CALC_EXPRESSION_H_
20 #define __DEF_CALC_EXPRESSION_H_
21
22 #ifdef __cplusplus
23 extern "C" {
24
25 #endif  /* __cplusplus */
26
27 #include "calculator_parser.h"
28
29 #define IS_SIGN(ch)         ((ch) == '+' || (ch) == '-')
30 #define IS_SCIENCE_E(ch)    ((ch) == 'E' || (ch) == 'e')
31 #define IS_OPERATOER(ch)    ((ch) == '+' || (ch) == '-' || (ch) == 'x' || (ch) == '/' || (ch) == '^')
32 #define IS_DIGITAL(ch)          (isdigit((ch)) || (ch) == 'p' || (ch) == 'e')
33
34 /* */
35 #define FLOAT_EQUAL(a, b)       (fabs((a) - (b)) < 0.000000000001)
36           struct calc_func_t  {
37                 op_id_t id;
38                 char *symbol;
39         };
40
41 /**
42 * @describe
43 *
44 *
45 * @param    expr_in
46 * @param    expr_out
47 * @return    void
48 * @exception
49 */
50         void calc_expr_format_expression(const char *expr_in, char *expr_out);
51
52 /**
53 * @describe
54 *
55 *
56 * @param    expr
57 * @return    int
58 * @exception
59 */
60         int calc_expr_get_operator_num(const char *expr);
61
62 /**
63 * @describe
64 *
65 *
66 * @param    expr
67 * @return    int
68 * @exception
69 */
70         int calc_expr_get_left_parentheses_num(const char *expr);
71
72 /**
73 * @describe
74 *
75 *
76 * @param    expr
77 * @return    void
78 * @exception
79 */
80         void calc_expr_replace_with_special_char(char *expr);
81
82 /**
83 * @describe
84 *
85 *
86 * @param    expr
87 * @return    void
88 * @exception
89 */
90         void calc_expr_replace_from_special_char(char *expr);
91
92 /**
93 * @describe
94 *
95 *
96 * @param    result
97 * @param    text
98 * @return    void
99 * @exception
100 */
101         void calc_expr_num_format_result(double result, char *text);
102
103 /**
104 * @describe
105 *
106 *
107 * @param    expr
108 * @param    cursor
109 * @return    void
110 * @exception
111 */
112         char *calc_expr_get_current_func_at_cursor(char *expr, int cursor);
113
114 /**
115 * @describe
116 *
117 *
118 * @param    expr
119 * @param    cursor
120 * @param    begin
121 * @param    length
122 * @return    int
123 * @exception
124 */
125         int calc_expr_get_current_num_at_cursor(char *expr, int cursor,
126                                                 int *begin, int *length);
127
128 /**
129 * @describe
130 *
131 *
132 * @param    expr
133 * @return    void
134 * @exception
135 */
136         void calc_expr_close_parentheses(char *exp);
137
138 /**
139 * @describe
140 *
141 *
142 * @param    expr
143 * @return    void
144 * @exception
145 */
146         void calc_expr_preprocess(char *exp);
147
148 /**
149 * @describe
150 *
151 *
152 * @param    expr
153 * @param    cursor
154 * @return    void
155 * @exception
156 */
157         void calc_expr_input_backspace(char *exp, int *cursor);
158
159 /**
160 * @describe
161 *
162 *
163 * @param    expr
164 * @param    cursor
165 * @param    cursor
166 * @return    str
167 * @exception
168 */
169         void calc_expr_input_insert(char *exp, int *cursor, char *str);
170
171 bool calc_select_string_search(char *str);
172
173
174 #ifdef __cplusplus
175 }
176 #endif  /* __cplusplus */
177
178 #endif  /* __DEF_CALC_EXPRESSION_H_ */
179