Scid  4.7.0
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  * @param 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  * @param res: OK for success or an error code (error.h)
133  * @param value: a value (or a list of values, see UI_List) to pass to the 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  * An heterogeneous container used to pass a list of values from c++ to UI.
151  * @param 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  *
156  * Typical usage:
157  * UI_List uiList(2);
158  * uiList.push_back("string value");
159  * uiList.push_back(5);
160  * UI_Result(ti, OK, uiList)
161  */
162 class UI_List : public UI_impl::List {
163 public:
164  explicit UI_List(size_t max_size)
165  : UI_impl::List(max_size) {
166  }
167 
168  /**
169  * Inherited from UI_impl::List
170  *
171  void clear();
172  template <typename T> void push_back(const T& value);
173  */
174 };
175 
176 
177 #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:63
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)
Definition: tkscid.cpp:7426
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:208
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:913
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.
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)
An heterogeneous container used to pass a list of values from c++ to UI.
Definition: ui.h:162
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:164
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.
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