2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.tizenopensource.org/license
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #ifndef __CALCULATOR_PARSER_H
20 #define __CALCULATOR_PARSER_H
24 #endif /* __cplusplus */
30 CHAR_IS_DIGIT, //0,1,2...
31 CHAR_IS_LEFT_PARENTHESE, //(
32 CHAR_IS_RIGHT_PARENTHESE,
33 CHAR_IS_PLUS_MINUS, //+/-
36 CHAR_IS_MULTIPLY_DIVIDE, // */
37 CHAR_IS_CHARACTER, //a,P,C,^
38 CHAR_IS_POINT, //point
43 *@enum calculator_state_t, define calculator current state
45 * This enum is used to judge or record which state is current.
49 CALCULATOR_WAITING_INPUT = 0, /**<waiting input state*/
50 CALCULATOR_OPERAND_INPUT, /**<operand input state*/
51 CALCULATOR_OPERAND_FRACTION_INPUT, /**<fraction operand input state*/
52 CALCULATOR_OPERATOR_INPUT, /**<[basic] operator input state*/
53 CALCULATOR_OPERATOR_OPERAND_INPUT, /**<operand after [basic] operator input state*/
54 CALCULATOR_SPECIAL_SYMBOL_INPUT, /**<special symbol inputting state*/
55 CALCULATOR_SPECIAL_SYMBOL_INPUT_OVER,
56 /**<special symbol inputed state*/
57 CALCULATOR_SPECIAL_FUNCTION_INPUT, /**<function[excluding basic operator] input state*/
58 CALCULATOR_NAVIGATION, /**<browser in entry state, depreated*/
59 CALCULATOR_CALCULATED, /**<calculation completed state*/
60 CALCULATOR_ERROR_OCCURED, /**<error occured state*/
65 *@enum calculator_calculate_priority_t, define calculation priorities
67 * This enum is used to mark operator &functions's priority.
71 CALCULATOR_CALCULATE_PRIORITY_INVALID = 0,
72 /**<invalid priority*/
73 CALCULATOR_CALCULATE_PRIORITY_LOW, /**<lowest priority*/
74 CALCULATOR_CALCULATE_PRIORITY_MIDDLE, /**<middle priority*/
75 CALCULATOR_CALCULATE_PRIORITY_HIGH, /**<high priority*/
76 CALCULATOR_CALCULATE_PRIORITY_HIGHER, /**<higher priority*/
77 CALCULATOR_CALCULATE_PRIORITY_HIGHEST, /**<highest priority*/
78 } calculator_calculate_priority_t;
82 *@enum operator_type_t, define calculator operator type
86 OPERATOR_TYPE_INVALID = 0,
87 /**<operator type invalid*/
88 OPERATOR_TYPE_UNARY, /**<operator unary*/
89 OPERATOR_TYPE_BINARY, /**<operator binary*/
90 OPERATOR_TYPE_CNT, /**<max count*/
95 *@enum function_category_t, define calculator function category
100 /**<category invalid*/
101 FUNCTION_PREFIX, /**<prefix category, operand follows functions*/
102 FUNCTION_POSTFIX, /**<postfix category, function follows operand*/
104 /**<constant category, only for PI*/
105 FUNCTION_CNT, /**<max count*/
106 } function_category_t;
137 /* function pannel */
167 * @struct calculator_node_data_t, calculator node data structure
169 * This structure is used as node data of n-ary tree
173 double tmp_result; /**<store result by temoprary*/
174 calculator_calculate_priority_t node_calcu_priority;
175 /**<node calculation priority*/
176 operator_type_t operator_type; /**<node operator type*/
177 int children_num; /**<node children number*/
178 char cur_operator; /**<node operator char*/
179 int negative_flag; /**<node negative flag*/
180 } calculator_node_data_t;
184 * @struct calculator_parentheses_data_t, calculator parentheses data structure
188 // GNode* tree; /**<parentheses tree node*/
189 char *start_pos;/**<parentheses start position in original string*/
190 char *end_pos; /**<parentheses end position in original string*/
192 /**<parentheses if is matched*/
193 } calculator_parentheses_data_t;
197 * @struct function_t, calculator function data structure
201 char *func_name; /**<function name, use only prompt*/
202 char *func_string; /**<function string, use in text view*/
203 gint str_len; /**<function string length*/
204 char function_char; /**<function char*/
205 function_category_t category; /**<fuction category, input after operand*/
206 operator_type_t op_type; /**<operator type*/
207 calculator_calculate_priority_t priority;
208 /**<calculation priority*/
209 bool has_parentheses; /**<if function has parentheses*/
220 //bool calculator_calculate_truncate_result(double* tmp_result);
226 * @param szInputString
230 int calculator_get_open_braket(const char *szInputString);
242 bool calculator_get_digits_number(char *szInput, int *pDigitCnt,
255 bool calculator_calculate(char *string, double *result,
260 #endif /* __cplusplus */