Scid  4.6.5
ui.h
Go to the documentation of this file.
1 /*
2 # Copyright (C) 2015 Fulvio Benini
3 
4 * This file is part of Scid (Shane's Chess Information Database).
5 *
6 * Scid is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation.
9 *
10 * Scid is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with Scid. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #ifndef SCID_UI__H
20 #define SCID_UI__H
21 
22 #include "misc.h"
23 #ifndef CHECKUIDEP
24 #include "ui_tcltk.h"
25 #else
26 //Dummy functions useful to catch unwanted dependencies
27 namespace UI_impl {
28 
29 typedef int UI_res_t;
30 typedef void* UI_extra_t;
31 typedef void* UI_handle_t;
32 
33 inline int Main (int argc, char* argv[], void (*exit) (void*)) {
34  return 0;
35 }
36 inline Progress CreateProgress(UI_handle_t) {
37  return Progress();
38 }
39 inline Progress CreateProgressPosMask(UI_handle_t) {
40  return Progress();
41 }
42 class List {
43 public:
44  explicit List(size_t) {}
45  void clear() {}
46  template <typename T> void push_back(const T&) {}
47 };
48 inline UI_res_t Result(UI_handle_t, errorT) {
49  return 0;
50 }
51 template <typename T>
52 inline UI_res_t Result(UI_handle_t, errorT, const T&) {
53  return 0;
54 }
55 
56 }
57 #endif
58 
59 
60 /*
61  * Interface for communication between UI and c++ server.
62  *
63  * The interaction between the UI and c++ code is of type client/server.
64  * UI calls sc_ functions, the c++ server execute the operation and returns
65  * a success/error code plus, optionally, some results.
66  *
67  * The only server-side event generated by c++ code is for long operations:
68  * it will repeatedly report to UI the amount of work done until completion.
69  * UI should respond to this events with true (continue) or false (interrupt).
70  */
71 
72 
73 using UI_impl::UI_res_t;
76 
77 /**
78  * sc_*() - Execute server side operations
79  * Each function usually have subcommands.
80  * See functions implemenations for more usage info.
81  */
82 UI_res_t str_is_prefix (UI_extra_t, UI_handle_t, int argc, const char ** argv);
83 UI_res_t str_prefix_len (UI_extra_t, UI_handle_t, int argc, const char ** argv);
84 UI_res_t sc_base (UI_extra_t, UI_handle_t, int argc, const char ** argv);
85 UI_res_t sc_book (UI_extra_t, UI_handle_t, int argc, const char ** argv);
86 UI_res_t sc_clipbase (UI_extra_t, UI_handle_t, int argc, const char ** argv);
87 UI_res_t sc_eco (UI_extra_t, UI_handle_t, int argc, const char ** argv);
88 UI_res_t sc_filter (UI_extra_t, UI_handle_t, int argc, const char ** argv);
89 UI_res_t sc_game (UI_extra_t, UI_handle_t, int argc, const char ** argv);
90 UI_res_t sc_info (UI_extra_t, UI_handle_t, int argc, const char ** argv);
91 UI_res_t sc_move (UI_extra_t, UI_handle_t, int argc, const char ** argv);
92 UI_res_t sc_name (UI_extra_t, UI_handle_t, int argc, const char ** argv);
93 UI_res_t sc_report (UI_extra_t, UI_handle_t, int argc, const char ** argv);
94 UI_res_t sc_pos (UI_extra_t, UI_handle_t, int argc, const char ** argv);
95 UI_res_t sc_search (UI_extra_t, UI_handle_t, int argc, const char ** argv);
96 UI_res_t sc_tree (UI_extra_t, UI_handle_t, int argc, const char ** argv);
97 UI_res_t sc_var (UI_extra_t, UI_handle_t, int argc, const char ** argv);
98 
99 
100 /**
101  * UI_Main() - Init the UI
102  * @exit: clean up function to be called when closing UI
103  */
104 inline int UI_Main (int argc, char* argv[], void (*exit) (void*)) {
105  return UI_impl::Main(argc, argv, exit);
106 }
107 
108 
109 /**
110  * UI_CreateProgress() - create a Progress object
111  *
112  * With this function c++ code contact the UI to report that the operation
113  * asked may take a long time.
114  * Then c++ code call Progress::report repeatedly to inform the UI about
115  * the percentage of work done and an estimated time to complete the operation.
116  * Progress::report will return false if the UI wants to interrupt the operation
117  *
118  * Return:
119  * a Progress object that represent the server->UI async communication, or
120  * an empty Progress() if the UI is not interested in the progress report.
121  */
122 inline Progress UI_CreateProgress(UI_handle_t ti) {
123  return UI_impl::CreateProgress(ti);
124 }
125 inline Progress UI_CreateProgressPosMask(UI_handle_t ti) {
127 }
128 
129 
130 /**
131  * UI_Result() - pass the result of an operation from c++ to UI
132  * @res: OK for success or an error code (error.h)
133  * @value: a value (or a list of values, see UI_List) to pass to UI
134  *
135  * Typical usage:
136  * UI_Result(ti, OK);
137  * UI_Result(ti, OK, "string value");
138  * UI_Result(ti, OK, 5);
139  */
140 inline UI_res_t UI_Result(UI_handle_t ti, errorT res) {
141  return UI_impl::Result(ti, res);
142 }
143 template <typename T>
144 inline UI_res_t UI_Result(UI_handle_t ti, errorT res, const T& value) {
145  return UI_impl::Result(ti, res, value);
146 }
147 
148 
149 /**
150  * class UI_List - create a list of values to be sent to UI
151  * @max_size: currently there is no automatic reallocation in push_back()
152  * so the constructor must know the max number of values that
153  * will be stored in the list
154  *
155  * An heterogeneous container used to pass values from c++ to UI
156  *
157  * Typical usage:
158  * UI_List uiList(2);
159  * uiList.push_back("string value");
160  * uiList.push_back(5);
161  * UI_Result(ti, OK, uiList)
162  */
163 class UI_List : public UI_impl::List {
164 public:
165  explicit UI_List(size_t max_size)
166  : UI_impl::List(max_size) {
167  }
168 
169  /**
170  * Inherited from UI_impl::List
171  *
172  void clear();
173  template <typename T> void push_back(const T& value);
174  */
175 };
176 
177 
178 #endif
UI_res_t sc_move(UI_extra_t, UI_handle_t, int argc, const char **argv)
UI_res_t sc_tree(UI_extra_t, UI_handle_t, int argc, const char **argv)
Definition: misc.h:124
UI_res_t sc_var(UI_extra_t, UI_handle_t, int argc, const char **argv)
UI_res_t sc_eco(UI_extra_t, UI_handle_t, int argc, const char **argv)
int UI_res_t
Definition: ui_tcltk.h:30
UI_res_t sc_name(UI_extra_t, UI_handle_t, int argc, const char **argv)
UI_res_t str_prefix_len(UI_extra_t, UI_handle_t, int argc, const char **argv)
UI_res_t Result(UI_handle_t ti, errorT res)
Definition: ui_tcltk.h:210
UI_res_t sc_book(UI_extra_t, UI_handle_t, int argc, const char **argv)
Progress CreateProgressPosMask(UI_handle_t data)
Definition: ui_tcltk.h:123
UI_res_t sc_search(UI_extra_t, UI_handle_t, int argc, const char **argv)
UI_res_t sc_base(UI_extra_t, UI_handle_t, int argc, const char **argv)
Definition: sc_base.cpp:851
unsigned short errorT
Definition: error.h:20
UI_res_t sc_filter(UI_extra_t, UI_handle_t, int argc, const char **argv)
Definition: sc_filter.cpp:165
UI_res_t UI_Result(UI_handle_t ti, errorT res)
UI_Result() - pass the result of an operation from c++ to UI : OK for success or an error code (error...
Definition: ui.h:140
void push_back(Tcl_Obj *value)
Definition: ui_tcltk.h:154
int Main(int argc, char *argv[], void(*exit)(void *))
Definition: ui_tcltk.h:36
UI_res_t sc_info(UI_extra_t, UI_handle_t, int argc, const char **argv)
class UI_List - create a list of values to be sent to UI : currently there is no automatic reallocati...
Definition: ui.h:163
UI_res_t sc_report(UI_extra_t, UI_handle_t, int argc, const char **argv)
UI_List(size_t max_size)
Definition: ui.h:165
UI_res_t sc_clipbase(UI_extra_t, UI_handle_t, int argc, const char **argv)
Tcl_Interp * UI_handle_t
Definition: ui_tcltk.h:32
UI_res_t str_is_prefix(UI_extra_t, UI_handle_t, int argc, const char **argv)
sc_*() - Execute server side operations Each function usually have subcommands.
Progress UI_CreateProgress(UI_handle_t ti)
UI_CreateProgress() - create a Progress object.
Definition: ui.h:122
int UI_Main(int argc, char *argv[], void(*exit)(void *))
UI_Main() - Init the UI : clean up function to be called when closing UI.
Definition: ui.h:104
List(size_t max_size)
Definition: ui_tcltk.h:136
Progress CreateProgress(UI_handle_t data)
Definition: ui_tcltk.h:117
UI_res_t sc_pos(UI_extra_t, UI_handle_t, int argc, const char **argv)
void clear()
Definition: ui_tcltk.h:149
Progress UI_CreateProgressPosMask(UI_handle_t ti)
Definition: ui.h:125
UI_res_t sc_game(UI_extra_t, UI_handle_t, int argc, const char **argv)
ClientData UI_extra_t
Definition: ui_tcltk.h:31