StdAir Logo  1.00.3
C++ Standard Airline IT Object Library
swift::SReadline Class Reference

The readline library wrapper. More...

#include <stdair/ui/cmdline/SReadline.hpp>

Public Member Functions

 SReadline (const size_t Limit=DefaultHistoryLimit)
 Constructs the object, sets the completion function. More...
 
 SReadline (const std::string &historyFileName, const size_t Limit=DefaultHistoryLimit)
 Constructs the object, sets the completion function, loads history. More...
 
 ~SReadline ()
 Saves the session history (if the file name was provided) and destroys the object. More...
 
std::string GetLine (const std::string &Prompt)
 Gets a single line from a user. More...
 
template<typename Container >
std::string GetLine (const std::string &Prompt, Container &ReadTokens)
 Gets a single line from a user. More...
 
template<typename Container >
std::string GetLine (const std::string &Prompt, Container &ReadTokens, bool &BreakOut)
 Gets a single line from a user. More...
 
std::string GetLine (const std::string &Prompt, bool &BreakOut)
 Gets a single line from a user. More...
 
template<typename ContainerType >
void GetHistory (ContainerType &Container)
 Fills the given container with the current history list. More...
 
bool SaveHistory (std::ostream &OS)
 Saves the history to the given file stream. More...
 
bool SaveHistory (const std::string &FileName)
 Saves the history to the given file. More...
 
void ClearHistory ()
 Clears the history. Does not affect the file where the previous session history is saved. More...
 
bool LoadHistory (std::istream &IS)
 Loads a history from a file stream. More...
 
bool LoadHistory (const std::string &FileName)
 Loads a history from the given file. More...
 
template<typename ContainerType >
void RegisterCompletions (const ContainerType &Container)
 Allows to register custom completers. More...
 
void SetKeymap (SKeymap &NewKeymap)
 Sets the given keymap. More...
 

Detailed Description

The readline library wrapper.

Attention: It is not thread safe! Supports: editing, history, custom completers

Definition at line 424 of file SReadline.hpp.

Constructor & Destructor Documentation

swift::SReadline::SReadline ( const size_t  Limit = DefaultHistoryLimit)
inline

Constructs the object, sets the completion function.

Parameters
LimitHistory size

Definition at line 431 of file SReadline.hpp.

swift::SReadline::SReadline ( const std::string &  historyFileName,
const size_t  Limit = DefaultHistoryLimit 
)
inline

Constructs the object, sets the completion function, loads history.

Parameters
historyFileNameFile name to load history from
LimitHistory size

Definition at line 446 of file SReadline.hpp.

References LoadHistory().

swift::SReadline::~SReadline ( )
inline

Saves the session history (if the file name was provided) and destroys the object.

Definition at line 462 of file SReadline.hpp.

References SaveHistory().

Member Function Documentation

std::string swift::SReadline::GetLine ( const std::string &  Prompt)
inline

Gets a single line from a user.

Parameters
PromptA printed prompt
Returns
A string which was actually inputed

Definition at line 473 of file SReadline.hpp.

Referenced by GetLine().

template<typename Container >
std::string swift::SReadline::GetLine ( const std::string &  Prompt,
Container &  ReadTokens 
)
inline

Gets a single line from a user.

Parameters
PromptA printed prompt
ReadTokensA user inputed string splitted into tokens. The container is cleared first
Returns
A string which was actually inputed

Definition at line 487 of file SReadline.hpp.

References GetLine().

template<typename Container >
std::string swift::SReadline::GetLine ( const std::string &  Prompt,
Container &  ReadTokens,
bool &  BreakOut 
)
inline

Gets a single line from a user.

Parameters
PromptA printed prompt
BreakOutit is set to true if the EOF found
ReadTokensA user inputed string splitted into tokens. The container is cleared first
Returns
A string which was actually inputed

Definition at line 502 of file SReadline.hpp.

References GetLine().

std::string swift::SReadline::GetLine ( const std::string &  Prompt,
bool &  BreakOut 
)
inline

Gets a single line from a user.

Parameters
PromptA printed prompt
BreakOutit is set to true if the EOF found
Returns
A string which was actually inputed

Definition at line 517 of file SReadline.hpp.

template<typename ContainerType >
void swift::SReadline::GetHistory ( ContainerType &  Container)
inline

Fills the given container with the current history list.

Does not clear the given container

Definition at line 552 of file SReadline.hpp.

bool swift::SReadline::SaveHistory ( std::ostream &  OS)
inline

Saves the history to the given file stream.

Parameters
OSoutput file stream
Returns
true if success

Definition at line 564 of file SReadline.hpp.

Referenced by SaveHistory(), and ~SReadline().

bool swift::SReadline::SaveHistory ( const std::string &  FileName)
inline

Saves the history to the given file.

Parameters
FileNameFile name to save the history to
Returns
true if success

Definition at line 581 of file SReadline.hpp.

References SaveHistory().

void swift::SReadline::ClearHistory ( )
inline

Clears the history. Does not affect the file where the previous session history is saved.

Definition at line 594 of file SReadline.hpp.

Referenced by LoadHistory().

bool swift::SReadline::LoadHistory ( std::istream &  IS)
inline

Loads a history from a file stream.

Parameters
ISInput file stream
Returns
true if success

Definition at line 604 of file SReadline.hpp.

References ClearHistory().

Referenced by LoadHistory(), and SReadline().

bool swift::SReadline::LoadHistory ( const std::string &  FileName)
inline

Loads a history from the given file.

Parameters
FileNameFile name to be load from
Returns
true if success

Definition at line 629 of file SReadline.hpp.

References LoadHistory().

template<typename ContainerType >
void swift::SReadline::RegisterCompletions ( const ContainerType &  Container)
inline

Allows to register custom completers.

Supports a special keyword: file. It means to use the standard file name completer.

For example the given container elements could be as follows:

  • command1 opt1
  • command1 opt2 file
  • command2
  • command2 opt1

Each container element must describe a single possible command line. The container element must have a conversion to std::string operator.

Parameters
ContainerA container which has all the user possible commands.

Definition at line 658 of file SReadline.hpp.

void swift::SReadline::SetKeymap ( SKeymap NewKeymap)
inline

Sets the given keymap.

Parameters
NewKeymapThe keymap that should be used from now.

Definition at line 675 of file SReadline.hpp.


The documentation for this class was generated from the following file: