Geogram  Version 1.9.1-rc
A programming library of geometric algorithms
command.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2000-2022 Inria
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  * * Neither the name of the ALICE Project-Team nor the names of its
14  * contributors may be used to endorse or promote products derived from this
15  * software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  *
29  * Contact: Bruno Levy
30  *
31  * https://www.inria.fr/fr/bruno-levy
32  *
33  * Inria,
34  * Domaine de Voluceau,
35  * 78150 Le Chesnay - Rocquencourt
36  * FRANCE
37  *
38  */
39 
40 #ifndef GEOGRAM_GFX_GUI_COMMAND
41 #define GEOGRAM_GFX_GUI_COMMAND
42 
44 #include <geogram/basic/logger.h>
45 #include <geogram/basic/string.h>
46 
53 namespace GEO {
54 
61  public:
66 
70  ~CommandInvoker() override;
71 
75  virtual void invoke() = 0;
76 
84  virtual void auto_create_args() = 0;
85  };
86 
92 
93  /*****************************************************************/
94 
99  class GEOGRAM_GFX_API Command : public Counted {
100  public:
101 
145  template<class FPTR> static void set_current(
146  const std::string& prototype, FPTR tfun
147  );
148 
199  template<class T, class TFPTR> static void set_current(
200  const std::string& prototype, T* target, TFPTR tfun
201  );
202 
213  static void flush_queue();
214 
215 
219  static void replay_latest();
220 
228  Command(const std::string& prototype);
229 
230 
235  const std::string& name() const {
236  return name_;
237  }
238 
247  void set_invoker(CommandInvoker* invoker) {
248  invoker_ = invoker;
249  if(auto_create_args_) {
250  invoker_->auto_create_args();
251  auto_create_args_ = false;
252  }
253  }
254 
258  ~Command() override;
259 
265  bool is_visible() const {
266  return visible_;
267  }
268 
274  bool* is_visible_ptr() {
275  return &visible_;
276  }
277 
283  virtual void draw();
284 
292  virtual void reset_factory_settings();
293 
305  virtual void apply() ;
306 
312  static Command* current() {
313  return current_;
314  }
315 
316 
322  static Command* latest() {
323  return latest_;
324  }
325 
330  static Command* queued() {
331  return queued_;
332  }
333 
334 
338  static void reset_current() {
339  current_.reset();
340  }
341 
348  static void set_current(Command* command) {
349  current_ = command;
350  command->visible_ = true;
351  }
352 
362  bool bool_arg_by_index(index_t i) const {
363  const Arg& arg = find_arg_by_index(i);
364  geo_assert(arg.type == Arg::ARG_BOOL);
365  return arg.val.bool_val;
366  }
367 
377  int int_arg_by_index(index_t i) const;
378 
390  unsigned int uint_arg_by_index(index_t i) const;
391 
401  float float_arg_by_index(index_t i) const {
402  const Arg& arg = find_arg_by_index(i);
403  geo_assert(arg.type == Arg::ARG_FLOAT);
404  return arg.val.float_val;
405  }
406 
417  double double_arg_by_index(index_t i) const {
418  return double(float_arg_by_index(i));
419  }
420 
430  std::string string_arg_by_index(index_t i) const {
431  const Arg& arg = find_arg_by_index(i);
432  geo_assert(arg.type == Arg::ARG_STRING);
433  return std::string(arg.val.string_val);
434  }
435 
447  template<class T> void get_arg_by_index(index_t i, T& val) {
448  geo_argused(val);
449  Logger::err("Cmd") << "Attempted to read argument #"
450  << i
451  << " to variable of unknown type"
452  << std::endl;
454  }
455 
456  /***************************************************************/
457 
467  template <class T> void invoke(
468  T* target, void (T::*fptr)(void)
469  ) {
470  this->assert_nb_args_matches(0);
471  if(target != nullptr && fptr != nullptr) {
472  (*target.*fptr)();
473  }
474  }
475 
486  template <
487  class T,
488  class ARG0
489  > void invoke(
490  T* target,
491  void (T::*fptr)(ARG0)
492  ) {
493  this->assert_nb_args_matches(1);
494  ARG0 a0;
495  this->get_arg_by_index(0,a0);
496  if(target != nullptr && fptr != nullptr) {
497  (*target.*fptr)(a0);
498  }
499  }
500 
511  template <
512  class T,
513  class ARG0, class ARG1
514  > void invoke(
515  T* target,
516  void (T::*fptr)(ARG0,ARG1)
517  ) {
518  this->assert_nb_args_matches(2);
519  ARG0 a0;
520  this->get_arg_by_index(0,a0);
521  ARG1 a1;
522  this->get_arg_by_index(1,a1);
523  if(target != nullptr && fptr != nullptr) {
524  (*target.*fptr)(a0,a1);
525  }
526  }
527 
539  template <
540  class T,
541  class ARG0, class ARG1, class ARG2
542  > void invoke(
543  T* target,
544  void (T::*fptr)(ARG0,ARG1,ARG2)
545  ) {
546  this->assert_nb_args_matches(3);
547  ARG0 a0;
548  this->get_arg_by_index(0,a0);
549  ARG1 a1;
550  this->get_arg_by_index(1,a1);
551  ARG2 a2;
552  this->get_arg_by_index(2,a2);
553  if(target != nullptr && fptr != nullptr) {
554  (*target.*fptr)(a0,a1,a2);
555  }
556  }
557 
569  template <
570  class T,
571  class ARG0, class ARG1, class ARG2, class ARG3
572  > void invoke(
573  T* target,
574  void (T::*fptr)(ARG0,ARG1,ARG2,ARG3)
575  ) {
576  this->assert_nb_args_matches(4);
577  ARG0 a0;
578  this->get_arg_by_index(0,a0);
579  ARG1 a1;
580  this->get_arg_by_index(1,a1);
581  ARG2 a2;
582  this->get_arg_by_index(2,a2);
583  ARG3 a3;
584  this->get_arg_by_index(3,a3);
585  if(target != nullptr && fptr != nullptr) {
586  (*target.*fptr)(a0,a1,a2,a3);
587  }
588  }
589 
601  template <
602  class T,
603  class ARG0, class ARG1, class ARG2, class ARG3,
604  class ARG4
605  > void invoke(
606  T* target,
607  void (T::*fptr)(ARG0,ARG1,ARG2,ARG3,ARG4)
608  ) {
609  this->assert_nb_args_matches(5);
610  ARG0 a0;
611  this->get_arg_by_index(0,a0);
612  ARG1 a1;
613  this->get_arg_by_index(1,a1);
614  ARG2 a2;
615  this->get_arg_by_index(2,a2);
616  ARG3 a3;
617  this->get_arg_by_index(3,a3);
618  ARG4 a4;
619  this->get_arg_by_index(4,a4);
620  if(target != nullptr && fptr != nullptr) {
621  (*target.*fptr)(a0,a1,a2,a3,a4);
622  }
623  }
624 
636  template <
637  class T,
638  class ARG0, class ARG1, class ARG2, class ARG3,
639  class ARG4, class ARG5
640  > void invoke(
641  T* target,
642  void (T::*fptr)(ARG0,ARG1,ARG2,ARG3,ARG4,ARG5)
643  ) {
644  this->assert_nb_args_matches(6);
645  ARG0 a0;
646  this->get_arg_by_index(0,a0);
647  ARG1 a1;
648  this->get_arg_by_index(1,a1);
649  ARG2 a2;
650  this->get_arg_by_index(2,a2);
651  ARG3 a3;
652  this->get_arg_by_index(3,a3);
653  ARG4 a4;
654  this->get_arg_by_index(4,a4);
655  ARG5 a5;
656  this->get_arg_by_index(5,a5);
657  if(target != nullptr && fptr != nullptr) {
658  (*target.*fptr)(a0,a1,a2,a3,a4,a5);
659  }
660  }
661 
673  template <
674  class T,
675  class ARG0, class ARG1, class ARG2, class ARG3,
676  class ARG4, class ARG5, class ARG6
677  > void invoke(
678  T* target,
679  void (T::*fptr)(ARG0,ARG1,ARG2,ARG3,ARG4,ARG5,ARG6)
680  ) {
681  this->assert_nb_args_matches(7);
682  ARG0 a0;
683  this->get_arg_by_index(0,a0);
684  ARG1 a1;
685  this->get_arg_by_index(1,a1);
686  ARG2 a2;
687  this->get_arg_by_index(2,a2);
688  ARG3 a3;
689  this->get_arg_by_index(3,a3);
690  ARG4 a4;
691  this->get_arg_by_index(4,a4);
692  ARG5 a5;
693  this->get_arg_by_index(5,a5);
694  ARG6 a6;
695  this->get_arg_by_index(6,a6);
696  if(target != nullptr && fptr != nullptr) {
697  (*target.*fptr)(a0,a1,a2,a3,a4,a5,a6);
698  }
699  }
700 
712  template <
713  class T,
714  class ARG0, class ARG1, class ARG2, class ARG3,
715  class ARG4, class ARG5, class ARG6, class ARG7
716  > void invoke(
717  T* target,
718  void (T::*fptr)(ARG0,ARG1,ARG2,ARG3,ARG4,ARG5,ARG6,ARG7)
719  ) {
720  this->assert_nb_args_matches(8);
721  ARG0 a0;
722  this->get_arg_by_index(0,a0);
723  ARG1 a1;
724  this->get_arg_by_index(1,a1);
725  ARG2 a2;
726  this->get_arg_by_index(2,a2);
727  ARG3 a3;
728  this->get_arg_by_index(3,a3);
729  ARG4 a4;
730  this->get_arg_by_index(4,a4);
731  ARG5 a5;
732  this->get_arg_by_index(5,a5);
733  ARG6 a6;
734  this->get_arg_by_index(6,a6);
735  ARG7 a7;
736  this->get_arg_by_index(7,a7);
737  if(target != nullptr && fptr != nullptr) {
738  (*target.*fptr)(a0,a1,a2,a3,a4,a5,a6,a7);
739  }
740  }
741 
742  /**************************************************************/
743 
752  void invoke(
753  void (*fptr)(void)
754  ) {
755  this->assert_nb_args_matches(0);
756  if(fptr != nullptr) {
757  (*fptr)();
758  }
759  }
760 
770  template <
771  class ARG0
772  > void invoke(
773  void (*fptr)(ARG0)
774  ) {
775  this->assert_nb_args_matches(1);
776  ARG0 a0;
777  this->get_arg_by_index(0,a0);
778  if(fptr != nullptr) {
779  (*fptr)(a0);
780  }
781  }
782 
792  template <
793  class ARG0, class ARG1
794  > void invoke(
795  void (*fptr)(ARG0,ARG1)
796  ) {
797  this->assert_nb_args_matches(2);
798  ARG0 a0;
799  this->get_arg_by_index(0,a0);
800  ARG1 a1;
801  this->get_arg_by_index(1,a1);
802  if(fptr != nullptr) {
803  (*fptr)(a0,a1);
804  }
805  }
806 
816  template <
817  class ARG0, class ARG1, class ARG2
818  > void invoke(
819  void (*fptr)(ARG0,ARG1,ARG2)
820  ) {
821  this->assert_nb_args_matches(3);
822  ARG0 a0;
823  this->get_arg_by_index(0,a0);
824  ARG1 a1;
825  this->get_arg_by_index(1,a1);
826  ARG2 a2;
827  this->get_arg_by_index(2,a2);
828  if(fptr != nullptr) {
829  (*fptr)(a0,a1,a2);
830  }
831  }
832 
842  template <
843  class ARG0, class ARG1, class ARG2, class ARG3
844  > void invoke(
845  void (*fptr)(ARG0,ARG1,ARG2,ARG3)
846  ) {
847  this->assert_nb_args_matches(4);
848  ARG0 a0;
849  this->get_arg_by_index(0,a0);
850  ARG1 a1;
851  this->get_arg_by_index(1,a1);
852  ARG2 a2;
853  this->get_arg_by_index(2,a2);
854  ARG3 a3;
855  this->get_arg_by_index(3,a3);
856  if(fptr != nullptr) {
857  (*fptr)(a0,a1,a2,a3);
858  }
859  }
860 
870  template <
871  class ARG0, class ARG1, class ARG2, class ARG3,
872  class ARG4
873  > void invoke(
874  void (*fptr)(ARG0,ARG1,ARG2,ARG3,ARG4)
875  ) {
876  this->assert_nb_args_matches(5);
877  ARG0 a0;
878  this->get_arg_by_index(0,a0);
879  ARG1 a1;
880  this->get_arg_by_index(1,a1);
881  ARG2 a2;
882  this->get_arg_by_index(2,a2);
883  ARG3 a3;
884  this->get_arg_by_index(3,a3);
885  ARG4 a4;
886  this->get_arg_by_index(4,a4);
887  if(fptr != nullptr) {
888  (*fptr)(a0,a1,a2,a3,a4);
889  }
890  }
891 
901  template <
902  class ARG0, class ARG1, class ARG2, class ARG3,
903  class ARG4, class ARG5
904  > void invoke(
905  void (*fptr)(ARG0,ARG1,ARG2,ARG3,ARG4,ARG5)
906  ) {
907  this->assert_nb_args_matches(6);
908  ARG0 a0;
909  this->get_arg_by_index(0,a0);
910  ARG1 a1;
911  this->get_arg_by_index(1,a1);
912  ARG2 a2;
913  this->get_arg_by_index(2,a2);
914  ARG3 a3;
915  this->get_arg_by_index(3,a3);
916  ARG4 a4;
917  this->get_arg_by_index(4,a4);
918  ARG5 a5;
919  this->get_arg_by_index(5,a5);
920  if(fptr != nullptr) {
921  (*fptr)(a0,a1,a2,a3,a4,a5);
922  }
923  }
924 
934  template <
935  class ARG0, class ARG1, class ARG2, class ARG3,
936  class ARG4, class ARG5, class ARG6
937  > void invoke(
938  void (*fptr)(ARG0,ARG1,ARG2,ARG3,ARG4,ARG5,ARG6)
939  ) {
940  this->assert_nb_args_matches(7);
941  ARG0 a0;
942  this->get_arg_by_index(0,a0);
943  ARG1 a1;
944  this->get_arg_by_index(1,a1);
945  ARG2 a2;
946  this->get_arg_by_index(2,a2);
947  ARG3 a3;
948  this->get_arg_by_index(3,a3);
949  ARG4 a4;
950  this->get_arg_by_index(4,a4);
951  ARG5 a5;
952  this->get_arg_by_index(5,a5);
953  ARG6 a6;
954  this->get_arg_by_index(6,a6);
955  if(fptr != nullptr) {
956  (*fptr)(a0,a1,a2,a3,a4,a5,a6);
957  }
958  }
959 
969  template <
970  class ARG0, class ARG1, class ARG2, class ARG3,
971  class ARG4, class ARG5, class ARG6, class ARG7
972  > void invoke(
973  void (*fptr)(ARG0,ARG1,ARG2,ARG3,ARG4,ARG5,ARG6,ARG7)
974  ) {
975  this->assert_nb_args_matches(8);
976  ARG0 a0;
977  this->get_arg_by_index(0,a0);
978  ARG1 a1;
979  this->get_arg_by_index(1,a1);
980  ARG2 a2;
981  this->get_arg_by_index(2,a2);
982  ARG3 a3;
983  this->get_arg_by_index(3,a3);
984  ARG4 a4;
985  this->get_arg_by_index(4,a4);
986  ARG5 a5;
987  this->get_arg_by_index(5,a5);
988  ARG6 a6;
989  this->get_arg_by_index(6,a6);
990  ARG7 a7;
991  this->get_arg_by_index(7,a7);
992  if(fptr != nullptr) {
993  (*fptr)(a0,a1,a2,a3,a4,a5,a6,a7);
994  }
995  }
996 
997  /**************************************************************/
998 
999  protected:
1000 
1011  geo_assert(
1012  (auto_create_args_ && args_.size() == 0) ||
1013  (args_.size() == nb)
1014  );
1015  }
1016 
1017 
1027  template<class T> void add_arg(
1028  const std::string& name, const T& default_val,
1029  const std::string& help = ""
1030  ) {
1031  args_.push_back(Arg(name, default_val, help));
1032  }
1033 
1042  template<class T> void create_arg(
1043  index_t i, const T& default_val
1044  ) {
1045  if(i >= args_.size()) {
1046  args_.resize(i+1);
1047  }
1048  args_[i] = Arg("arg " + String::to_string(i), default_val);
1049  }
1050 
1051  private:
1052 
1057  struct GEOGRAM_GFX_API ArgVal {
1061  void clear();
1062 
1066  ArgVal() {
1067  clear();
1068  }
1069 
1075  ArgVal(const ArgVal& rhs);
1076 
1083  ArgVal& operator=(const ArgVal& rhs);
1084 
1085  bool bool_val;
1086  int int_val;
1087  float float_val;
1088  char string_val[64];
1089  };
1090 
1096  struct GEOGRAM_GFX_API Arg {
1097 
1101  Arg();
1102 
1110  Arg(
1111  const std::string& name_in, bool x,
1112  const std::string& help_in=""
1113  );
1114 
1122  Arg(
1123  const std::string& name_in, int x,
1124  const std::string& help_in=""
1125  );
1126 
1135  Arg(
1136  const std::string& name_in, unsigned int x,
1137  const std::string& help_in=""
1138  );
1139 
1147  Arg(
1148  const std::string& name_in, float x,
1149  const std::string& help_in=""
1150  );
1151 
1160  Arg(
1161  const std::string& name_in, double x,
1162  const std::string& help_in=""
1163  );
1164 
1173  Arg(
1174  const std::string& name_in, const std::string& x,
1175  const std::string& help_in=""
1176  );
1177 
1181  void draw();
1182 
1183  enum { ARG_BOOL, ARG_INT, ARG_UINT, ARG_FLOAT, ARG_STRING } type;
1184  std::string name;
1185  std::string help;
1186  ArgVal val;
1187  ArgVal default_val;
1188  };
1189 
1197  const Arg& find_arg(const std::string& name) const {
1198  for(index_t i=0; i<args_.size(); ++i) {
1199  if(args_[i].name == name) {
1200  return args_[i];
1201  }
1202  }
1204  }
1205 
1211  const Arg& find_arg_by_index(index_t i) const {
1212  geo_assert(i < args_.size());
1213  return args_[i];
1214  }
1215 
1216 
1217  private:
1218  std::string name_;
1219  std::string help_;
1220  vector<Arg> args_;
1221  CommandInvoker_var invoker_;
1222  bool visible_;
1227  bool auto_create_args_;
1228  static SmartPointer<Command> current_;
1229  static SmartPointer<Command> queued_;
1230  static SmartPointer<Command> latest_;
1231  };
1232 
1233 /***********************************************************************/
1234 
1238  template<> inline void Command::get_arg_by_index(
1239  index_t i, bool& val
1240  ) {
1241  if(auto_create_args_) {
1242  val = false;
1243  this->create_arg(i, val);
1244  } else {
1245  val = this->bool_arg_by_index(i);
1246  }
1247  }
1248 
1252  template<> inline void Command::get_arg_by_index(
1253  index_t i, int& val
1254  ) {
1255  if(auto_create_args_) {
1256  val = 0;
1257  this->create_arg(i, val);
1258  } else {
1259  val = this->int_arg_by_index(i);
1260  }
1261  }
1262 
1266  template<> inline void Command::get_arg_by_index(
1267  index_t i, unsigned int& val
1268  ) {
1269  if(auto_create_args_) {
1270  val = 0;
1271  this->create_arg(i, val);
1272  } else {
1273  val = this->uint_arg_by_index(i);
1274  }
1275  }
1276 
1280  template<> inline void Command::get_arg_by_index(
1281  index_t i, float& val
1282  ) {
1283  if(auto_create_args_) {
1284  val = 0.0f;
1285  this->create_arg(i, val);
1286  } else {
1287  val = this->float_arg_by_index(i);
1288  }
1289  }
1290 
1294  template<> inline void Command::get_arg_by_index(
1295  index_t i, double& val
1296  ) {
1297  if(auto_create_args_) {
1298  val = 0.0;
1299  this->create_arg(i, val);
1300  } else {
1301  val = this->double_arg_by_index(i);
1302  }
1303  }
1304 
1308  template<> inline void Command::get_arg_by_index(
1309  index_t i, std::string& val
1310  ) {
1311  if(auto_create_args_) {
1312  val = "";
1313  this->create_arg(i, val);
1314  } else {
1315  val = this->string_arg_by_index(i);
1316  }
1317  }
1318 
1319  /*****************************************************************/
1320 
1326  template <class FPTR>
1328  public:
1329 
1336  Command* command,
1337  FPTR fun
1338  ) :
1339  command_(command),
1340  fun_(fun) {
1341  }
1342 
1346  void invoke() override {
1347  command_->invoke(fun_);
1348  }
1349 
1353  void auto_create_args() override {
1354  command_->invoke(FPTR(nullptr));
1355  }
1356 
1357  private:
1358  Command* command_;
1359  FPTR fun_;
1360  };
1361 
1362  /*****************************************************************/
1363 
1371  template <class T, class TFPTR>
1373  public:
1374 
1383  Command* command,
1384  T* target,
1385  TFPTR target_fun
1386  ) :
1387  command_(command),
1388  target_(target),
1389  target_fun_(target_fun) {
1390  }
1391 
1396  void invoke() override {
1397  command_->invoke(target_, target_fun_);
1398  }
1399 
1404  void auto_create_args() override {
1405  command_->invoke((T*)(nullptr), (TFPTR)(nullptr));
1406  }
1407 
1408 
1409  private:
1410  Command* command_;
1411  T* target_;
1412  TFPTR target_fun_;
1413  };
1414 
1415  /*****************************************************************/
1416 
1417  template<class FPTR> inline void Command::set_current(
1418  const std::string& prototype,
1419  FPTR fun
1420  ) {
1421  set_current(new Command(prototype));
1422  current()->set_invoker(
1424  );
1425  }
1426 
1427  /*****************************************************************/
1428 
1429  template<class T, class TFPTR> inline void Command::set_current(
1430  const std::string& prototype,
1431  T* target,
1432  TFPTR tfun
1433  ) {
1434  set_current(new Command(prototype));
1435  current()->set_invoker(
1436  new MemberFunctionCommandInvoker<T, TFPTR>(current(), target, tfun)
1437  );
1438  }
1439 
1440  /*****************************************************************/
1441 
1442 }
1443 
1444 #endif
#define geo_assert_not_reached
Sets a non reachable point in the program.
Definition: assert.h:177
#define geo_assert(x)
Verifies that a condition is met.
Definition: assert.h:149
Abstract class for calling functions or calling member functions.
Definition: command.h:60
CommandInvoker()
CommandInvoker constructor.
virtual void auto_create_args()=0
Creates the arguments in the target command.
~CommandInvoker() override
CommandInvoker destructor.
virtual void invoke()=0
Invokes the target function.
Manages the GUI of a command with ImGUI.
Definition: command.h:99
static void flush_queue()
Flushes the potentially queued command invokation.
void invoke(T *target, void(T::*fptr)(ARG0, ARG1, ARG2))
Invokes a member function with the stored arguments.
Definition: command.h:542
~Command() override
Command destructor.
void get_arg_by_index(index_t i, T &val)
Gets the value of an argument by index.
Definition: command.h:447
bool is_visible() const
Tests whether this Command is visible.
Definition: command.h:265
int int_arg_by_index(index_t i) const
Gets the value of an integer argument by index.
void assert_nb_args_matches(index_t nb)
Tests whether the number of declared arguments matches a specified number.
Definition: command.h:1010
void invoke(T *target, void(T::*fptr)(ARG0, ARG1))
Invokes a member function with the stored arguments.
Definition: command.h:514
virtual void reset_factory_settings()
Restores default parameter values for all parameters.
void invoke(T *target, void(T::*fptr)(ARG0, ARG1, ARG2, ARG3, ARG4))
Invokes a member function with the stored arguments.
Definition: command.h:605
void invoke(void(*fptr)(ARG0, ARG1, ARG2, ARG3, ARG4))
Invokes a function with the stored arguments.
Definition: command.h:873
static Command * queued()
Gets the queued command.
Definition: command.h:330
void invoke(T *target, void(T::*fptr)(ARG0, ARG1, ARG2, ARG3, ARG4, ARG5))
Invokes a member function with the stored arguments.
Definition: command.h:640
const std::string & name() const
Gets the name of this command.
Definition: command.h:235
virtual void draw()
Displays and manages the GUI of this Command.
void invoke(void(*fptr)(void))
Invokes a function with the stored arguments.
Definition: command.h:752
float float_arg_by_index(index_t i) const
Gets the value of a floating-point argument by index.
Definition: command.h:401
void invoke(void(*fptr)(ARG0))
Invokes a function with the stored arguments.
Definition: command.h:772
static void set_current(Command *command)
Sets the current command.
Definition: command.h:348
void set_invoker(CommandInvoker *invoker)
Sets the invoker.
Definition: command.h:247
void invoke(void(*fptr)(ARG0, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6))
Invokes a function with the stored arguments.
Definition: command.h:937
bool * is_visible_ptr()
Gets a pointer to the visibility flag of this command.
Definition: command.h:274
void invoke(T *target, void(T::*fptr)(ARG0))
Invokes a member function with the stored arguments.
Definition: command.h:489
void invoke(void(*fptr)(ARG0, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7))
Invokes a function with the stored arguments.
Definition: command.h:972
virtual void apply()
Gets the value of the parameters and does the task.
void add_arg(const std::string &name, const T &default_val, const std::string &help="")
Adds a parameter to this command.
Definition: command.h:1027
static Command * current()
Gets the current command.
Definition: command.h:312
static void replay_latest()
Replays the latest invoked command.
void invoke(void(*fptr)(ARG0, ARG1, ARG2, ARG3, ARG4, ARG5))
Invokes a function with the stored arguments.
Definition: command.h:904
void invoke(T *target, void(T::*fptr)(void))
Invokes a member function with the stored arguments.
Definition: command.h:467
bool bool_arg_by_index(index_t i) const
Gets the value of a boolean argument by index.
Definition: command.h:362
static void reset_current()
Resets the current command.
Definition: command.h:338
void invoke(T *target, void(T::*fptr)(ARG0, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7))
Invokes a member function with the stored arguments.
Definition: command.h:716
std::string string_arg_by_index(index_t i) const
Gets the value of a string argument by index.
Definition: command.h:430
void invoke(void(*fptr)(ARG0, ARG1))
Invokes a function with the stored arguments.
Definition: command.h:794
void create_arg(index_t i, const T &default_val)
Creates an argument at a given index.
Definition: command.h:1042
Command(const std::string &prototype)
Command constructor.
static void set_current(const std::string &prototype, FPTR tfun)
Binds the current command to a function.
Definition: command.h:1417
void invoke(void(*fptr)(ARG0, ARG1, ARG2))
Invokes a function with the stored arguments.
Definition: command.h:818
void invoke(T *target, void(T::*fptr)(ARG0, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6))
Invokes a member function with the stored arguments.
Definition: command.h:677
double double_arg_by_index(index_t i) const
Gets the value of a floating-point argument by index and converts it to a double.
Definition: command.h:417
void invoke(void(*fptr)(ARG0, ARG1, ARG2, ARG3))
Invokes a function with the stored arguments.
Definition: command.h:844
static Command * latest()
Gets the latest command.
Definition: command.h:322
unsigned int uint_arg_by_index(index_t i) const
Gets the value of an unsigned integer argument by index.
void invoke(T *target, void(T::*fptr)(ARG0, ARG1, ARG2, ARG3))
Invokes a member function with the stored arguments.
Definition: command.h:572
Base class for reference-counted objects.
Definition: counted.h:71
An implementation of CommandInvoker that calls a function.
Definition: command.h:1327
FunctionCommandInvoker(Command *command, FPTR fun)
FunctionCommandInvoker constructor.
Definition: command.h:1335
void invoke() override
Invokes the target function.
Definition: command.h:1346
void auto_create_args() override
Creates the arguments in the target command.
Definition: command.h:1353
static std::ostream & err(const std::string &feature)
Gets the stream to send error messages.
An implementation of CommandInvoker that calls a member function of an object.
Definition: command.h:1372
void auto_create_args() override
Creates the arguments in the target command.
Definition: command.h:1404
MemberFunctionCommandInvoker(Command *command, T *target, TFPTR target_fun)
MemberFunctionCommandInvoker constructor.
Definition: command.h:1382
void invoke() override
Invokes the target function.
Definition: command.h:1396
#define GEOGRAM_GFX_API
Linkage declaration for geogram symbols.
Definition: defs.h:55
Common include file, providing basic definitions. Should be included before anything else by all head...
Generic logging mechanism.
void clear(void *addr, size_t size)
Clears a memory block.
Definition: memory.h:116
Global Vorpaline namespace.
Definition: basic.h:55
SmartPointer< CommandInvoker > CommandInvoker_var
Automatic reference-counted pointer to a CommandInvoker.
Definition: command.h:91
void geo_argused(const T &)
Suppresses compiler warnings about unused parameters.
Definition: argused.h:60
geo_index_t index_t
The type for storing and manipulating indices.
Definition: numeric.h:329
Functions for string manipulation.