gstream-set_input_approver (3) - Linux Manuals

NAME

set_input_approver

SYNOPSIS

#include <gstream.h>

void set_input_approver(bool (*input_approver)(int));

DESCRIPTION

The function handed over will be called with every new character inputted and determines whether the character will be accepted by the inputter. If it returns true, the character is accepted and inserted in the input string, if false, the character is thrown away.

A short example:

   bool ia_abc_is_what_we_want(int chr)
   {
     if (chr == 'a' || chr == 'b' || chr == 'c')
       return true;
     else
       return false;
   }
   
   //...
   
   gs.set_input_approver(ia_abc_is_what_we_want);
   gs >> my_string; // the user is only able to input a, b or c
   
If you want to declare any variables of the type of the function, the typedef 'input_approver' in 'gbuf' makes it easy, e.g.

   gbuf::input_approver tmp_ap;
   
   //...
   
   tmp_ap = gs1.get_input_approver();
   gs1.set_input_approver(gs2.get_input_approver());
   gs2.set_input_approver(tmp_ap);
   
Note that a default input string as entered by set_input_string is not checked by this function. The default approver is