| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
#ifndef GVARS3_INC_GUI_IMPL_H |
| 10 |
#define GVARS3_INC_GUI_IMPL_H |
| 11 |
|
| 12 |
#include <gvars3/gvars3.h> |
| 13 |
#include <gvars3/GUI.h> |
| 14 |
#include <vector> |
| 15 |
#include <iostream> |
| 16 |
#include <set> |
| 17 |
#include <list> |
| 18 |
#include <functional> |
| 19 |
|
| 20 |
namespace GVars3 |
| 21 |
{ |
| 22 |
typedef struct |
| 23 |
{ |
| 24 |
GUICallbackProc cbp; |
| 25 |
void* thisptr; |
| 26 |
} CallbackInfoStruct; |
| 27 |
|
| 28 |
typedef std::vector<CallbackInfoStruct> CallbackVector; |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
class GUI_language; |
| 34 |
|
| 35 |
class GUI_impl |
| 36 |
{ |
| 37 |
public: |
| 38 |
GUI_impl(); |
| 39 |
void post_init(); |
| 40 |
GUI_impl(GVars2*); |
| 41 |
|
| 42 |
void RegisterCommand(std::string sCommandName, GUICallbackProc callback, void* thisptr=NULL); |
| 43 |
void RegisterCommand(std::string sCommandName, std::function<void(std::string,std::string)>); |
| 44 |
void UnRegisterAllCommands(void* thisptr); |
| 45 |
void UnRegisterCommand(std::string sCommandName, void* thisptr); |
| 46 |
void UnRegisterCommand(std::string sCommandName); |
| 47 |
void ParseLine(std::string s, bool bSilentFailure = false); |
| 48 |
void ParseStream(std::istream& is); |
| 49 |
void LoadFile(std::string sFileName); |
| 50 |
|
| 51 |
bool CallCallbacks(std::string sCommand, std::string sParams); |
| 52 |
void SetupReadlineCompletion(); |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
void StartParserThread(); |
| 57 |
|
| 58 |
|
| 59 |
static void StopParserThread(); |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
int parseArguments( const int argc, char * argv[], int start = 1, const std::string prefix = "--", const std::string execKeyword = "exec" ); |
| 71 |
|
| 72 |
private: |
| 73 |
void do_builtins(); |
| 74 |
void RegisterBuiltin(std::string, GUICallbackProc); |
| 75 |
|
| 76 |
static GUI_impl *mpReadlineCompleterGUI; |
| 77 |
|
| 78 |
static char** ReadlineCompletionFunction(const char *text, int start, int end); |
| 79 |
static char * ReadlineCommandGeneratorCB(const char *text, int state); |
| 80 |
char * ReadlineCommandGenerator(const char *text, int state); |
| 81 |
|
| 82 |
void *mptr; |
| 83 |
GUICallbackProc cbp; |
| 84 |
|
| 85 |
static void *mpParserThread; |
| 86 |
GUI_language* lang; |
| 87 |
|
| 88 |
std::map<std::string, CallbackVector > mmCallBackMap; |
| 89 |
std::set<std::string> builtins; |
| 90 |
std::map<std::string, std::vector<std::string> > mmQueues; |
| 91 |
std::list<std::function<void(std::string,std::string)>> callback_functions; |
| 92 |
|
| 93 |
friend void builtin_commandlist(void* ptr, std::string sCommand, std::string sParams); |
| 94 |
friend void builtin_queue(void* ptr, std::string sCommand, std::string sParams); |
| 95 |
friend void builtin_runqueue(void* ptr, std::string sCommand, std::string sParams); |
| 96 |
}; |
| 97 |
|
| 98 |
template<int D=0> struct GUI_impl_singleton |
| 99 |
{ |
| 100 |
static GUI_impl& instance() |
| 101 |
{ |
| 102 |
static GUI_impl* inst = 0; |
| 103 |
if(!inst) |
| 104 |
{ |
| 105 |
inst = new GUI_impl; |
| 106 |
inst->post_init(); |
| 107 |
} |
| 108 |
return *inst; |
| 109 |
} |
| 110 |
}; |
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
} |
| 115 |
|
| 116 |
#endif |