Debian Codegraph @

src/GUI_impl.h

raw symbols SCIP
1 /*
2 This file is part of the GVars3 Library.
3
4 Copyright (C) 2005 The Authors
5
6 This library is free software, see LICENSE file for details
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*);//Dummy 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 /// Start a thread which parses user input from the console.
55 /// Uses libreadline if configured, or just plain old iostream readline
56 void StartParserThread();
57 /// Stop the console parser thread, if running
58 /// Top tip: This is static so that it can be used with atexit(void*)
59 static void StopParserThread();
60
61 /// parse command line arguments for GVar values. It expects the form --name value and will stop
62 /// parsing when this form is not true anymore. possible cases are a single --, an argument, etc..
63 /// if it finds an argument --exec it interprets the next argument as a file name to load via LoadFile
64 /// @arg argc total number of arguments from main argc
65 /// @arg argv pointer to array of strings from main argv
66 /// @arg start first argument to look at to be compatible with other parsers
67 /// @arg prefix the prefix to use. note that everything after the prefix will be interpreted as part of the variable name
68 /// @arg execKeyword keyword to use to trigger execution of the file given as parameter with LoadFile
69 /// @return
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