home *** CD-ROM | disk | FTP | other *** search
/ The Pier Shareware 6 / The_Pier_Shareware_Number_6_(The_Pier_Exchange)_(1995).iso / 035 / kwclass.zip / KVALID.HPP < prev    next >
C/C++ Source or Header  |  1994-04-18  |  4KB  |  156 lines

  1. #ifndef _KVALID_
  2. #define _KVALID_
  3.  
  4. #ifndef _IKEYHDR_
  5.    #include <ikeyhdr.hpp>
  6. #endif
  7.  
  8. class IKeyboardEvent;
  9.  
  10. /*----------------------------------------------------------------------
  11.  * Class: KValidator
  12.  *
  13.  * Implementation File: kvalid.cpp
  14.  *
  15.  * Base Class: Derived from IKeyboardHandler
  16.  *
  17.  * Purpose: Serves as a base class for entry field validator classes.  
  18.  *          Derived classes implement only the functions necessary to
  19.  *          validate the content of characters entered by the user and
  20.  *          the overall format of the data in the entry field.
  21.  *
  22.  * Notes:  KValidator objects may or may not be used as event handlers
  23.  *         for entry fields.  If they are not used as an event handler,
  24.  *         the string validation function is used for field-level 
  25.  *         validation.
  26.  *--------------------------------------------------------------------*/
  27. class _Export KValidator : public IKeyboardHandler
  28. {
  29.    typedef IKeyboardHandler Inherited;
  30.    public:
  31.       virtual ~KValidator();
  32.       virtual void error();
  33.       virtual Boolean isValid(const char *text, Boolean fill=false) const;
  34.       virtual IString &strip(IString &text);
  35.       virtual IString &fill(IString &text);
  36.  
  37.    protected:
  38.       KValidator(Boolean val=true);
  39.       virtual Boolean characterKeyPress(IKeyboardEvent& event);
  40.       virtual Boolean virtualKeyPress(IKeyboardEvent& event);
  41.       virtual Boolean test(int c) const;
  42.  
  43.    private:
  44.       Boolean validateContentOnChar;
  45. };
  46.  
  47.  
  48. /*----------------------------------------------------------------------
  49.  * Class: KAlphaValidator
  50.  *
  51.  * Implementation File: kvalid.cpp
  52.  *
  53.  * Base Class: Derived from KValidator
  54.  *
  55.  * Purpose: Allows only alphabetic and space characters in an entry
  56.  *          field.  
  57.  *
  58.  * Notes:
  59.  *--------------------------------------------------------------------*/
  60. class _Export KAlphaValidator : public KValidator
  61. {
  62.    typedef KValidator Inherited;
  63.  
  64.    public:
  65.       KAlphaValidator();
  66.  
  67.    protected:
  68.       virtual Boolean test(int c) const;
  69. };
  70.  
  71.  
  72. /*----------------------------------------------------------------------
  73.  * Class: KNumericValidator
  74.  *
  75.  * Implementation File: kvalid.cpp
  76.  *
  77.  * Base Class: Derived from KValidator
  78.  *
  79.  * Purpose: Allows only numeric characters and a leading sign in an 
  80.  *          entry field.  
  81.  *
  82.  * Notes:
  83.  *--------------------------------------------------------------------*/
  84. class _Export KNumericValidator : public KValidator
  85. {
  86.    typedef KValidator Inherited;
  87.  
  88.    public:
  89.       KNumericValidator();
  90.       void enableSign(Boolean val);
  91.       void disableSign();
  92.  
  93.    protected:
  94.       virtual Boolean isValid(const char *text,
  95.                               Boolean fill=false) const;
  96.       virtual Boolean test(int c) const;
  97.  
  98.    private:
  99.       Boolean allowSign;
  100. };
  101.  
  102.  
  103. /*----------------------------------------------------------------------
  104.  * Class: KAlphaNumericValidator
  105.  *
  106.  * Implementation File: kvalid.cpp
  107.  *
  108.  * Base Class: Derived from KValidator
  109.  *
  110.  * Purpose: Allows only numeric characters and a leading sign in an 
  111.  *          entry field.  
  112.  *
  113.  * Notes:
  114.  *--------------------------------------------------------------------*/
  115. class _Export KAlphaNumericValidator : public KValidator
  116. {
  117.    typedef KValidator Inherited;
  118.  
  119.    public:
  120.       KAlphaNumericValidator();
  121.  
  122.    protected:
  123.       virtual Boolean test(int c) const;
  124. };
  125.  
  126.  
  127. /*----------------------------------------------------------------------
  128.  * Class: KRealValidator
  129.  *
  130.  * Implementation File: kvalid.cpp
  131.  *
  132.  * Base Class: Derived from KValidator
  133.  *
  134.  * Purpose: Allows real numbers in an entry field.  Valid format for a
  135.  *          real number is:
  136.  *        
  137.  *          [sign][digits][.digits][{e|E|d|D}[sign]digits]
  138.  *
  139.  * Notes:
  140.  *--------------------------------------------------------------------*/
  141. class _Export KRealValidator : public KValidator
  142. {
  143.    typedef KValidator Inherited;
  144.  
  145.    public:
  146.       KRealValidator();
  147.  
  148.    protected:
  149.       virtual Boolean isValid(const char *text, 
  150.                               Boolean fill=false) const;
  151.       virtual Boolean test(int c) const;
  152. };
  153.  
  154. #endif
  155.  
  156.