rlmm::basic_completion< Lock > Struct Template Reference
[The Readline classes.]

#include <rlmm/completion.hh>

Inheritance diagram for rlmm::basic_completion< Lock >:

Inheritance graph
[legend]
Collaboration diagram for rlmm::basic_completion< Lock >:

Collaboration graph
[legend]
List of all members.

Detailed Description

template<typename Lock>
struct rlmm::basic_completion< Lock >

Class to do completions for readline.

readline completion. The application should sub-class this class for custom completion. Several completer objects can exists. They should be installed as needed by sending the static message rlmm::completion::install.

See also:
examples::completer for an elaborate example.


Public Types

typedef std::list< std::string > string_list
enum  match { none, single, multiple }
enum  type {
  unknown, normal, list, partial,
  insert
}

Public Member Functions

 basic_completion ()
virtual ~basic_completion ()
virtual string_list matches (const std::string &what)
virtual std::string filename_complete (const std::string &what)
virtual std::string username_complete (const std::string &what)
virtual void max_before_query (int max=100)
virtual int max_before_query ()
virtual void word_breakers (const std::string &breakers)
virtual const std::string & word_breakers () const
virtual void quoters (const std::string &quoters)
virtual const std::string & quoters () const
virtual void filename_quoters (const std::string &quote)
virtual const std::string & filename_quoters () const
virtual void special_prefix (const std::string &prefix)
virtual const std::string & special_prefix () const
virtual void append_character (char append=' ')
virtual char append_character () const
virtual void ignore_duplicates (bool ignore)
virtual bool ignore_duplicates () const
virtual void inhibit (bool inhibit=false)
virtual bool inhibit () const
virtual void filename_match (bool isfiles=true)
virtual bool filename_match () const
virtual void quote_match (bool isquote=true)
virtual bool quote_match () const
virtual void completion_done (bool isover=true)
virtual bool completion_done () const
virtual void completion_type (type t)
virtual type completion_type (void) const

Protected Member Functions

virtual bool internal (type t)
virtual void possibilities (const std::string &what)
virtual std::string completer (const std::string &what, int state)
virtual string_list alternate_completer (const std::string &what, int start, int end)
virtual std::string quote_filename (const std::string &filename, match m, std::string::size_type &start)
virtual std::string dequote_filename (const std::string &filename, std::string::size_type &start)
virtual bool quoted (const std::string &what, std::string::size_type where) const
virtual bool remove_completions (const std::string &substring, string_list &matches)
virtual bool directory_hook (std::string &dirname, const std::string &basename)
virtual bool display_hook (string_list &matches, int width)
virtual std::string complete (const std::string &what)

Static Protected Member Functions

static int type2internal (type t)
static type internal2type (int t)

Protected Attributes

int _state
int _max_before_query
std::string _word_breakers
std::string _quoters
std::string _filename_quoters
std::string _special_prefix
char _append_character
bool _ignore_duplicates
bool _inhibit

Private Member Functions

void do_activate ()
void do_deactivate ()

Friends

class one_at_a_time
char * rlmm_completer (const char *, int)
char ** rlmm_alternate_completer (const char *, int, int)
char * rlmm_filename_quote (char *, int, char *)
char * rlmm_filename_dequote (char *, int)
int rlmm_quoted (char *, int)
int rlmm_remove (char **)
int rlmm_directory_hook (char **)
void rlmm_display_hook (char **, int, int)


Member Typedef Documentation

template<typename Lock>
typedef std::list<std::string> rlmm::basic_completion< Lock >::string_list
 

List of strings.


Member Enumeration Documentation

template<typename Lock>
enum rlmm::basic_completion::match
 

What kind of match.

Enumerator:
none  No match.
single  Single match.
multiple  Multiple matches.

template<typename Lock>
enum rlmm::basic_completion::type
 

What kind of completion.

Enumerator:
unknown  Unknown.
normal  Normal (attempting) completion.
list  List possible completions.
partial  List possible partial completions, if more than 0.
insert  Insert all possible completions.


Constructor & Destructor Documentation

template<typename Lock>
rlmm::basic_completion< Lock >::basic_completion  )  [inline]
 

CTOR.

template<typename Lock>
rlmm::basic_completion< Lock >::~basic_completion  )  [inline, virtual]
 

DTOR.


Member Function Documentation

template<typename Lock>
basic_completion< Lock >::string_list rlmm::basic_completion< Lock >::alternate_completer const std::string &  what,
int  start,
int  end
[inline, protected, virtual]
 

Abstract alternate completion to try first.

Parameters:
what What to make a completion list for
start Pointer into buffer where completion starts
end Pointer into buffer where completion starts
Returns:
list of possible completions (can be empty)

template<typename Lock>
virtual char rlmm::basic_completion< Lock >::append_character  )  const [inline, virtual]
 

the character to the completions.

Returns:
the character to append.

template<typename Lock>
void rlmm::basic_completion< Lock >::append_character char  append = ' '  )  [inline, virtual]
 

the character to the completions.

Parameters:
append the character to append.

template<typename Lock>
virtual std::string rlmm::basic_completion< Lock >::complete const std::string &  what  )  [inline, protected, virtual]
 

Abstract member function to be overloaded by user.

This should return a possible match to what, or the empty string if there's no (more) possible matches. This member function is called repeatedly during completion of a single what. If the member function Possilibities uses a STL container like stack (LIFO) or deque (FIFO), then this member function could simply pop the head of that container.

Parameters:
what What to return a completion for
Returns:
The next possible completion, or empty string if none

template<typename Lock>
std::string rlmm::basic_completion< Lock >::completer const std::string &  what,
int  state
[inline, protected, virtual]
 

Member function that delegates to complete and possibilities.

Parameters:
what What to complete
state First call (0) or later (>0)
Returns:
next possible completion, or empty string if no more

template<typename Lock>
bool rlmm::basic_completion< Lock >::completion_done  )  const [inline, virtual]
 

Wether the completion is flaged as over.

Note that this member function only makes sense in the AlternativeComplete member function.

Returns:
wether completion is flaged as over.

template<typename Lock>
void rlmm::basic_completion< Lock >::completion_done bool  isover = true  )  [inline, virtual]
 

Flag the completion as done.

Sending this message causes readline to stop doing completions. This should be called from AlternativeComplete only - it has no effect elsewhere.

Parameters:
isover true if completion is over.

template<typename Lock>
basic_completion< Lock >::type rlmm::basic_completion< Lock >::completion_type void   )  const [inline, virtual]
 

the current completion type.

See the completionType(char) member function for a list of possible return values.

Returns:
the current completion type.

template<typename Lock>
void rlmm::basic_completion< Lock >::completion_type type  t  )  [inline, virtual]
 

the completion action type.

the internal flag for what kind of completion is to be done.

Parameters:
t the type of action.

template<typename Lock>
std::string rlmm::basic_completion< Lock >::dequote_filename const std::string &  filename,
std::string::size_type &  start
[inline, protected, virtual]
 

De-quote a file name.

Parameters:
filename File name to quote.
start Index into line buffer.
Returns:
the dequoated filename.

template<typename Lock>
bool rlmm::basic_completion< Lock >::directory_hook std::string &  dirname,
const std::string &  basename
[inline, protected, virtual]
 

Hook for manipulating directory part of a file.

The method is called when completing a file name. The hook may change the directory part of it's argument. If it modifies it, it must return true, otherwise false. It may not modify the filename part

Parameters:
dirname The directory part of the file.
basename The file name of the file.
Returns:
true if the directory part is modified.

template<typename Lock>
bool rlmm::basic_completion< Lock >::display_hook string_list matches,
int  width
[inline, protected, virtual]
 

Method to display the completions.

This member function is called when readline is about to display a list of possible matches. The sub-classes can redefine this method to do tricky stuff in the output.

Parameters:
matches A list of matches.
width Length of longest match.
Returns:
false if internal displayer is to be used.

template<typename Lock>
void rlmm::basic_completion< Lock >::do_activate  )  [inline, private, virtual]
 

Install a new completion handler.

Implements rlmm::one_at_a_time< basic_completion, Lock >.

template<typename Lock>
void rlmm::basic_completion< Lock >::do_deactivate  )  [inline, private, virtual]
 

Remove a completion handler.

Implements rlmm::one_at_a_time< basic_completion, Lock >.

template<typename Lock>
std::string rlmm::basic_completion< Lock >::filename_complete const std::string &  what  )  [inline, virtual]
 

Complete a file name.

Parameters:
what File name to complete
Returns:
The next possible completion to partial file name

template<typename Lock>
bool rlmm::basic_completion< Lock >::filename_match  )  const [inline, virtual]
 

Wether matches are filenames.

Note that this member function only makes sense in the Complete function.

Returns:
true if matches are flag as filenames.

template<typename Lock>
void rlmm::basic_completion< Lock >::filename_match bool  isfiles = true  )  [inline, virtual]
 

Flag the completions as filenames.

Sending this message tells readline, that the completion matches are to be treated as filenames. This member function does not have any effect outside of the Complete member function.

Parameters:
isfiles true if completion treated as filenames.

template<typename Lock>
const std::string & rlmm::basic_completion< Lock >::filename_quoters  )  const [inline, virtual]
 

Characters that forces quotation of a filename.

Returns:
Characters that forces quotation of a filename.

template<typename Lock>
void rlmm::basic_completion< Lock >::filename_quoters const std::string &  quote  )  [inline, virtual]
 

Characters that forces quotation of a filename.

Parameters:
quote Characters that forces quotation.

template<typename Lock>
virtual bool rlmm::basic_completion< Lock >::ignore_duplicates  )  const [inline, virtual]
 

wether to ignore duplicates or not

Returns:
true if to ignore duplicates, false otherwise.

template<typename Lock>
void rlmm::basic_completion< Lock >::ignore_duplicates bool  ignore  )  [inline, virtual]
 

wether to ignore duplicates or not

Parameters:
ignore true if to ignore duplicates, false otherwise.

template<typename Lock>
virtual bool rlmm::basic_completion< Lock >::inhibit  )  const [inline, virtual]
 

wether to ineibit completion or not

Returns:
true if completion is inhibited, false otherwise.

template<typename Lock>
void rlmm::basic_completion< Lock >::inhibit bool  inhibit = false  )  [inline, virtual]
 

wether to inheibit completion or not

Parameters:
inhibit true if completion is inhibited, false otherwise.

template<typename Lock>
bool rlmm::basic_completion< Lock >::internal type  t  )  [inline, protected, virtual]
 

Call the internal completion function.

The actual action taken depends on the type argument. This member function only really makes sense within the Completer, Complete, and Possibilities member functions.

Parameters:
t The type of action to take.
Returns:
true on success, falls otherwise.

template<typename Lock>
basic_completion< Lock >::type rlmm::basic_completion< Lock >::internal2type int  t  )  [inline, static, protected]
 

transform internal representation to type enum.

Parameters:
t the internal type to translate.
Returns:
class representation.

template<typename Lock>
basic_completion< Lock >::string_list rlmm::basic_completion< Lock >::matches const std::string &  what  )  [inline, virtual]
 

Return a list of possible matches.

First element is the replacement text (if any) for what, possibly what itself.

Parameters:
what What to get completions for
Returns:
A list of possible completions. First element is the expansion of what.

template<typename Lock>
virtual int rlmm::basic_completion< Lock >::max_before_query  )  [inline, virtual]
 

the maximum number of items before query.

Returns:
The maximum number of items.

template<typename Lock>
void rlmm::basic_completion< Lock >::max_before_query int  max = 100  )  [inline, virtual]
 

Set the maximum number of items before query.

This method sets the maximum number of items that the completion will show without querying the user if she wants to see the completions.

Parameters:
max The maximum.

template<typename Lock>
virtual void rlmm::basic_completion< Lock >::possibilities const std::string &  what  )  [inline, protected, virtual]
 

Abstract mmember function to be overloaded by user.

This should setup a list of possible matches to what. A STL stack, deque, or similar is a good candidate.

Parameters:
what What to setup a completion list for

template<typename Lock>
std::string rlmm::basic_completion< Lock >::quote_filename const std::string &  filename,
match  m,
std::string::size_type &  start
[inline, protected, virtual]
 

Quote a file name.

Parameters:
filename File name to quote
m How many matches
start Index into line buffer
Returns:
the quoted file name

template<typename Lock>
bool rlmm::basic_completion< Lock >::quote_match  )  const [inline, virtual]
 

Wether mathces are to be quoted.

Note that this member function only makes sense in the Complete member function.

Returns:
true if match is to be quoted.

template<typename Lock>
void rlmm::basic_completion< Lock >::quote_match bool  isquote = true  )  [inline, virtual]
 

Flag filename to be quoted.

Sending this message from the Complete member function will prompt readline to quote the filename using the QuoteFilename member function. This message has no effect outside of the Complete function.

Parameters:
isquote true if filename is to be quoted.

template<typename Lock>
bool rlmm::basic_completion< Lock >::quoted const std::string &  what,
std::string::size_type  where
const [inline, protected, virtual]
 

Decide wether a character is quoted.

This method should be overloaded by the user. If the character at the index postion in the passed string is quoted according to the quoting scheme, this should return true.

Parameters:
what The string.
where The character position.
Returns:
true if character is quoted, false otherwise.

template<typename Lock>
virtual const std::string& rlmm::basic_completion< Lock >::quoters  )  const [inline, virtual]
 

Characters that quote.

Returns:
Characters that quote.

template<typename Lock>
void rlmm::basic_completion< Lock >::quoters const std::string &  quoters  )  [inline, virtual]
 

characters that quote.

Parameters:
quoters Characters tha can be used for quoting.

template<typename Lock>
bool rlmm::basic_completion< Lock >::remove_completions const std::string &  substring,
string_list matches
[inline, protected, virtual]
 

Remove matches from list of matches.

This member function is called with the a list of possible matches after completion. The user can overload this member function to alter the list if some completions are undesirable.

Parameters:
substring Maximal substring common to all matches.
matches list of possible matches.
Returns:
The true if the list was modified.

template<typename Lock>
const std::string & rlmm::basic_completion< Lock >::special_prefix  )  const [inline, virtual]
 

the word break characters to be left in match text.

Returns:
The prefix characters.

template<typename Lock>
void rlmm::basic_completion< Lock >::special_prefix const std::string &  prefix  )  [inline, virtual]
 

the word break characters to be left in match text.

Parameters:
prefix The prefix characters.

template<typename Lock>
int rlmm::basic_completion< Lock >::type2internal type  t  )  [inline, static, protected]
 

transform type enum to internal representation.

Parameters:
t the type to translate.
Returns:
internal representation.

template<typename Lock>
std::string rlmm::basic_completion< Lock >::username_complete const std::string &  what  )  [inline, virtual]
 

Complete a user name.

Parameters:
what The partial user name to complete
Returns:
The next possible completion to partial username

template<typename Lock>
const std::string & rlmm::basic_completion< Lock >::word_breakers  )  const [inline, virtual]
 

Get characters that break words.

Returns:
Characters that break words.

template<typename Lock>
void rlmm::basic_completion< Lock >::word_breakers const std::string &  breakers  )  [inline, virtual]
 

Set Characters that break words.

Parameters:
breakers Charaters that break words


Friends And Related Function Documentation

template<typename Lock>
friend class one_at_a_time [friend]
 

Base class is a friend.

template<typename Lock>
char** rlmm_alternate_completer const char *  what,
int  start,
int  end
[friend]
 

Inteface function.

Parameters:
what What to complete
start Start of range
end end of range
Returns:
return of basic_completion<Lock>::alternate_completer(what,start, end)

template<typename Lock>
char* rlmm_completer const char *  what,
int  state
[friend]
 

Interface function for completion.

Parameters:
what What to complete
state The current state
Returns:
return value of basic_completion<Lock>::completer(what, state)

template<typename Lock>
int rlmm_directory_hook char **  fullpath  )  [friend]
 

Parameters:
fullpath filename. On return, the full path.
Returns:
basic_completion<Lock>::directory_hook(rlmm_basename(fullpath), rlmm_dirname(*fullpath))

template<typename Lock>
void rlmm_display_hook char **  matches,
int  n,
int  w
[friend]
 

Hook to run when displaying possible completions.

Parameters:
matches List of possible completions.
n Number of items in matches.
w The number of characters in the widest entry in matches.

template<typename Lock>
char* rlmm_filename_dequote char *  what,
int  quote
[friend]
 

Unquote a file name.

Parameters:
what What to dequote.
quote Pointer to quote in what
Returns:
return value of basic_completion<Lock>::dequote_filename(what, quote)

template<typename Lock>
char* rlmm_filename_quote char *  what,
int  match,
char *  quote
[friend]
 

Quite a file name.

Parameters:
what What to quite
match Kind of match
quote pointer to quote in what
Returns:
return value of basic_completion<Lock>::quote_filename(fn, match, quote)

template<typename Lock>
int rlmm_quoted char *  what,
int  index
[friend]
 

Check if what is quoted.

Parameters:
what String to check
index Index where quote might be
Returns:
basic_completion<Lock>::quoted(what, index)

template<typename Lock>
int rlmm_remove char **  matches  )  [friend]
 

Filter matches.

Parameters:
matches List of possible matches. On output, the filtered list.
Returns:
Number of items in matches on output.


Member Data Documentation

template<typename Lock>
char rlmm::basic_completion< Lock >::_append_character [protected]
 

Append this character to the completions.

template<typename Lock>
std::string rlmm::basic_completion< Lock >::_filename_quoters [protected]
 

Characters that forces quotation of a filename.

template<typename Lock>
bool rlmm::basic_completion< Lock >::_ignore_duplicates [protected]
 

Wether to ignore duplicates or not.

template<typename Lock>
bool rlmm::basic_completion< Lock >::_inhibit [protected]
 

Wether to inheibit completion or not.

template<typename Lock>
int rlmm::basic_completion< Lock >::_max_before_query [protected]
 

Maximum number of items to display before prompting.

template<typename Lock>
std::string rlmm::basic_completion< Lock >::_quoters [protected]
 

Characters that quote.

template<typename Lock>
std::string rlmm::basic_completion< Lock >::_special_prefix [protected]
 

Word break characters to be left in match text.

template<typename Lock>
int rlmm::basic_completion< Lock >::_state [protected]
 

The state argument that completer was called with.

template<typename Lock>
std::string rlmm::basic_completion< Lock >::_word_breakers [protected]
 

Characters that break words.


The documentation for this struct was generated from the following file:
Top of page
Last update Fri Aug 26 15:19:53 2005
Christian Holm
Created by DoxyGen 1.4.4