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

#include <rlmm/history.hh>

Inheritance diagram for rlmm::basic_history< Lock >:

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

Collaboration graph
[legend]
List of all members.

Detailed Description

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

history for readline.

This class provides a history interface for readline. Several history objects can exists at a given time. One can switch between history objects by calling the static member function history::install. The current active history object can be accessed via the static member function history::instance. The first history object created will install itself as the current history.

See also:
examples::rlmmtest for how to use multiple history objects.
Examples:

fileman.cc, and rlmmtest.cc.


Public Types

typedef std::list< entryentry_list
enum  direction { backward = -1, forward = 1 }

Public Member Functions

Creating and deleting
 basic_history ()
virtual ~basic_history ()
Setting/getting parameters
void comment_character (char c)
char comment_character () const
void expansion_character (char c)
char expansion_character () const
void no_expand_characters (const std::string &noexp)
const std::string & no_expand_characters () const
void quote_inhibit_expansion (bool inhibit)
bool quote_inhibit_expansion () const
void search_delimiters (const std::string &del)
const std::string & search_delimiters () const
void substitution_character (char c)
char substitution_character () const
void word_delimiters (const std::string &del)
const std::string & word_delimiters () const
void add (const std::string &line, void *data=0)
void add (const entry &e)
entry at (int index) const
int bytes () const
void clear ()
entry current () const
int length () const
entry next () const
entry previous () const
entry remove (int index)
entry replace (int index, const entry &e)
bool position (int pos)
int where () const
const entry_list list () const
Expansion of history
std::string event (const std::string &text, int &index, char term='\0')
int expand (const std::string &line, std::string &expansion)
searching in the history
bool search (const std::string &line, direction dir=forward, bool anchored=false)
bool search (const std::string &line, int &pos, direction dir=forward)
(Un)freezing of history size
int stifle () const
int stifle (int max)
History file manipulation
int append (const std::string &filename, int lines)
int read (const std::string &filename, int from=-1, int to=-1)
int truncate (const std::string &filename, int lines)
int write (const std::string &filename)
Miscellaneous operations
std::string arguments (int first, int last, const std::string &text) const
void sync ()
std::list< std::string > tokenize (const std::string &text) const

Static Public Attributes

static const entry no_entry

Protected Types

typedef HISTORY_STATE * state_type
typedef HIST_ENTRY * entry_type

Protected Member Functions

void save () const
void restore () const
virtual bool inhibit_expansion (const std::string &line, int where)
global manupulations
void do_activate ()
void do_deactivate ()

Protected Attributes

entry_list _list
state_type _state
state_type _keep
char _comment_character
char _expansion_character
char _substitution_character
std::string _word_delimiters
std::string _no_expand_characters
std::string _search_delimiters
bool _quote_inhibit_expansion

Static Protected Attributes

static bool _initialized = false

Friends

class one_at_a_time
int rlmm_inhibit_expansion (char *, int)

Classes

class  entry
 An entry in the history list. More...
struct  saver


Member Typedef Documentation

template<typename Lock>
typedef std::list<entry> rlmm::basic_history< Lock >::entry_list
 

Examples:
fileman.cc.

template<typename Lock>
typedef HIST_ENTRY* rlmm::basic_history< Lock >::entry_type [protected]
 

C API entry type.

template<typename Lock>
typedef HISTORY_STATE* rlmm::basic_history< Lock >::state_type [protected]
 

C API state type.


Member Enumeration Documentation

template<typename Lock>
enum rlmm::basic_history::direction
 

Directions.

Enumerator:
backward  Search backward in history list.
forward  Search forward in history list.


Constructor & Destructor Documentation

template<typename Lock>
rlmm::basic_history< Lock >::basic_history  ) 
 

CTOR.

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

DTOR.


Member Function Documentation

template<typename Lock>
void rlmm::basic_history< Lock >::add const entry e  )  [inline]
 

template<typename Lock>
void rlmm::basic_history< Lock >::add const std::string &  line,
void *  data = 0
[inline]
 

Add a line to the history.

Parameters:
line Line to add.
data user data for line.

template<typename Lock>
int rlmm::basic_history< Lock >::append const std::string &  filename,
int  lines
[inline]
 

Append lines to history file.

Parameters:
lines Number of lines to append.
filename File to append to.
Returns:
0 on success, errno otherwise.

template<typename Lock>
std::string rlmm::basic_history< Lock >::arguments int  first,
int  last,
const std::string &  text
const [inline]
 

Return arguments.

Return a string of positional arguments in the passed text.

Parameters:
first first argument to extract.
last last argument to extract.
text The line to extract from.
Returns:
string with arguments seperated by .

template<typename Lock>
basic_history< Lock >::entry rlmm::basic_history< Lock >::at int  index  )  const [inline]
 

Get entry at position.

Parameters:
index Index in history.
Returns:
entry or 0 if out of bounds

template<typename Lock>
int rlmm::basic_history< Lock >::bytes  )  const [inline]
 

Return the number of bytes used by entries.

Returns:
sum of bytes used by entries.

template<typename Lock>
void rlmm::basic_history< Lock >::clear  )  [inline]
 

Clear the history.

template<typename Lock>
char rlmm::basic_history< Lock >::comment_character  )  const [inline]
 

Get the comment character.

template<typename Lock>
void rlmm::basic_history< Lock >::comment_character char  c  )  [inline]
 

Set the comment character ('#').

template<typename Lock>
basic_history< Lock >::entry rlmm::basic_history< Lock >::current  )  const [inline]
 

Get the current history entry.

template<typename Lock>
void rlmm::basic_history< Lock >::do_activate  )  [inline, protected, virtual]
 

Install a new history state.

At this point, the old history is synced with the current internal state.

Implements rlmm::one_at_a_time< basic_history, Lock >.

template<typename Lock>
void rlmm::basic_history< Lock >::do_deactivate  )  [inline, protected, virtual]
 

Remove a history state.

Implements rlmm::one_at_a_time< basic_history, Lock >.

template<typename Lock>
std::string rlmm::basic_history< Lock >::event const std::string &  text,
int &  index,
char  term = '\0'
[inline]
 

Return an event.

Returns the text of the history event at index in passed string. The index will be modified to point to after the event specifier.

Parameters:
text Text where event specifier is in.
index Index of event specifier in text.
term Additional termination character.
Returns:
the expanded event.

template<typename Lock>
int rlmm::basic_history< Lock >::expand const std::string &  line,
std::string &  expansion
[inline]
 

Do a history expansion on a line.

Parameters:
line Partial line to expand.
expansion The expansion.
Returns:
status of the expansion:
  • -1: Error in expansion
  • 0: No expansion.
  • 1: Did expansion.
  • 2: To be displayed
.

template<typename Lock>
char rlmm::basic_history< Lock >::expansion_character  )  const [inline]
 

Return the expansion character.

template<typename Lock>
void rlmm::basic_history< Lock >::expansion_character char  c  )  [inline]
 

Set the expansion character.

Note:
that this changes the expansion character globally.
Parameters:
c The expansion character. ('!')

template<typename Lock>
bool rlmm::basic_history< Lock >::inhibit_expansion const std::string &  line,
int  where
[inline, protected, virtual]
 

Inhibit expansion hook.

Users can override this method in derived classes.

Parameters:
line the line currently being expanded.
where index in line where expansion might take place.
Returns:
true if expansion is to be done at index, false otherwise.

template<typename Lock>
int rlmm::basic_history< Lock >::length  )  const [inline]
 

Get the length of the current history.

template<typename Lock>
const entry_list rlmm::basic_history< Lock >::list  )  const [inline]
 

Get the history list.

Note, this cannot be modified.

Examples:
fileman.cc.

template<typename Lock>
basic_history< Lock >::entry rlmm::basic_history< Lock >::next  )  const [inline]
 

Get the next entry.

Returns:
The next entry.

template<typename Lock>
const std::string& rlmm::basic_history< Lock >::no_expand_characters  )  const [inline]
 

Get the characters that are not expanded.

template<typename Lock>
void rlmm::basic_history< Lock >::no_expand_characters const std::string &  noexp  )  [inline]
 

Set the characters that shouldn't be expanded.

" \t\n\r="

template<typename Lock>
bool rlmm::basic_history< Lock >::position int  pos  )  [inline]
 

Set the position in the history.

Parameters:
pos Position to go to.
Returns:
true on success, false if pos is outout bounds.

template<typename Lock>
basic_history< Lock >::entry rlmm::basic_history< Lock >::previous  )  const [inline]
 

Get the previous entry.

Returns:
The next entry.

template<typename Lock>
bool rlmm::basic_history< Lock >::quote_inhibit_expansion  )  const [inline]
 

Set wether quotes inhibit expansion.

template<typename Lock>
void rlmm::basic_history< Lock >::quote_inhibit_expansion bool  inhibit  )  [inline]
 

Set wether quotes inhibit expansion.

template<typename Lock>
int rlmm::basic_history< Lock >::read const std::string &  filename,
int  from = -1,
int  to = -1
[inline]
 

Read history from a file.

Parameters:
filename file to read.
from Start at this entry if larger than zero.
to End at this entry if larger than zero.
Returns:
0 on success, errno otherwise.

template<typename Lock>
basic_history< Lock >::entry rlmm::basic_history< Lock >::remove int  index  )  [inline]
 

Remove an entry from the history.

Remove one entry from the history. The entry is returned, and it's the users responsibility to free the allocated memory in the returned entry. Note, that the string is allocated using std::malloc and should therefor be deallocated with std::free.

Parameters:
index Index of line in history to remove.
Returns:
The removed entry.

template<typename Lock>
basic_history< Lock >::entry rlmm::basic_history< Lock >::replace int  index,
const entry e
[inline]
 

Replace a line in the history.

Replace a line in the history with a new element. The entry is returned, and it's the users responsibility to free the allocated memory in the returned entry. Note, that the string is allocated using std::malloc and should therefor be deallocated with std::free.

Parameters:
index Line number to replace.
e the entry
Returns:
the old entry, or 0 if not valid.

template<typename Lock>
void rlmm::basic_history< Lock >::restore  )  const [inline, protected]
 

Restore the previously saved state.

template<typename Lock>
void rlmm::basic_history< Lock >::save  )  const [inline, protected]
 

Save the current state if this object is not the current history state.

template<typename Lock>
bool rlmm::basic_history< Lock >::search const std::string &  line,
int &  pos,
direction  dir = forward
[inline]
 

Search for a line in the history.

Contrary to the non-position search, this does not change the current position in the history list.

Parameters:
line The line to search for.
pos Line to start at. On return it contains the found location or -1 if no match was found.
dir The direction of the search.
Returns:
true if found.

template<typename Lock>
bool rlmm::basic_history< Lock >::search const std::string &  line,
direction  dir = forward,
bool  anchored = false
[inline]
 

Search for a line in the history.

Set the current history entry to the line if found.

Parameters:
line The line to search for.
dir The direction of the search.
anchored String must match at start of a line.
Returns:
true if found.

template<typename Lock>
const std::string& rlmm::basic_history< Lock >::search_delimiters  )  const [inline]
 

Get the search delimiters.

template<typename Lock>
void rlmm::basic_history< Lock >::search_delimiters const std::string &  del  )  [inline]
 

set the search delimiters.

template<typename Lock>
int rlmm::basic_history< Lock >::stifle int  max  )  [inline]
 

Stiffle the history.

Set the maximum number of lines to remember in the history, or release the history.

Parameters:
max The maximum number of lines. If max is negative, the history is unstiffled.
Returns:
max entries, or negative if it isn't stiffled.

template<typename Lock>
int rlmm::basic_history< Lock >::stifle  )  const [inline]
 

Test if the history is stiffled.

Returns:
max number entries in history if it's stiffled, otherwise a negative value.

template<typename Lock>
char rlmm::basic_history< Lock >::substitution_character  )  const [inline]
 

Get the substitution character.

template<typename Lock>
void rlmm::basic_history< Lock >::substitution_character char  c  )  [inline]
 

Set the substitution character.

('^')

template<typename Lock>
void rlmm::basic_history< Lock >::sync  )  [inline]
 

Syncronise this object with current history.

template<typename Lock>
std::list< std::string > rlmm::basic_history< Lock >::tokenize const std::string &  text  )  const [inline]
 

Tokenize a string according to history.

Parameters:
text Text to tokenize.

template<typename Lock>
int rlmm::basic_history< Lock >::truncate const std::string &  filename,
int  lines
[inline]
 

Truncate the history file.

This will throw an Errno exception on failure.

Parameters:
filename File to truncate.
lines number lines in file after trnuncateion.

template<typename Lock>
int rlmm::basic_history< Lock >::where  )  const [inline]
 

Get the current offset in the history.

Returns:
current offset.

template<typename Lock>
const std::string& rlmm::basic_history< Lock >::word_delimiters  )  const [inline]
 

Get the word delimiters.

template<typename Lock>
void rlmm::basic_history< Lock >::word_delimiters const std::string &  del  )  [inline]
 

Set the word delimiters.

" \t\n()<>;&|"

template<typename Lock>
int rlmm::basic_history< Lock >::write const std::string &  filename  )  [inline]
 

Write history to file.

Parameters:
filename File to write to.
Returns:
0 on success, errno otherwise.


Friends And Related Function Documentation

template<typename Lock>
friend class one_at_a_time [friend]
 

Base classs is a friend.

template<typename Lock>
int rlmm_inhibit_expansion char *  line,
int  where
[friend]
 


Member Data Documentation

template<typename Lock>
char rlmm::basic_history< Lock >::_comment_character [protected]
 

comment character

template<typename Lock>
char rlmm::basic_history< Lock >::_expansion_character [protected]
 

expension character

template<typename Lock>
bool rlmm::basic_history< Lock >::_initialized = false [static, protected]
 

Flag telling us if history library has been initialised.

template<typename Lock>
state_type rlmm::basic_history< Lock >::_keep [mutable, protected]
 

keep

template<typename Lock>
entry_list rlmm::basic_history< Lock >::_list [protected]
 

The history.

template<typename Lock>
std::string rlmm::basic_history< Lock >::_no_expand_characters [protected]
 

no expand characters

template<typename Lock>
bool rlmm::basic_history< Lock >::_quote_inhibit_expansion [protected]
 

wether quotes inhibits expansion

template<typename Lock>
std::string rlmm::basic_history< Lock >::_search_delimiters [protected]
 

Search delimiters.

template<typename Lock>
state_type rlmm::basic_history< Lock >::_state [mutable, protected]
 

Internal state information.

template<typename Lock>
char rlmm::basic_history< Lock >::_substitution_character [protected]
 

substitution character

template<typename Lock>
std::string rlmm::basic_history< Lock >::_word_delimiters [protected]
 

Word delimiters.

template<typename Lock>
const basic_history< Lock >::entry rlmm::basic_history< Lock >::no_entry [static]
 

The empty entry.


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