Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

rs::user Namespace Reference

simple user interaction for command line utils. More...


Functions

string ask (const string &question, bool allow_empty)
bool ask_yn (string question, const char *default_answer)
int ask_number (string question, int low, int high)
size_t choose (const string &title, const vector< string > &answers)
size_t choose (const string &title, const string &answers, char separator)
void pause (const string &message)
void pause (const std::string &message)
std::string ask (const std::string &question, bool allow_empty=false)
size_t choose (const std::string &title, const std::string &answers, char separator=',')
 ask user to select between several choices. More...

size_t choose (const std::string &title, const std::vector< std::string > &answers)
 ask user to select between several choices. More...


Detailed Description

simple user interaction for command line utils.

Function Documentation

string ask const string &    question,
bool    allow_empty
 

Definition at line 39 of file user.cpp.

Referenced by ask_number(), ask_yn(), and pause().

bool ask_yn std::string    question,
const char *    default_answer = 0
 

ask a question and expect yes/no/y/n as answer

Parameters:
question  This is printed to stdout
default_answer  When user pressed ENTER take this as answer. If default_answer sis 0, pressing ENTER is not allowed.
Returns:
true if user answered 'yes' or 'y'

Definition at line 54 of file user.cpp.

int ask_number std::string    question,
int    low = INT_MIN,
int    high = INT_MAX
 

ask to enter a number between low and high

Definition at line 68 of file user.cpp.

Referenced by choose().

size_t choose const string &    title,
const vector< string > &    answers
 

Definition at line 83 of file user.cpp.

Referenced by choose().

size_t choose const string &    title,
const string &    answers,
char    separator
 

Definition at line 127 of file user.cpp.

void pause const string &    message
 

Definition at line 145 of file user.cpp.

void pause const std::string &    message
 

Display message and wait for RETURN

std::string ask const std::string &    question,
bool    allow_empty = false
 

ask a question and return user input

Parameters:
question  This is printed to stdout
allow_empty  if true, empty input is accepted
Returns:
user input

size_t choose const std::string &    title,
const std::string &    answers,
char    separator = ','
 

ask user to select between several choices.

Parameters:
title  printed at top
answers  the possible answers separated by separator
separator  'answers' is separated by separator
Returns:
1 for first answer, 2 for second, etc.
Example:
            int answer = choose("(y)es or (n)o ? ", "y,n");
            if (answer == 1) cout << "The answer was 'y'\n";

size_t choose const std::string &    title,
const std::vector< std::string > &    answers
 

ask user to select between several choices.

Parameters:
title  printed at top
answers  the possible answers
Returns:
1 for first answer, 2 for second, etc.


Contact me in case of errors or questions.
This documentation is powered by Doxygen.
(C) 2000-2002 Doxygen