40 #ifndef GEOGRAM_GFX_GUI_COMMAND
41 #define GEOGRAM_GFX_GUI_COMMAND
145 template<
class FPTR>
static void set_current(
146 const std::string& prototype, FPTR tfun
199 template<
class T,
class TFPTR>
static void set_current(
200 const std::string& prototype, T* target, TFPTR tfun
235 const std::string&
name()
const {
249 if(auto_create_args_) {
251 auto_create_args_ =
false;
350 command->visible_ =
true;
363 const Arg& arg = find_arg_by_index(i);
365 return arg.val.bool_val;
402 const Arg& arg = find_arg_by_index(i);
404 return arg.val.float_val;
418 return double(float_arg_by_index(i));
431 const Arg& arg = find_arg_by_index(i);
433 return std::string(arg.val.string_val);
449 Logger::err(
"Cmd") <<
"Attempted to read argument #"
451 <<
" to variable of unknown type"
468 T* target,
void (T::*fptr)(
void)
470 this->assert_nb_args_matches(0);
471 if(target !=
nullptr && fptr !=
nullptr) {
491 void (T::*fptr)(ARG0)
493 this->assert_nb_args_matches(1);
495 this->get_arg_by_index(0,a0);
496 if(target !=
nullptr && fptr !=
nullptr) {
513 class ARG0,
class ARG1
516 void (T::*fptr)(ARG0,ARG1)
518 this->assert_nb_args_matches(2);
520 this->get_arg_by_index(0,a0);
522 this->get_arg_by_index(1,a1);
523 if(target !=
nullptr && fptr !=
nullptr) {
524 (*target.*fptr)(a0,a1);
541 class ARG0,
class ARG1,
class ARG2
544 void (T::*fptr)(ARG0,ARG1,ARG2)
546 this->assert_nb_args_matches(3);
548 this->get_arg_by_index(0,a0);
550 this->get_arg_by_index(1,a1);
552 this->get_arg_by_index(2,a2);
553 if(target !=
nullptr && fptr !=
nullptr) {
554 (*target.*fptr)(a0,a1,a2);
571 class ARG0,
class ARG1,
class ARG2,
class ARG3
574 void (T::*fptr)(ARG0,ARG1,ARG2,ARG3)
576 this->assert_nb_args_matches(4);
578 this->get_arg_by_index(0,a0);
580 this->get_arg_by_index(1,a1);
582 this->get_arg_by_index(2,a2);
584 this->get_arg_by_index(3,a3);
585 if(target !=
nullptr && fptr !=
nullptr) {
586 (*target.*fptr)(a0,a1,a2,a3);
603 class ARG0,
class ARG1,
class ARG2,
class ARG3,
607 void (T::*fptr)(ARG0,ARG1,ARG2,ARG3,ARG4)
609 this->assert_nb_args_matches(5);
611 this->get_arg_by_index(0,a0);
613 this->get_arg_by_index(1,a1);
615 this->get_arg_by_index(2,a2);
617 this->get_arg_by_index(3,a3);
619 this->get_arg_by_index(4,a4);
620 if(target !=
nullptr && fptr !=
nullptr) {
621 (*target.*fptr)(a0,a1,a2,a3,a4);
638 class ARG0,
class ARG1,
class ARG2,
class ARG3,
639 class ARG4,
class ARG5
642 void (T::*fptr)(ARG0,ARG1,ARG2,ARG3,ARG4,ARG5)
644 this->assert_nb_args_matches(6);
646 this->get_arg_by_index(0,a0);
648 this->get_arg_by_index(1,a1);
650 this->get_arg_by_index(2,a2);
652 this->get_arg_by_index(3,a3);
654 this->get_arg_by_index(4,a4);
656 this->get_arg_by_index(5,a5);
657 if(target !=
nullptr && fptr !=
nullptr) {
658 (*target.*fptr)(a0,a1,a2,a3,a4,a5);
675 class ARG0,
class ARG1,
class ARG2,
class ARG3,
676 class ARG4,
class ARG5,
class ARG6
679 void (T::*fptr)(ARG0,ARG1,ARG2,ARG3,ARG4,ARG5,ARG6)
681 this->assert_nb_args_matches(7);
683 this->get_arg_by_index(0,a0);
685 this->get_arg_by_index(1,a1);
687 this->get_arg_by_index(2,a2);
689 this->get_arg_by_index(3,a3);
691 this->get_arg_by_index(4,a4);
693 this->get_arg_by_index(5,a5);
695 this->get_arg_by_index(6,a6);
696 if(target !=
nullptr && fptr !=
nullptr) {
697 (*target.*fptr)(a0,a1,a2,a3,a4,a5,a6);
714 class ARG0,
class ARG1,
class ARG2,
class ARG3,
715 class ARG4,
class ARG5,
class ARG6,
class ARG7
718 void (T::*fptr)(ARG0,ARG1,ARG2,ARG3,ARG4,ARG5,ARG6,ARG7)
720 this->assert_nb_args_matches(8);
722 this->get_arg_by_index(0,a0);
724 this->get_arg_by_index(1,a1);
726 this->get_arg_by_index(2,a2);
728 this->get_arg_by_index(3,a3);
730 this->get_arg_by_index(4,a4);
732 this->get_arg_by_index(5,a5);
734 this->get_arg_by_index(6,a6);
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);
755 this->assert_nb_args_matches(0);
756 if(fptr !=
nullptr) {
775 this->assert_nb_args_matches(1);
777 this->get_arg_by_index(0,a0);
778 if(fptr !=
nullptr) {
793 class ARG0,
class ARG1
795 void (*fptr)(ARG0,ARG1)
797 this->assert_nb_args_matches(2);
799 this->get_arg_by_index(0,a0);
801 this->get_arg_by_index(1,a1);
802 if(fptr !=
nullptr) {
817 class ARG0,
class ARG1,
class ARG2
819 void (*fptr)(ARG0,ARG1,ARG2)
821 this->assert_nb_args_matches(3);
823 this->get_arg_by_index(0,a0);
825 this->get_arg_by_index(1,a1);
827 this->get_arg_by_index(2,a2);
828 if(fptr !=
nullptr) {
843 class ARG0,
class ARG1,
class ARG2,
class ARG3
845 void (*fptr)(ARG0,ARG1,ARG2,ARG3)
847 this->assert_nb_args_matches(4);
849 this->get_arg_by_index(0,a0);
851 this->get_arg_by_index(1,a1);
853 this->get_arg_by_index(2,a2);
855 this->get_arg_by_index(3,a3);
856 if(fptr !=
nullptr) {
857 (*fptr)(a0,a1,a2,a3);
871 class ARG0,
class ARG1,
class ARG2,
class ARG3,
874 void (*fptr)(ARG0,ARG1,ARG2,ARG3,ARG4)
876 this->assert_nb_args_matches(5);
878 this->get_arg_by_index(0,a0);
880 this->get_arg_by_index(1,a1);
882 this->get_arg_by_index(2,a2);
884 this->get_arg_by_index(3,a3);
886 this->get_arg_by_index(4,a4);
887 if(fptr !=
nullptr) {
888 (*fptr)(a0,a1,a2,a3,a4);
902 class ARG0,
class ARG1,
class ARG2,
class ARG3,
903 class ARG4,
class ARG5
905 void (*fptr)(ARG0,ARG1,ARG2,ARG3,ARG4,ARG5)
907 this->assert_nb_args_matches(6);
909 this->get_arg_by_index(0,a0);
911 this->get_arg_by_index(1,a1);
913 this->get_arg_by_index(2,a2);
915 this->get_arg_by_index(3,a3);
917 this->get_arg_by_index(4,a4);
919 this->get_arg_by_index(5,a5);
920 if(fptr !=
nullptr) {
921 (*fptr)(a0,a1,a2,a3,a4,a5);
935 class ARG0,
class ARG1,
class ARG2,
class ARG3,
936 class ARG4,
class ARG5,
class ARG6
938 void (*fptr)(ARG0,ARG1,ARG2,ARG3,ARG4,ARG5,ARG6)
940 this->assert_nb_args_matches(7);
942 this->get_arg_by_index(0,a0);
944 this->get_arg_by_index(1,a1);
946 this->get_arg_by_index(2,a2);
948 this->get_arg_by_index(3,a3);
950 this->get_arg_by_index(4,a4);
952 this->get_arg_by_index(5,a5);
954 this->get_arg_by_index(6,a6);
955 if(fptr !=
nullptr) {
956 (*fptr)(a0,a1,a2,a3,a4,a5,a6);
970 class ARG0,
class ARG1,
class ARG2,
class ARG3,
971 class ARG4,
class ARG5,
class ARG6,
class ARG7
973 void (*fptr)(ARG0,ARG1,ARG2,ARG3,ARG4,ARG5,ARG6,ARG7)
975 this->assert_nb_args_matches(8);
977 this->get_arg_by_index(0,a0);
979 this->get_arg_by_index(1,a1);
981 this->get_arg_by_index(2,a2);
983 this->get_arg_by_index(3,a3);
985 this->get_arg_by_index(4,a4);
987 this->get_arg_by_index(5,a5);
989 this->get_arg_by_index(6,a6);
991 this->get_arg_by_index(7,a7);
992 if(fptr !=
nullptr) {
993 (*fptr)(a0,a1,a2,a3,a4,a5,a6,a7);
1012 (auto_create_args_ && args_.size() == 0) ||
1013 (args_.size() == nb)
1028 const std::string& name,
const T& default_val,
1029 const std::string& help =
""
1031 args_.push_back(Arg(name, default_val, help));
1043 index_t i,
const T& default_val
1045 if(i >= args_.size()) {
1048 args_[i] = Arg(
"arg " + String::to_string(i), default_val);
1075 ArgVal(
const ArgVal& rhs);
1083 ArgVal& operator=(
const ArgVal& rhs);
1088 char string_val[64];
1111 const std::string& name_in,
bool x,
1112 const std::string& help_in=
""
1123 const std::string& name_in,
int x,
1124 const std::string& help_in=
""
1136 const std::string& name_in,
unsigned int x,
1137 const std::string& help_in=
""
1148 const std::string& name_in,
float x,
1149 const std::string& help_in=
""
1161 const std::string& name_in,
double x,
1162 const std::string& help_in=
""
1174 const std::string& name_in,
const std::string& x,
1175 const std::string& help_in=
""
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) {
1211 const Arg& find_arg_by_index(
index_t i)
const {
1227 bool auto_create_args_;
1228 static SmartPointer<Command> current_;
1229 static SmartPointer<Command> queued_;
1230 static SmartPointer<Command> latest_;
1241 if(auto_create_args_) {
1255 if(auto_create_args_) {
1269 if(auto_create_args_) {
1283 if(auto_create_args_) {
1297 if(auto_create_args_) {
1311 if(auto_create_args_) {
1326 template <
class FPTR>
1354 command_->
invoke(FPTR(
nullptr));
1371 template <
class T,
class TFPTR>
1389 target_fun_(target_fun) {
1397 command_->
invoke(target_, target_fun_);
1405 command_->
invoke((T*)(
nullptr), (TFPTR)(
nullptr));
1418 const std::string& prototype,
1430 const std::string& prototype,
#define geo_assert_not_reached
Sets a non reachable point in the program.
#define geo_assert(x)
Verifies that a condition is met.
Abstract class for calling functions or calling member functions.
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.
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.
~Command() override
Command destructor.
void get_arg_by_index(index_t i, T &val)
Gets the value of an argument by index.
bool is_visible() const
Tests whether this Command is visible.
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.
void invoke(T *target, void(T::*fptr)(ARG0, ARG1))
Invokes a member function with the stored arguments.
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.
void invoke(void(*fptr)(ARG0, ARG1, ARG2, ARG3, ARG4))
Invokes a function with the stored arguments.
static Command * queued()
Gets the queued command.
void invoke(T *target, void(T::*fptr)(ARG0, ARG1, ARG2, ARG3, ARG4, ARG5))
Invokes a member function with the stored arguments.
const std::string & name() const
Gets the name of this command.
virtual void draw()
Displays and manages the GUI of this Command.
void invoke(void(*fptr)(void))
Invokes a function with the stored arguments.
float float_arg_by_index(index_t i) const
Gets the value of a floating-point argument by index.
void invoke(void(*fptr)(ARG0))
Invokes a function with the stored arguments.
static void set_current(Command *command)
Sets the current command.
void set_invoker(CommandInvoker *invoker)
Sets the invoker.
void invoke(void(*fptr)(ARG0, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6))
Invokes a function with the stored arguments.
bool * is_visible_ptr()
Gets a pointer to the visibility flag of this command.
void invoke(T *target, void(T::*fptr)(ARG0))
Invokes a member function with the stored arguments.
void invoke(void(*fptr)(ARG0, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7))
Invokes a function with the stored arguments.
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.
static Command * current()
Gets the current command.
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.
void invoke(T *target, void(T::*fptr)(void))
Invokes a member function with the stored arguments.
bool bool_arg_by_index(index_t i) const
Gets the value of a boolean argument by index.
static void reset_current()
Resets the current command.
void invoke(T *target, void(T::*fptr)(ARG0, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7))
Invokes a member function with the stored arguments.
std::string string_arg_by_index(index_t i) const
Gets the value of a string argument by index.
void invoke(void(*fptr)(ARG0, ARG1))
Invokes a function with the stored arguments.
void create_arg(index_t i, const T &default_val)
Creates an argument at a given index.
Command(const std::string &prototype)
Command constructor.
static void set_current(const std::string &prototype, FPTR tfun)
Binds the current command to a function.
void invoke(void(*fptr)(ARG0, ARG1, ARG2))
Invokes a function with the stored arguments.
void invoke(T *target, void(T::*fptr)(ARG0, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6))
Invokes a member function with the stored arguments.
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.
void invoke(void(*fptr)(ARG0, ARG1, ARG2, ARG3))
Invokes a function with the stored arguments.
static Command * latest()
Gets the latest command.
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.
Base class for reference-counted objects.
An implementation of CommandInvoker that calls a function.
FunctionCommandInvoker(Command *command, FPTR fun)
FunctionCommandInvoker constructor.
void invoke() override
Invokes the target function.
void auto_create_args() override
Creates the arguments in the target command.
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.
void auto_create_args() override
Creates the arguments in the target command.
MemberFunctionCommandInvoker(Command *command, T *target, TFPTR target_fun)
MemberFunctionCommandInvoker constructor.
void invoke() override
Invokes the target function.
#define GEOGRAM_GFX_API
Linkage declaration for geogram symbols.
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.
Global Vorpaline namespace.
SmartPointer< CommandInvoker > CommandInvoker_var
Automatic reference-counted pointer to a CommandInvoker.
void geo_argused(const T &)
Suppresses compiler warnings about unused parameters.
geo_index_t index_t
The type for storing and manipulating indices.
Functions for string manipulation.