19#include <readline/readline.h>
22 static std::set < std::string > fetchAlgorithmsFullyQualifiedName (
const char *text ) {
23 std::set < std::string > fullyQualifiedNames;
26 fullyQualifiedNames.insert ( algo.first );
29 return filter_completions ( fullyQualifiedNames, text );
32 static std::set < std::string > fetchAlgorithmsLastSegmentName (
const char *text ) {
33 std::map < std::string, unsigned > collisions;
36 size_t pos = algo.first.find_last_of (
':' );
37 if ( pos != std::string::npos )
38 collisions [ algo.first.substr ( pos + 1 ) ] += 1;
41 std::set < std::string >
res;
42 for (
const std::pair < const std::string, unsigned > & kv : collisions )
44 res.insert ( kv.first );
46 return filter_completions (
res, text );
49 static std::set < std::string > fetchAlgorithmGroups (
const char *text ) {
50 std::set < std::string >
res;
53 std::set < std::string > groups = getGroups ( algo.first );
54 res.insert ( groups.begin ( ), groups.end ( ) );
57 return filter_completions (
res, text );
60 static std::set < std::string > fetchDatatypeGroups (
const char *text ) {
61 std::set < std::string >
res;
64 std::set < std::string > groups = getGroups ( dtt );
65 res.insert ( groups.begin ( ), groups.end ( ) );
68 return filter_completions (
res, text );
71 static std::set < std::string > fetchCommands (
const char *text ) {
72 return filter_completions ( {
"print",
"execute",
"introspect",
"quit",
"help",
"set" }, text );
75 static std::set < std::string > fetchCommandsIntrospect (
const char *text ) {
76 return filter_completions ( {
"algorithms",
"overloads",
"casts",
"datatypes",
"variables",
"bindings" }, text );
79 static std::set < std::string > fetchBindings (
const char *text ) {
80 return filter_completions ( addPrefix (
Prompt::getPrompt ( ).getEnvironment ( ).getBindingNames ( ),
"#" ), text );
83 static std::set < std::string > fetchVariables (
const char *text ) {
84 return filter_completions ( addPrefix (
Prompt::getPrompt ( ).getEnvironment ( ).getVariableNames ( ),
"$" ), text );
87 static std::set < std::string > fetchSet (
const char *text ) {
88 return filter_completions ( {
"verbose",
"measure",
"optimizeXml",
"seed" }, text );
91 static std::set < std::string > fetchFilepath (
const char *text ) {
92 std::set < std::string >
res;
96 while ( ( str = rl_filename_completion_function ( text, state++ ) ) !=
nullptr ) {
126 static bool masterCommandCompletionTest (
const std::string & line,
unsigned start,
const std::string & expectation );
127 static std::set < std::string > addPrefix (
const std::set < std::string > & collection,
const std::string & prefix );
128 static std::set < std::string > getGroups (
const std::string & qualified_name );
129 static std::set < std::string > filter_completions (
const std::set < std::string > & choices,
const char *text );
136 template <
typename... CompletionGeneratorFunc >
137 static char * completion_generator (
const char *text,
int state,
const CompletionGeneratorFunc & ... generators ) {
138 static std::string prefix;
139 static std::set < std::string > choices;
140 static std::set < std::string > :: const_iterator iter;
146 choices = std::set < std::string > ( );
149 const std::vector < std::function < std::set < std::string > (
const char* ) > > gens = { generators... };
150 for (
const auto & gen : gens ) {
151 std::set < std::string > tmpres;
152 std::set < std::string > tmpg = gen ( text );
156 std::inserter ( tmpres,
std::begin ( tmpres ) ) );
160 iter = choices.begin ( );
164 while ( iter != choices.end ( ) ) {
165 return strdup ( iter ++ -> c_str ( ) );
176 static char * complete_algorithm (
const char *text,
int state ) {
177 return completion_generator ( text, state, fetchAlgorithmsFullyQualifiedName, fetchAlgorithmsLastSegmentName );
180 static char * complete_algorithm_group (
const char *text,
int state ) {
181 return completion_generator ( text, state, fetchAlgorithmGroups );
184 static char * complete_datatype_group (
const char *text,
int state ) {
185 return completion_generator ( text, state, fetchDatatypeGroups );
188 static char * complete_command (
const char *text,
int state ) {
189 return completion_generator ( text, state, fetchCommands );
192 static char * complete_command_introspect (
const char *text,
int state ) {
193 return completion_generator ( text, state, fetchCommandsIntrospect );
196 static char * complete_variable (
const char *text,
int state ) {
197 return completion_generator ( text, state, fetchVariables );
200 static char * complete_binding (
const char *text,
int state ) {
201 return completion_generator ( text, state, fetchBindings );
204 static char * complete_filepath (
const char *text,
int state ) {
205 return completion_generator ( text, state, fetchFilepath );
208 static char * complete_filepath_or_variable (
const char *text,
int state ) {
209 return completion_generator ( text, state, fetchFilepath, fetchVariables );
212 static char * complete_set (
const char *text,
int state ) {
213 return completion_generator ( text, state, fetchSet );
static Prompt & getPrompt()
Definition: Prompt.h:28
Definition: ReadlinePromptCompletion.h:21
CompletionContext
Definition: ReadlinePromptCompletion.h:104
static ext::set< ext::pair< std::string, ext::vector< std::string > > > listAlgorithms()
Definition: Registry.cpp:21
static ext::set< std::string > listDataTypes()
Definition: XmlRegistry.cpp:14
Class extending the pair class from the standard library. Original reason is to allow printing of the...
Definition: pair.hpp:43
Class extending the vector class from the standard library. Original reason is to allow printing of t...
Definition: vector.hpp:45
static CompletionContext context(const char *text, unsigned start, unsigned end)
Definition: ReadlinePromptCompletion.cpp:59
static char ** readline_completion(const char *text, unsigned start, unsigned end)
Definition: ReadlinePromptCompletion.cpp:113
return res
Definition: MinimizeByPartitioning.h:145
auto begin(Container &&cont) -> decltype(std::forward(cont).begin())
Definition: iterator.hpp:900
void start(measurements::stealth_string name, measurements::Type type)
Definition: measurements.cpp:14
void end()
Definition: measurements.cpp:19