GTK+/Kalkulator 0.0.1 - kalkulator.hpp

Z Wikibooks, biblioteki wolnych podręczników.
Przejdź do nawigacji Przejdź do wyszukiwania
 1 #include <gtk/gtk.h>
 2 
 3 enum btn_id
 4 {
 5   Button_1 = 1,  Button_2 = 2,  Button_3 = 3,  Button_4 = 4,  Button_5 = 5,
 6   Button_6 = 6,  Button_7 = 7,  Button_8 = 8,  Button_9 = 9,  Button_0 = 0,
 7   Button_add = 10,  Button_sub = 11,  Button_multi = 12,  Button_div = 13,
 8   Button_result = 14,
 9   Button_comma = 15,  Button_back = 16,  Button_clear = 17,Button_signed = 18,
10   Button_addmem = 19, Button_readmem =20, Button_clearmem=21,
11   NoSelectBtn = 22
12 };
13 enum operation_id
14 {
15   Add = 1, Sub = 2, Multi = 3, Div = 4, NoSelectOprt = 5
16 };
17 
18 class Kalkulator
19 {
20 	private:
21     GString *value1;
22     GString *value2;
23     operation_id operation;
24     operation_id prev_operation;
25     gboolean is_value1;
26     gboolean is_value2;
27     gboolean is_result;
28     btn_id prev_button;
29     // wykorzystywany do śledzenia poprzednio wciśniętych przycisków
30     // (prev_button przechwuje tylko ostatnio wciśnięte)
31     btn_id button_cache_comma; 
32     btn_id button_cache_result; 
33     GList *memory;
34   
35   public:
36     Kalkulator();
37     ~Kalkulator();
38     const char*  _btn_id_to_char(btn_id val);
39     const char*  _operation_id_to_char(operation_id val);
40     btn_id       _operation_id_to_btn_id(operation_id val);
41     void __debug(const gchar* event,bool data);
42     void calculate(bool);
43     char* get_value1();
44     void  set_value1(const gchar *val);
45     bool  del_value1();
46     char* get_value2();
47     void  set_value2(const gchar *val);
48     bool  del_value2();
49     bool  get_is_value1() {return is_value1;};
50     void  set_is_value1(bool val) {is_value1=val;};
51     bool  get_is_value2() {return is_value2;};
52     void  set_is_value2(bool val) {is_value2=val;};
53     bool  get_is_result() {return is_result;};
54     void  set_is_result(bool val) {is_result=val;};
55     operation_id get_operation() {return operation;};
56     void  set_operation(operation_id val) {operation=val;};
57     operation_id get_prev_operation() {return prev_operation;};
58     void  set_prev_operation(operation_id val) {prev_operation=val;};
59     inline btn_id get_button_cache_result() {return button_cache_result;};
60     inline void  set_button_cache_result(btn_id val) {button_cache_result=val;};
61     btn_id get_prev_button() {return prev_button;};
62     void  set_prev_button(btn_id val) {prev_button=val;};
63     inline btn_id get_button_cache_comma() {return button_cache_comma;};
64     inline void  set_button_cache_comma(btn_id val) {button_cache_comma=val;};
65     void add_to_memory(const gchar *val);
66     void memory_free();
67     void memory_print();
68     guint memory_count();
69 };